Skip to content

Commit eb700f7

Browse files
committed
fix(Game): do not send repeated MoveRequests
1 parent ba70a34 commit eb700f7

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

.dev/scopes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ sdk
1818
framework
1919
network
2020
logging
21+
Game

plugin/src/main/kotlin/sc/plugin2022/Game.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ class Game(override val currentState: GameState = GameState()): AbstractGame(Gam
136136

137137
logger.debug("Performing $move")
138138
currentState.performMove(move)
139-
next()
140139
logger.debug("Current State: ${currentState.longString()}")
141140
}
142141

sdk/src/main/server-api/sc/framework/plugins/AbstractGame.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import sc.api.plugins.IMove
77
import sc.api.plugins.exceptions.GameLogicException
88
import sc.api.plugins.exceptions.NotYourTurnException
99
import sc.api.plugins.host.IGameListener
10+
import sc.protocol.room.WelcomeMessage
1011
import sc.shared.InvalidMoveException
1112
import sc.shared.PlayerScore
12-
import sc.protocol.room.WelcomeMessage
1313
import sc.shared.WinCondition
1414

1515
abstract class AbstractGame(override val pluginUUID: String) : IGameInstance, Pausable {
@@ -29,7 +29,7 @@ abstract class AbstractGame(override val pluginUUID: String) : IGameInstance, Pa
2929
/** Pause the game after current turn has finished or continue playing. */
3030
override var isPaused = false
3131
set(value) {
32-
if(!value)
32+
if(!value && moveRequestTimeout == null)
3333
step()
3434
field = value
3535
}
@@ -55,6 +55,7 @@ abstract class AbstractGame(override val pluginUUID: String) : IGameInstance, Pa
5555
if (fromPlayer != activePlayer)
5656
throw NotYourTurnException(activePlayer, fromPlayer, move)
5757
moveRequestTimeout?.let { timer ->
58+
moveRequestTimeout = null
5859
timer.stop()
5960
logger.info("Time needed for move: " + timer.timeDiff)
6061
if (timer.didTimeout()) {
@@ -63,6 +64,7 @@ abstract class AbstractGame(override val pluginUUID: String) : IGameInstance, Pa
6364
stop()
6465
} else {
6566
onRoundBasedAction(move)
67+
next()
6668
}
6769
} ?: throw GameLogicException("Move from $fromPlayer has not been requested.")
6870
}

server/src/test/java/sc/server/plugins/TestGame.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ data class TestGame(
2525
override val message = "TestGame only processes TestMove"
2626
})
2727
move.perform(currentState)
28-
next()
2928
}
3029

3130
override fun checkWinCondition(): WinCondition? {

0 commit comments

Comments
 (0)