@@ -8,13 +8,13 @@ import sc.plugin2022.util.Constants.boardrange
8
8
import sc.plugin2022.util.MoveMistake
9
9
import sc.shared.InvalidMoveException
10
10
11
- /* * Das Spielbrett besteht aus 8x8 Feldern. */
11
+ /* * Das Spielbrett besteht aus 8x8 Feldern mit anfänglich 8 Figuren pro Spieler . */
12
12
@XStreamAlias(value = " board" )
13
13
data 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 {
16
16
17
- constructor (): this (generateBoard ())
17
+ constructor (): this (generatePiecePositions ())
18
18
19
19
/* * Gibt das Feld an den gegebenen Koordinaten zurück. */
20
20
operator fun get (x : Int , y : Int ) =
@@ -25,19 +25,19 @@ data class Board(
25
25
* @return the moved [Piece], null if it turned into an amber. */
26
26
@Throws(InvalidMoveException ::class )
27
27
fun movePiece (move : Move ): Piece ? =
28
- board [move.start]? .let { piece ->
28
+ (piecePositions [move.start] ? : throw InvalidMoveException ( MoveMistake . START_EMPTY , move)) .let { piece ->
29
29
if (move.delta !in piece.possibleMoves)
30
30
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)
33
33
if (piece.isAmber || (piece.type.isLight && move.destination.y == piece.team.opponent().startLine)) {
34
- board .remove(move.destination)
34
+ piecePositions .remove(move.destination)
35
35
null
36
36
} else {
37
- board [move.destination] = piece
37
+ piecePositions [move.destination] = piece
38
38
piece
39
39
}
40
- } ? : throw InvalidMoveException ( MoveMistake . START_EMPTY , move)
40
+ }
41
41
42
42
override fun toString () =
43
43
boardrange.joinToString(" \n " ) { y ->
@@ -46,11 +46,14 @@ data class Board(
46
46
}
47
47
}
48
48
49
- override fun clone () = Board (HashMap (board ))
49
+ override fun clone () = Board (HashMap (piecePositions ))
50
50
51
51
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. */
52
55
@JvmStatic
53
- fun generateBoard () =
56
+ fun generatePiecePositions () =
54
57
(PieceType .values() + PieceType .values()).let { pieces ->
55
58
pieces.shuffle()
56
59
pieces.withIndex().flatMap { (index, type) ->
0 commit comments