Search code examples
javadesign-patternschessstate-pattern

Is implementing state pattern a good design choice for simple chess game?


I am trying to write an offline no AI no GUI synchronized command-line chess game that two users play (or one user play both white & black). That means there's only 1 thread.

The chess game includes special movement {capture, en passant, promotion, castling, checkmate, stalemate}

The user interact with the game by stating the start position and end position. e.g. e1 g1. That's it, in one line.

I am trying to take the full privilege of object-oriented design. But just for the sake of this requirement. Does implementing state pattern worth it? Since the user only input the command and the game should not ask the user to make any other decision after it.

Edit: I apologize for not making this clear. What I was confused of is whether to implement the state at the game control level like this image: enter image description here or the game piece level like this image: enter image description here


Solution

  • If you are not planning to improve the game later or add more features in it then there is no need to make it stateful.

    But if there is any chance (as low as 1%) for future work then you better make it stateful. because writing unnecessery code is always easier that rewriting functionality in a new context.