Skip to content

Commit

Permalink
fix(plugin25): reorder Cards
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Jul 4, 2024
1 parent a558cac commit 68d70c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions plugin2025/src/main/kotlin/sc/plugin2025/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ import sc.shared.IMoveMistake
@XStreamAlias(value = "card")
enum class Card(val label: String, val moves: Boolean, val check: (GameState) -> HuIMoveMistake?, val play: (GameState) -> Unit):
HuIAction {
/** Falle hinter den Gegenspieler. */
FALL_BACK("Zurückfallen", true,
{ state ->
HuIMoveMistake.CANNOT_PLAY_FALL_BACK.takeUnless { state.isAhead() }
?: state.validateTargetField(state.otherPlayer.position - 1)
},
{ it.moveToField(it.otherPlayer.position - 1) }),
/** Rücke vor den Gegenspieler. */
HURRY_AHEAD("Vorrücken", true,
{ state ->
HuIMoveMistake.CANNOT_PLAY_HURRY_AHEAD.takeIf { state.isAhead() }
?: state.validateTargetField(state.otherPlayer.position + 1)
},
{ it.moveToField(it.otherPlayer.position + 1) }),
/** Friss sofort einen Salat. */
EAT_SALAD("Salat fressen", false,
{ state -> HuIMoveMistake.NO_SALAD.takeUnless { state.currentPlayer.salads > 0 } },
Expand All @@ -41,7 +27,22 @@ enum class Card(val label: String, val moves: Boolean, val check: (GameState) ->
val car = state.currentPlayer.carrots
state.currentPlayer.carrots = state.otherPlayer.carrots
state.otherPlayer.carrots = car
});
}),
/** Falle hinter den Gegenspieler. */
FALL_BACK("Zurückfallen", true,
{ state ->
HuIMoveMistake.CANNOT_PLAY_FALL_BACK.takeUnless { state.isAhead() }
?: state.validateTargetField(state.otherPlayer.position - 1)
},
{ it.moveToField(it.otherPlayer.position - 1) }),
/** Rücke vor den Gegenspieler. */
HURRY_AHEAD("Vorrücken", true,
{ state ->
HuIMoveMistake.CANNOT_PLAY_HURRY_AHEAD.takeIf { state.isAhead() }
?: state.validateTargetField(state.otherPlayer.position + 1)
},
{ it.moveToField(it.otherPlayer.position + 1) }),
;

override fun perform(state: GameState): IMoveMistake? {
if(state.currentField != Field.HARE)
Expand Down
2 changes: 1 addition & 1 deletion plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ data class GameState @JvmOverloads constructor(
fun nextCards(player: Hare = currentPlayer): Collection<Array<Card>>? =
when(player.field) {
Field.HARE -> {
player.getCards().toSet().flatMap { card ->
HashSet(player.getCards()).flatMap { card ->
if(card.check(this) == null) {
val newState = clone()
newState.currentPlayer.removeCard(card)
Expand Down

0 comments on commit 68d70c2

Please sign in to comment.