@@ -20,17 +20,24 @@ data class Board(
2020 operator fun get (x : Int , y : Int ) =
2121 get(Coordinates (x, y))
2222
23- /* * Moves a piece according to [Move].
23+ /* * Moves a piece according to [Move] after verification .
2424 * @throws InvalidMoveException if something is wrong with the Move.
2525 * @return the moved [Piece], null if it turned into an amber. */
2626 @Throws(InvalidMoveException ::class )
2727 fun movePiece (move : Move ): Piece ? =
2828 (piecePositions[move.start] ? : throw InvalidMoveException (MoveMistake .START_EMPTY , move)).let { piece ->
29+ if (! move.destination.isValid)
30+ throw InvalidMoveException (MoveMistake .OUT_OF_BOUNDS , move)
2931 if (move.delta !in piece.possibleMoves)
3032 throw InvalidMoveException (MoveMistake .INVALID_MOVEMENT , move)
31- piecePositions[move.destination]?.let { piece.capture(it) }
33+ piecePositions[move.destination]?.let {
34+ if (it.team == piece.team)
35+ throw InvalidMoveException (MoveMistake .DESTINATION_BLOCKED , move)
36+ piece.capture(it)
37+ }
3238 piecePositions.remove(move.start)
3339 if (piece.isAmber || (piece.type.isLight && move.destination.y == piece.team.opponent().startLine)) {
40+ // TODO how to indicate double amber?
3441 piecePositions.remove(move.destination)
3542 null
3643 } else {
@@ -54,7 +61,8 @@ data class Board(
5461 * in rotational symmetry. */
5562 @JvmStatic
5663 fun generatePiecePositions () =
57- (PieceType .values() + PieceType .values()).let { pieces ->
64+ PieceType .values().let { types ->
65+ val pieces = types + types
5866 pieces.shuffle()
5967 pieces.withIndex().flatMap { (index, type) ->
6068 Team .values().map { team ->
0 commit comments