After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 779598 - When playing time-bound game, wrong player wins
When playing time-bound game, wrong player wins
Status: RESOLVED OBSOLETE
Product: gnome-chess
Classification: Applications
Component: General
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: Sahil Sareen
gnome-chess-maint
Depends on:
Blocks:
 
 
Reported: 2017-03-05 00:10 UTC by Alessandro Bruni
Modified: 2018-05-22 12:26 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Screenshot of the match with wrong result. (48.83 KB, image/png)
2017-03-05 00:10 UTC, Alessandro Bruni
  Details
Preferences set to Simple clock (32.34 KB, image/png)
2017-03-31 13:51 UTC, Sahil Sareen
  Details
Simple clock & white wins the game (64.25 KB, image/png)
2017-03-31 13:52 UTC, Sahil Sareen
  Details
Simple clock & black wins the game (63.83 KB, image/png)
2017-03-31 13:53 UTC, Sahil Sareen
  Details
Preferences set to Fischer clock (35.03 KB, image/png)
2017-03-31 13:53 UTC, Sahil Sareen
  Details
Fischer clock & white wins the game (64.90 KB, image/png)
2017-03-31 13:55 UTC, Sahil Sareen
  Details
Fischer clock & black wins the game (63.90 KB, image/png)
2017-03-31 13:56 UTC, Sahil Sareen
  Details
Preferences set to Bronstein clock (35.96 KB, image/png)
2017-03-31 13:56 UTC, Sahil Sareen
  Details
Bronstein clock & black wins the game (63.79 KB, image/png)
2017-03-31 13:57 UTC, Sahil Sareen
  Details
Bronstein clock & white wins the game (63.72 KB, image/png)
2017-03-31 13:58 UTC, Sahil Sareen
  Details
Move on the last second consistently shows the bug (68.82 KB, image/png)
2017-04-18 22:03 UTC, Alessandro Bruni
  Details
Should fix the bug (1.39 KB, patch)
2017-04-18 22:46 UTC, Alessandro Bruni
none Details | Review
Updated patch (1.39 KB, patch)
2017-04-19 10:56 UTC, Alessandro Bruni
none Details | Review
Updated patch (1.39 KB, patch)
2017-04-19 13:36 UTC, Alessandro Bruni
needs-work Details | Review

Description Alessandro Bruni 2017-03-05 00:10:42 UTC
Created attachment 347241 [details]
Screenshot of the match with wrong result.

I experienced on a time-bound match that at the end of the game the wrong person is said to have won it. I tried it a couple of times but cannot reproduce it again. See attached screenshot.
Comment 1 Sahil Sareen 2017-03-12 12:25:04 UTC
I'll try reproducing this, Could you attach the saved game pgn file if you still have it?
Comment 2 Alessandro Bruni 2017-03-13 18:18:41 UTC
Unfortunately not. When I come across it again I'll save it.
Comment 3 Sahil Sareen 2017-03-20 22:37:15 UTC
Do you remember the clock type that was being used, or any settings from the preferences dialog?
Comment 4 Sahil Sareen 2017-03-31 13:19:12 UTC
Related bug found while trying to reproduce this issue: https://bugzilla.gnome.org/show_bug.cgi?id=779937 (Already fixed).
Comment 5 Sahil Sareen 2017-03-31 13:19:23 UTC
Looking into all possible combinations of clock types and black/white winning to try to reproduce this.
Comment 6 Sahil Sareen 2017-03-31 13:51:50 UTC
Created attachment 349046 [details]
Preferences set to Simple clock
Comment 7 Sahil Sareen 2017-03-31 13:52:23 UTC
Created attachment 349047 [details]
Simple clock & white wins the game
Comment 8 Sahil Sareen 2017-03-31 13:53:14 UTC
Created attachment 349048 [details]
Simple clock & black wins the game
Comment 9 Sahil Sareen 2017-03-31 13:53:37 UTC
Created attachment 349049 [details]
Preferences set to Fischer clock
Comment 10 Sahil Sareen 2017-03-31 13:55:17 UTC
Created attachment 349050 [details]
Fischer clock & white wins the game
Comment 11 Sahil Sareen 2017-03-31 13:56:29 UTC
Created attachment 349051 [details]
Fischer clock & black wins the game
Comment 12 Sahil Sareen 2017-03-31 13:56:58 UTC
Created attachment 349052 [details]
Preferences set to Bronstein clock
Comment 13 Sahil Sareen 2017-03-31 13:57:22 UTC
Created attachment 349055 [details]
Bronstein clock & black wins the game
Comment 14 Sahil Sareen 2017-03-31 13:58:04 UTC
Created attachment 349056 [details]
Bronstein clock & white wins the game
Comment 15 Sahil Sareen 2017-03-31 14:12:10 UTC
The problem doesn't seem to be happening in the current state as it looks like from my testing.

