Skip to content

Commit ac65050

Browse files
committed
feat(gameLogic): Add miss moves
1 parent fa1beea commit ac65050

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

plugin/src/shared/sc/plugin2020/Move.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ data class SetMove(val piece: Piece, val destination: CubeCoordinates): IMove {
1313
data class DragMove(val start: CubeCoordinates, val destination: CubeCoordinates): IMove {
1414
override fun toString() = String.format("Drag from %s to %s", this.start, this.destination)
1515
}
16+
17+
@XStreamAlias(value = "missmove")
18+
data class MissMove(val type: String = "miss"): IMove {
19+
override fun toString() = "Miss move"
20+
}

plugin/src/shared/sc/plugin2020/util/GameRuleLogic.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import sc.api.plugins.IMove
44
import sc.plugin2020.*
55
import sc.shared.InvalidMoveException
66
import sc.shared.PlayerColor
7-
import java.util.*
8-
import kotlin.collections.ArrayList
97
import kotlin.math.abs
108

119
object GameRuleLogic {
@@ -86,10 +84,19 @@ object GameRuleLogic {
8684
when (move) {
8785
is SetMove -> validateSetMove(gameState, move)
8886
is DragMove -> validateDragMove(gameState, move)
87+
is MissMove -> validateMissMove(gameState)
8988
}
9089
return true
9190
}
92-
91+
92+
private fun validateMissMove(gameState: GameState): Boolean {
93+
if(this.getPossibleMoves(gameState).isNotEmpty())
94+
throw InvalidMoveException("Missing a turn is only allowed when no other moves can be made.")
95+
if(gameState.round == 3 && !hasPlayerPlacedBee(gameState))
96+
throw InvalidMoveException("The bee must be placed in fourth round latest")
97+
return true
98+
}
99+
93100
@Throws(InvalidMoveException::class)
94101
@JvmStatic
95102
fun validateSetMove(gameState: GameState, move: SetMove): Boolean {
@@ -107,7 +114,7 @@ object GameRuleLogic {
107114
}
108115
} else {
109116
if (gameState.round == 3 && !hasPlayerPlacedBee(gameState) && move.piece.type != PieceType.BEE)
110-
throw InvalidMoveException("The Bee must be placed in fourth round latest")
117+
throw InvalidMoveException("The bee must be placed in fourth round latest")
111118

112119
if (!gameState.getUndeployedPieces(gameState.currentPlayerColor).contains(move.piece))
113120
throw InvalidMoveException("Piece is not a undeployed piece of the current player")

plugin/src/test/sc/plugin2020/GamePlayTest.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ class GamePlayTest {
342342
state.turn = 6
343343
val setAnt = SetMove(Piece(PlayerColor.RED, PieceType.ANT), CubeCoordinates(-4, 5))
344344
assertThrows(InvalidMoveException::class.java) { GameRuleLogic.validateMove(state, setAnt) }
345+
val miss = MissMove()
346+
assertThrows(InvalidMoveException::class.java) { GameRuleLogic.validateMove(state, miss) }
345347
val setBee = SetMove(Piece(PlayerColor.RED, PieceType.BEE), CubeCoordinates(-4, 5))
346348
assertTrue(GameRuleLogic.validateMove(state, setBee))
347349
}
@@ -1206,4 +1208,40 @@ class GamePlayTest {
12061208
assertEquals(1, GameRuleLogic.getPossibleDragMoves(state).size)
12071209
}
12081210
}
1211+
1212+
@Test
1213+
fun missMoveTest() {
1214+
run {
1215+
TestGameUtil.updateGamestateWithBoard(state, "" +
1216+
" ------------" +
1217+
" --------------" +
1218+
" ----------------" +
1219+
" RGBG--------------" +
1220+
" --------------------" +
1221+
"----------------------" +
1222+
" --------------------" +
1223+
" ------------------" +
1224+
" ----------------" +
1225+
" --------------" +
1226+
" ------------")
1227+
val invalid = MissMove()
1228+
assertThrows(InvalidMoveException::class.java) { GameRuleLogic.validateMove(state, invalid) }
1229+
}
1230+
run {
1231+
TestGameUtil.updateGamestateWithBoard(state, "" +
1232+
" RA----------" +
1233+
" --BG----------" +
1234+
" ----------------" +
1235+
" ------------------" +
1236+
" --------------------" +
1237+
"----------------------" +
1238+
" --------------------" +
1239+
" ------------------" +
1240+
" ----------------" +
1241+
" --------------" +
1242+
" ------------")
1243+
val valid = MissMove()
1244+
assertTrue(GameRuleLogic.validateMove(state, valid))
1245+
}
1246+
}
12091247
}

0 commit comments

Comments
 (0)