@@ -8,13 +8,13 @@ import sc.plugin2022.util.Constants.boardrange
88import sc.plugin2022.util.MoveMistake
99import sc.shared.InvalidMoveException
1010
11- /* * Das Spielbrett besteht aus 8x8 Feldern. */
11+ /* * Das Spielbrett besteht aus 8x8 Feldern mit anfänglich 8 Figuren pro Spieler . */
1212@XStreamAlias(value = " board" )
1313data class Board (
14- private val board : MutableMap <Coordinates , Piece >,
15- ): IBoard, Map<Coordinates, Piece> by board {
14+ private val piecePositions : MutableMap <Coordinates , Piece >,
15+ ): IBoard, Map<Coordinates, Piece> by piecePositions {
1616
17- constructor (): this (generateBoard ())
17+ constructor (): this (generatePiecePositions ())
1818
1919 /* * Gibt das Feld an den gegebenen Koordinaten zurück. */
2020 operator fun get (x : Int , y : Int ) =
@@ -25,19 +25,19 @@ data class Board(
2525 * @return the moved [Piece], null if it turned into an amber. */
2626 @Throws(InvalidMoveException ::class )
2727 fun movePiece (move : Move ): Piece ? =
28- board [move.start]? .let { piece ->
28+ (piecePositions [move.start] ? : throw InvalidMoveException ( MoveMistake . START_EMPTY , move)) .let { piece ->
2929 if (move.delta !in piece.possibleMoves)
3030 throw InvalidMoveException (MoveMistake .INVALID_MOVEMENT , move)
31- board [move.destination]?.let { piece.capture(it) }
32- board .remove(move.start)
31+ piecePositions [move.destination]?.let { piece.capture(it) }
32+ piecePositions .remove(move.start)
3333 if (piece.isAmber || (piece.type.isLight && move.destination.y == piece.team.opponent().startLine)) {
34- board .remove(move.destination)
34+ piecePositions .remove(move.destination)
3535 null
3636 } else {
37- board [move.destination] = piece
37+ piecePositions [move.destination] = piece
3838 piece
3939 }
40- } ? : throw InvalidMoveException ( MoveMistake . START_EMPTY , move)
40+ }
4141
4242 override fun toString () =
4343 boardrange.joinToString(" \n " ) { y ->
@@ -46,11 +46,14 @@ data class Board(
4646 }
4747 }
4848
49- override fun clone () = Board (HashMap (board ))
49+ override fun clone () = Board (HashMap (piecePositions ))
5050
5151 companion object {
52+ /* * Generates a random new board with two pieces per type
53+ * for each player arranged randomly on their starting line
54+ * in rotational symmetry. */
5255 @JvmStatic
53- fun generateBoard () =
56+ fun generatePiecePositions () =
5457 (PieceType .values() + PieceType .values()).let { pieces ->
5558 pieces.shuffle()
5659 pieces.withIndex().flatMap { (index, type) ->
0 commit comments