Skip to content

Commit 97e1a67

Browse files
committed
Fix tests
1 parent 5f67283 commit 97e1a67

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

games-server/src/main/kotlin/net/zomis/games/server2/ais/ServerAI.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ class ServerAI(val gameType: String, val name: String, val perform: ServerGameAI
6464
executor.submit {
6565
try {
6666
val aiMoves = playerIndex.map {
67-
perform.invoke(game, it).map { move ->
68-
val gameImpl = move.game.obj as GameImpl<Any>
69-
val serializedMove = gameImpl.actions.type(move.moveType)!!
70-
.actionType.serialize.serialize(move.move)
71-
PlayerGameMoveRequest(move.game, move.player, move.moveType, serializedMove)
72-
}
67+
perform.invoke(game, it).map { act -> act.serialize(game.obj as GameImpl<Any>) }
7368
}
7469
aiMoves.filter { it.isNotEmpty() }.forEach {singleAIMoves ->
7570
events.execute(DelayedAIMoves(singleAIMoves))
@@ -90,4 +85,10 @@ class ServerAI(val gameType: String, val name: String, val perform: ServerGameAI
9085
events.execute(ClientJsonMessage(client, interestingGames))
9186
}
9287

93-
}
88+
}
89+
90+
fun PlayerGameMoveRequest.serialize(gameImpl: GameImpl<*>): PlayerGameMoveRequest {
91+
val serializedMove = gameImpl.actions.type(this.moveType)!!
92+
.actionType.serialize.serialize(this.move)
93+
return PlayerGameMoveRequest(this.game, this.player, this.moveType, serializedMove)
94+
}

games-server/src/test/kotlin/net/zomis/games/server2/DslRandomPlayTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import net.zomis.games.impl.SetGameModel
1515
import net.zomis.games.server2.ais.AIRepository
1616
import net.zomis.games.server2.ais.ServerAIs
1717
import net.zomis.games.server2.ais.gamescorers.SplendorScorers
18+
import net.zomis.games.server2.ais.serialize
1819
import net.zomis.games.server2.clients.WSClient
1920
import net.zomis.games.server2.clients.getInt
2021
import net.zomis.games.server2.clients.getText
@@ -136,7 +137,7 @@ class DslRandomPlayTest {
136137
} else {
137138
serverAIs.randomAction(game, playerIndex).firstOrNull()
138139
}
139-
}
140+
}.map { it.serialize(gameImpl) }
140141
if (actions.isEmpty()) {
141142
p1.sendAndExpectResponse("""{ "route": "games/$dslGame/1/view" }""")
142143
p1.expectJsonObject { it.getText("type") == "GameView" }

0 commit comments

Comments
 (0)