본문 바로가기

카테고리 없음

Chess Game Design Class Diagram

$begingroup$ Further move: Taking a pawn en passent: If a pawn moves two positions in its first move, it can be taken by an opposing pawn in the very next move as if it had moved one position only. Offering a draw or giving up: The player whose move it is can offer a draw, and the other player can accept or reject it. And the player whose move it is can give up the game. After 50 moves with no piece taken or pawn moved the player can demand a draw.

Chess Game Design

Same if the identical position is entered for the third time. $endgroup$–Dec 5 '14 at 22:22. My comments are with respect to design of the game.I see responsibilities of entities are mixed up in many places. Player should not initialize pieces.

Chess board layout diagram

We can move the responsibility to board. Board and pieces doesn't need to know about players. Pieces should not handle move. Pieces can provide list of possible moves to reach the destination path but board should choose a valid path. Board should have check for 'Check Mate' condition. Game should track the players move history and piece color selection. Player class should have only player details.A rough class diagram is attached below.

Chess game design class diagram template

Instead of using a boolean to flag if something is something (and thus implying that it isn't the other thing), consider an enum; in this case that doesn't buy you anything in terms of flexibility (since it's not as if there will ever be, say, red or purple or whatnot) but it will make your code much more clear.On the game, instead of setting black and white separately, you should have a single setPlayers(Player black, Player white), or better yet, have the board be a factory that provides the black and white Players itself - if there's even a reason to have a Player object in the first place.