File tree Expand file tree Collapse file tree 7 files changed +22
-8
lines changed
plugin2025/src/main/kotlin/sc/plugin2025
plugin2026/src/test/kotlin/sc
plugin/src/main/kotlin/sc/plugin2023
sdk/src/main/server-api/sc Expand file tree Collapse file tree 7 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ data class GameState @JvmOverloads constructor(
36
36
if (board[move.from].penguin != currentTeam)
37
37
throw InvalidMoveException (MoveMistake .WRONG_COLOR , move)
38
38
if (currentPieces.size < PenguinConstants .PENGUINS )
39
- throw InvalidMoveException (PenguinsMoveMistake .PENGUINS , move)
39
+ throw InvalidMoveException (PenguinsMoveMistake .PLACE_PENGUINS_FIRST , move)
40
40
if (! move.to.minus(move.from).straightHex)
41
41
throw InvalidMoveException (MoveMistake .INVALID_MOVE , move)
42
42
// TODO avoid this check
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import sc.shared.IMoveMistake
10
10
*/
11
11
enum class PenguinsMoveMistake (override val message : String ): IMoveMistake {
12
12
SINGLE_FISH (" Pinguine können nur auf einzelne Fische gesetzt werden" ),
13
- PENGUINS (" Setze zuerst alle Pinguine" ),
13
+ PLACE_PENGUINS_FIRST (" Setze zuerst alle Pinguine" ),
14
14
MAX_PENGUINS (" Bereits alle Pinguine gesetzt" );
15
15
override fun toString () = message
16
16
}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ object GameRuleLogic {
10
10
* @param moveCount Anzahl der Felder, um die bewegt wird
11
11
* @return Anzahl der benötigten Karotten
12
12
*/
13
+ @JvmStatic
13
14
fun calculateCarrots (moveCount : Int ): Int =
14
15
(moveCount * (moveCount + 1 )) / 2
15
16
@@ -19,6 +20,7 @@ object GameRuleLogic {
19
20
* @param carrots maximal ausgegebene Karotten
20
21
* @return Felder um die maximal bewegt werden kann
21
22
*/
23
+ @JvmStatic
22
24
fun calculateMoveableFields (carrots : Int ): Int {
23
25
return when {
24
26
carrots >= 990 -> 44
Original file line number Diff line number Diff line change @@ -92,7 +92,8 @@ data class GameState @JvmOverloads constructor(
92
92
fun clonePlayer (team : Team = currentTeam, transform : (Hare ) -> Unit = {}) =
93
93
copy(players = players.map { if (it.team == team) it.clone().apply (transform) else it })
94
94
95
- override fun getSensibleMoves (): List <Move > = getSensibleMoves(currentPlayer)
95
+ override fun getSensibleMoves (): List <Move > =
96
+ getSensibleMoves(currentPlayer)
96
97
97
98
fun getSensibleMoves (player : Hare ): List <Move > {
98
99
if (mustEatSalad(player))
Original file line number Diff line number Diff line change
1
+ package sc ;
2
+
3
+ import sc .plugin2026 .util .GameRuleLogic ;
4
+
5
+ public class GameRuleLogicTest {
6
+ public static void main (String [] args ) {
7
+ GameRuleLogic .possibleMovesFor (null , null ).iterator ();
8
+ }
9
+ }
Original file line number Diff line number Diff line change @@ -53,17 +53,17 @@ open class RectangularBoard<FIELD: IField<FIELD>>(
53
53
/* * Vergleicht zwei Spielfelder und gibt eine Liste aller Felder zurück, die sich unterscheiden. */
54
54
fun compare (other : RectangularBoard <FIELD >): Collection <FIELD > {
55
55
val entries = this .entries
56
- return other.entries.filter {
57
- it !in entries
58
- } .map { it.value }
56
+ return other.entries
57
+ .filter { it !in entries }
58
+ .map { it.value }
59
59
}
60
60
61
61
override fun toString () =
62
62
gameField.joinToString(separator = " \n " ) { row ->
63
63
row.joinToString(separator = " " ) { it.toString() }
64
64
}.ifEmpty { " Empty Board@" + System .identityHashCode(this ) }
65
65
66
- override val entries: Set <Map . Entry < Coordinates , FIELD >>
66
+ override val entries: Set <Positioned < FIELD >>
67
67
get() = gameField.flatMapIndexedTo(HashSet ()) { y, row ->
68
68
row.mapIndexed { x, field ->
69
69
Positioned (Coordinates (x, y), field)
Original file line number Diff line number Diff line change @@ -217,8 +217,10 @@ abstract class AbstractGame<M : IMove>(protected val plugin: IGamePlugin<M>): IG
217
217
* @return WinCondition, or null if game is not regularly over yet
218
218
*/
219
219
fun checkWinCondition (): WinCondition ? =
220
- currentWinner(). takeIf { currentState.isOver }
220
+ currentState.winCondition
221
221
222
+ // TODO this function is useless cause it is only used when the game is over
223
+ // in which case currentState.winCondition is not null anyway
222
224
fun currentWinner (): WinCondition {
223
225
val teams = Team .values()
224
226
val scores = teams.map { currentState.getPointsForTeam(it) }
You can’t perform that action at this time.
0 commit comments