Pregunta

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

¿Fue útil?

Solución

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.

Otros consejos

Using states will give you the same benefits for a cosnosle application chess game as it would give you with a full fledged UI application. the main benefit is that you can keep track of the allowed moves and game state , like you've said: casteling, en-passant , check , check-mate etc..

The game state and possible moves are not affected by the fact that you use console application , UI , a distributed web application or whatever. they have to do with the internal logic of the game.

Edit:

One bonus I can think of for UI chess application is if you wish to specialize the look of ceratin states, e.g. : put a red square on the king when there is a check state.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top