Skip to content

Commit 84d10ed

Browse files
committed
chore: fixup
Signed-off-by: moul <[email protected]>
1 parent 220f7a8 commit 84d10ed

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

realm/chess.gno

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ func xNewGame(opponentRaw string, seconds, increment int) string {
221221

222222
opponent := parsePlayer(opponentRaw)
223223
caller := std.GetOrigCaller()
224+
getPlayerStats(opponent).StartedGames++
225+
getPlayerStats(caller).StartedGames++
224226
assertUserNotInLobby(caller)
225227

226228
return newGame(caller, opponent, seconds, increment).json()
@@ -361,8 +363,18 @@ func MakeMove(gameID, from, to string, promote Piece) string {
361363

362364
caller := std.GetOrigCaller()
363365

364-
stats := getPlayerStats(caller)
365-
stats.Moves++
366+
// FIXME: create better helpers to avoid if/else conditions.
367+
whiteStats := getPlayerStats(g.White)
368+
blackStats := getPlayerStats(g.Black)
369+
var callerStats, opponentStats *playerStats
370+
if caller == g.White {
371+
callerStats = whiteStats
372+
opponentStats = blackStats
373+
} else {
374+
callerStats = blackStats
375+
opponentStats = whiteStats
376+
}
377+
callerStats.Moves++
366378

367379
if (isBlack && g.Black != caller) ||
368380
(!isBlack && g.White != caller) {
@@ -372,6 +384,9 @@ func MakeMove(gameID, from, to string, promote Piece) string {
372384

373385
// game is time controlled? add move to time control
374386
if g.Time != nil {
387+
whiteStats.TimedoutGames++
388+
blackStats.TimedoutGames++
389+
375390
valid := g.Time.AddMove()
376391
if !valid && len(g.Position.Moves) < 2 {
377392
g.State = GameStateAborted
@@ -424,13 +439,20 @@ func MakeMove(gameID, from, to string, promote Piece) string {
424439
case o == Checkmate && isBlack:
425440
g.State = GameStateCheckmated
426441
g.Winner = WinnerBlack
442+
blackStats.WonGames++
443+
whiteStats.LostGames++
444+
blackStats.SeriousGames++
445+
whiteStats.SeriousGames++
427446
case o == Checkmate && !isBlack:
428447
g.State = GameStateCheckmated
429448
g.Winner = WinnerWhite
449+
whiteStats.WonGames++
450+
blackStats.LostGames++
451+
blackStats.SeriousGames++
452+
whiteStats.SeriousGames++
430453
case o == Stalemate:
431454
g.State = GameStateStalemate
432455
g.Winner = WinnerDraw
433-
434456
case o == Drawn75Move:
435457
g.State = GameStateDrawn75Move
436458
g.Winner = WinnerDraw

realm/chess_test.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ var commandTests = [...]string{
145145
stats white
146146
# contains addr:g1white moves:4 started:1 won:1 lost:0 timedout:0 resigned:0 drawn:0 serious:1
147147
stats black
148-
# contains addr:g1white moves:3 started:1 won:0 lost:1 timedout:0 resigned:0 drawn:0 serious:1
148+
# contains addr:g1black moves:3 started:1 won:0 lost:1 timedout:0 resigned:0 drawn:0 serious:1
149149
`,
150150
/* XXX: TEMPORARILY DISABLED
151151
` name DrawByAgreement

0 commit comments

Comments
 (0)