@@ -10,61 +10,61 @@ import sc.shared.InvalidMoveException
10
10
11
11
class GameStateTest : StringSpec ({
12
12
" GameState starts correctly" {
13
- val gameState = GameState ()
13
+ val state = GameState ()
14
14
15
- gameState .board shouldBe Board ()
15
+ state .board shouldBe Board ()
16
16
17
- gameState .undeployedPieceShapes[Color .BLUE ] shouldBe PieceShape .values().toSet()
18
- gameState .undeployedPieceShapes[Color .YELLOW ] shouldBe PieceShape .values().toSet()
19
- gameState .undeployedPieceShapes[Color .RED ] shouldBe PieceShape .values().toSet()
20
- gameState .undeployedPieceShapes[Color .GREEN ] shouldBe PieceShape .values().toSet()
17
+ state .undeployedPieceShapes[Color .BLUE ] shouldBe PieceShape .values().toSet()
18
+ state .undeployedPieceShapes[Color .YELLOW ] shouldBe PieceShape .values().toSet()
19
+ state .undeployedPieceShapes[Color .RED ] shouldBe PieceShape .values().toSet()
20
+ state .undeployedPieceShapes[Color .GREEN ] shouldBe PieceShape .values().toSet()
21
21
22
- gameState .deployedPieces[Color .BLUE ] shouldBe mutableListOf<Piece >()
23
- gameState .deployedPieces[Color .YELLOW ] shouldBe mutableListOf<Piece >()
24
- gameState .deployedPieces[Color .RED ] shouldBe mutableListOf<Piece >()
25
- gameState .deployedPieces[Color .GREEN ] shouldBe mutableListOf<Piece >()
22
+ state .deployedPieces[Color .BLUE ] shouldBe mutableListOf<Piece >()
23
+ state .deployedPieces[Color .YELLOW ] shouldBe mutableListOf<Piece >()
24
+ state .deployedPieces[Color .RED ] shouldBe mutableListOf<Piece >()
25
+ state .deployedPieces[Color .GREEN ] shouldBe mutableListOf<Piece >()
26
26
27
27
// TODO: adjust values accordingly
28
- gameState .getPointsForPlayer(Team .ONE ) shouldBe -178 // Twice the lowest score, once per color
29
- gameState .getPointsForPlayer(Team .TWO ) shouldBe -178
28
+ state .getPointsForPlayer(Team .ONE ) shouldBe -178 // Twice the lowest score, once per color
29
+ state .getPointsForPlayer(Team .TWO ) shouldBe -178
30
30
}
31
31
" GameStates know currently active Color" {
32
32
var colorIter = Color .RED
33
- val gameState = GameState (startColor = colorIter)
33
+ val state = GameState (startColor = colorIter)
34
34
35
35
for (x in 0 until 4) {
36
- gameState .currentColor shouldBe colorIter
37
- gameState .turn++
36
+ state .currentColor shouldBe colorIter
37
+ state .turn++
38
38
colorIter = colorIter.next
39
39
}
40
40
41
- gameState .currentColor shouldBe Color .RED
42
- gameState .turn++
43
- gameState .currentColor shouldBe Color .GREEN
44
- gameState .turn += 2
45
- gameState .currentColor shouldBe Color .YELLOW
41
+ state .currentColor shouldBe Color .RED
42
+ state .turn++
43
+ state .currentColor shouldBe Color .GREEN
44
+ state .turn += 2
45
+ state .currentColor shouldBe Color .YELLOW
46
46
}
47
47
" Pieces can only be placed once" {
48
- val gameState = GameState (startPiece = PieceShape .PENTO_I )
48
+ val state = GameState (startPiece = PieceShape .PENTO_I )
49
49
val move = SetMove (
50
50
Piece (Color .BLUE , PieceShape .PENTO_I , Rotation .RIGHT , true))
51
51
52
- gameState .undeployedPieceShapes.getValue(Color .BLUE ).size shouldBe 21
53
- gameState .deployedPieces.getValue(Color .BLUE ).size shouldBe 0
52
+ state .undeployedPieceShapes.getValue(Color .BLUE ).size shouldBe 21
53
+ state .deployedPieces.getValue(Color .BLUE ).size shouldBe 0
54
54
assertDoesNotThrow {
55
- GameRuleLogic .performMove(gameState , move)
55
+ GameRuleLogic .performMove(state , move)
56
56
}
57
- gameState .undeployedPieceShapes.getValue(Color .BLUE ).size shouldBe 20
58
- gameState .deployedPieces.getValue(Color .BLUE ).size shouldBe 1
59
- gameState .deployedPieces.getValue(Color .BLUE )[0 ] shouldBe move.piece
57
+ state .undeployedPieceShapes.getValue(Color .BLUE ).size shouldBe 20
58
+ state .deployedPieces.getValue(Color .BLUE ).size shouldBe 1
59
+ state .deployedPieces.getValue(Color .BLUE )[0 ] shouldBe move.piece
60
60
61
- gameState .turn += 4
61
+ state .turn += 4
62
62
assertThrows<InvalidMoveException > {
63
- GameRuleLogic .performMove(gameState , move)
63
+ GameRuleLogic .performMove(state , move)
64
64
}
65
- gameState .undeployedPieceShapes.getValue(Color .BLUE ).size shouldBe 20
66
- gameState .deployedPieces.getValue(Color .BLUE ).size shouldBe 1
67
- gameState .deployedPieces.getValue(Color .BLUE )[0 ] shouldBe move.piece
65
+ state .undeployedPieceShapes.getValue(Color .BLUE ).size shouldBe 20
66
+ state .deployedPieces.getValue(Color .BLUE ).size shouldBe 1
67
+ state .deployedPieces.getValue(Color .BLUE )[0 ] shouldBe move.piece
68
68
69
69
}
70
70
" XML conversion works" {
@@ -73,31 +73,36 @@ class GameStateTest: StringSpec({
73
73
74
74
xstream.fromXML(xstream.toXML(state)).toString() shouldBe state.toString()
75
75
xstream.fromXML(xstream.toXML(state)) shouldBe state
76
+
77
+ val transformed = xstream.fromXML(xstream.toXML(GameState ())) as GameState
78
+ transformed.deployedPieces shouldBe null
79
+ GameRuleLogic .isFirstMove(transformed) shouldBe true
80
+ transformed.getPointsForPlayer(Team .ONE )
76
81
}
77
82
" GameStates advance accordingly" {
78
- var gameState = GameState (startTurn = 2)
79
- gameState .turn shouldBe 2
80
- gameState .round shouldBe 1
81
- gameState .currentColor shouldBe Color .RED
83
+ var state = GameState (startTurn = 2)
84
+ state .turn shouldBe 2
85
+ state .round shouldBe 1
86
+ state .currentColor shouldBe Color .RED
82
87
83
- gameState = GameState ()
84
- gameState .turn shouldBe 0
85
- gameState .round shouldBe 1
86
- gameState .currentColor shouldBe Color .BLUE
88
+ state = GameState ()
89
+ state .turn shouldBe 0
90
+ state .round shouldBe 1
91
+ state .currentColor shouldBe Color .BLUE
87
92
88
- gameState .turn +=10
89
- gameState .turn shouldBe 10
90
- gameState .round shouldBe 3
91
- gameState .currentColor shouldBe Color .RED
93
+ state .turn +=10
94
+ state .turn shouldBe 10
95
+ state .round shouldBe 3
96
+ state .currentColor shouldBe Color .RED
92
97
93
- gameState .turn++
94
- gameState .turn shouldBe 11
95
- gameState .round shouldBe 3
96
- gameState .currentColor shouldBe Color .GREEN
98
+ state .turn++
99
+ state .turn shouldBe 11
100
+ state .round shouldBe 3
101
+ state .currentColor shouldBe Color .GREEN
97
102
98
- gameState .turn++
99
- gameState .turn shouldBe 12
100
- gameState .round shouldBe 4
101
- gameState .currentColor shouldBe Color .BLUE
103
+ state .turn++
104
+ state .turn shouldBe 12
105
+ state .round shouldBe 4
106
+ state .currentColor shouldBe Color .BLUE
102
107
}
103
108
})
0 commit comments