I am developing a chess game in Java (without AI, only with user control) and am still used to OOP. I have two questions.
I thought that in addition to the Game , Cell , Piece and Board objects, the Player object.
My question is: do I really need to? Of course, I do not need this, but is the option considered the best option? On the one hand, it seems that Player is useful for storing information about players and should contain methods such as takeTurn() . (For my implementation, I also want to keep track of all the possible actions, so I will have a getAllMoves() method). On the other hand, isn't a player just reorganizing existing data? Each piece already has an indication of which player it belongs to. And since my game does not contain AI, for takeTurn() may make sense to belong to Game , not Player . On the other hand, it is possible that Player can only have the getAllMoves() method, which uses its data but does not take action.
The second question, relevant, if the answer to the first question is yes, how can I organize relations between objects? getAllMoves() will accept an array of cells as input; but itโs strange that the Player class then depends on the fact that its cells correspond (are a subset) that are passed as input. It would be better if the data with cells are stored in different ways along with the array of all cells in the Board and updated together, which guarantees their agreement. Of course, a guarantee that they will agree will exist in any case, but it seems that the Player object should not know about the guarantee that exists in the Board object.
How do I solve these issues?
Thanks!
source share