@@ -221,6 +221,8 @@ func xNewGame(opponentRaw string, seconds, increment int) string {
221
221
222
222
opponent := parsePlayer(opponentRaw)
223
223
caller := std.GetOrigCaller()
224
+ getPlayerStats(opponent).StartedGames++
225
+ getPlayerStats(caller).StartedGames++
224
226
assertUserNotInLobby(caller)
225
227
226
228
return newGame(caller, opponent, seconds, increment).json()
@@ -361,8 +363,18 @@ func MakeMove(gameID, from, to string, promote Piece) string {
361
363
362
364
caller := std.GetOrigCaller()
363
365
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++
366
378
367
379
if (isBlack && g.Black != caller) ||
368
380
(!isBlack && g.White != caller) {
@@ -372,6 +384,9 @@ func MakeMove(gameID, from, to string, promote Piece) string {
372
384
373
385
// game is time controlled? add move to time control
374
386
if g.Time != nil {
387
+ whiteStats.TimedoutGames++
388
+ blackStats.TimedoutGames++
389
+
375
390
valid := g.Time.AddMove()
376
391
if !valid && len(g.Position.Moves) < 2 {
377
392
g.State = GameStateAborted
@@ -424,13 +439,20 @@ func MakeMove(gameID, from, to string, promote Piece) string {
424
439
case o == Checkmate && isBlack:
425
440
g.State = GameStateCheckmated
426
441
g.Winner = WinnerBlack
442
+ blackStats.WonGames++
443
+ whiteStats.LostGames++
444
+ blackStats.SeriousGames++
445
+ whiteStats.SeriousGames++
427
446
case o == Checkmate && !isBlack:
428
447
g.State = GameStateCheckmated
429
448
g.Winner = WinnerWhite
449
+ whiteStats.WonGames++
450
+ blackStats.LostGames++
451
+ blackStats.SeriousGames++
452
+ whiteStats.SeriousGames++
430
453
case o == Stalemate:
431
454
g.State = GameStateStalemate
432
455
g.Winner = WinnerDraw
433
-
434
456
case o == Drawn75Move:
435
457
g.State = GameStateDrawn75Move
436
458
g.Winner = WinnerDraw
0 commit comments