Alessandro, Can you please update to the latest release if not already there? [1]

I'm resolving this for now, please reopen if you happen to hit it again and attach to the bug:
- Saved game PGN file
- gnome-chess -> "Preferences"
- Version from gnome-chess -> "About"


[1]: https://git.gnome.org/browse/gnome-chess/refs/
Comment 16 Alessandro Bruni 2017-04-16 22:22:32 UTC
Hi all, I would like to reopen this bug as I found a way to consistently reproduce it after looking at your code.

Specifically, the method clock_expired_cb in lib/chess-game.vala, line 314. When the clock expires, it checks who is the current player and assigns the victory to the opponent. However if the player whose clock is going to expire makes a move in the last second, the other player will be the current player when the clock expires, hence the victory will be reported incorrectly.

You can reproduce this consistently by:
1. starting a time-limited game
2. letting one player's time almost expire
3. on the last second, making a move
the player whose clock still has plenty of time will be marked as loser.

Proposed solution: instead of checking whose turn it is when the clock expires, check which player has no time left.

I hope this helps.
Comment 17 Sahil Sareen 2017-04-17 16:00:13 UTC
Thanks for your report, I'll take a look at it now.
Comment 18 Alessandro Bruni 2017-04-18 22:03:44 UTC
Created attachment 350032 [details]
Move on the last second consistently shows the bug
Comment 19 Sahil Sareen 2017-04-18 22:08:15 UTC
I'm wrapping up a proposal for a talk for GUADEC, I'll look at this first thing after I finish that.
Comment 20 Alessandro Bruni 2017-04-18 22:46:26 UTC
Created attachment 350033 [details] [review]
Should fix the bug
Comment 21 Alessandro Bruni 2017-04-18 22:51:01 UTC
Hi Sahil, it wasn't my intention to put pressure, rather I wanted to document the fix :)
I just attached a patch, seems to work on my machine.

Best,
Alessandro
Comment 22 Mario Wenzel 2017-04-19 09:45:07 UTC
Review of attachment 350033 [details] [review]:

::: lib/chess-game.vala
@@ +284,3 @@
     private void clock_expired_cb (ChessClock clock)
     {
+        if (clock.white_remaining_seconds == 0)

Please check for less-or-equal zero. I do think that with the callbacks there are potential timing issues that would allow this to become negative at least by one.

Haven't checked the other code so if there is something that already checks for this case and prevents it, please ignore.
Comment 23 Alessandro Bruni 2017-04-19 10:56:24 UTC
Created attachment 350059 [details] [review]
Updated patch
Comment 24 Mario Wenzel 2017-04-19 11:48:38 UTC
Review of attachment 350059 [details] [review]:

::: lib/chess-game.vala
@@ +284,3 @@
     private void clock_expired_cb (ChessClock clock)
     {
+        if (clock.white_remaining_seconds == 0)

Please check for less-or-equal zero. I do think that with the callbacks there are potential timing issues that would allow this to become negative at least by one.

Haven't checked the other code so if there is something that already checks for this case and prevents it, please ignore.
Comment 25 Alessandro Bruni 2017-04-19 13:36:46 UTC
Created attachment 350072 [details] [review]
Updated patch

Sorry I thought I had updated it instead it was the same file as before.
Comment 26 Sahil Sareen 2017-04-19 13:58:09 UTC
Comment on attachment 350072 [details] [review]
Updated patch

Thanks for the patch! :)

You should probably also need to take care of white_extra_seconds and black_extra_seconds which are used for Fischer and Bronstein clocks. Can you test play a game with custom clocks instead of the simple clock please?
Comment 27 Michael Catanzaro 2017-09-09 04:08:40 UTC
Comment on attachment 350072 [details] [review]
Updated patch

Looks like Sahil left some review comments that still need to be addressed.
Comment 28 GNOME Infrastructure Team 2018-05-22 12:26:54 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gnome-chess/issues/25.