Frage

I'm trying to model chess game. My UML-newbie thinking goes like this:
GameEngine has just one chessboard and two players (who inherits from Player) and when GameEngine is destroyed, so are these (composition). Chessboard can contain up to 32 chessmen and each player can control/have references to 16 chessmen (aggregation). The players need to call or access some methods of the board (directed association). Is that correct or at least close?

enter image description here

War es hilfreich?

Lösung

You made abstraction Player over Human and CPU. I think all your arrows must use the common one Player. For example:

class Chessboard {
  Player p1;
  Player p2;
}

It is more convenient way, and you can change in runtime your players and different game modes: Human vs Human, Human vs CPU, even CPU vs CPU

The same changes applied to GameEngine.

By the way, I don't think it is a good idea to player aggregate controlled chessmen. All control over Chessman nut be responsibility of Chessboard, and player just send him a message when he want to make a move in his turn.

That change allows you to have several chessboards per player for multi-table game.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top