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 736932 - Don’t use a timeout when the AI is too slow.
Don’t use a timeout when the AI is too slow.
Status: RESOLVED FIXED
Product: iagno
Classification: Applications
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: iagno-maint
iagno-maint
Depends on:
Blocks: 736941
 
 
Reported: 2014-09-18 22:25 UTC by Arnaud B.
Modified: 2014-09-19 13:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Don't use a timeout when the AI is too slow. (7.27 KB, patch)
2014-09-18 22:25 UTC, Arnaud B.
needs-work Details | Review
computer-player: split searching out of move() (1.98 KB, patch)
2014-09-19 04:21 UTC, Michael Catanzaro
committed Details | Review
Calculate move delay after performing search (5.78 KB, patch)
2014-09-19 04:21 UTC, Michael Catanzaro
committed Details | Review

Description Arnaud B. 2014-09-18 22:25:29 UTC
Created attachment 286540 [details] [review]
Don't use a timeout when the AI is too slow.

The AI is really slow at level 3, so having a timeout that adds two second before it plays is a quite bad idea. I’m trying so to create a “minimal timeout”, that doesn’t add time if the AI takes more than this time. Here is the code, but I’m not really happy with it… Some ideas?

Oh, it’s build on top of the files renaming.
Comment 1 Michael Catanzaro 2014-09-19 01:12:56 UTC
Review of attachment 286540 [details] [review]:

::: src/iagno-main.vala
@@ +367,3 @@
+            timeout_running = true;
+            /* PIXMAP_FLIP_DELAY * 31 frames, needed for the animation */
+            computer_timer1 = Timeout.add (620, computer_move_cb);

Does this fix the animation glitch that sometimes occurs on the last turn of the game?
Comment 2 Michael Catanzaro 2014-09-19 04:21:21 UTC
Review of attachment 286540 [details] [review]:

::: src/iagno-main.vala
@@ +41,3 @@
+    private uint computer_timer2 = 0;
+    private uint computer_timer3 = 0;
+    private bool timeout_running = false;

It might be past my bedtime, but I can't follow what these are all used for... I can see why you said you weren't satisfied with this approach. ^^  Alternative suggestion incoming....

@@ +377,3 @@
+
+        if (game.n_tiles != 4 && game.n_tiles != 63 && !fast_mode)
+            computer_timer2 = Timeout.add_seconds (1, () => { timeout_running = false; computer_timer2 = 0; return false; });

Our style for lambdas is:

computer_timer2 = Timeout.add_seconds (1, () => {
    ...;
    ...;
    ....;
});

@@ +385,3 @@
+        computer.move (ref x, ref y);
+        computer_timer3 = Timeout.add (100, () =>
+            {

Style: opening brace one space after the => for lambdas.
Comment 3 Michael Catanzaro 2014-09-19 04:21:35 UTC
Created attachment 286550 [details] [review]
computer-player: split searching out of move()

Let's split the move action out from the search logic, so that we can do
more complex things in move(), like returning after a delay and running
the search in another thread.
Comment 4 Michael Catanzaro 2014-09-19 04:21:37 UTC
Created attachment 286551 [details] [review]
Calculate move delay after performing search

Right now, we add a fixed amount of delay before each move, then start
the search. This means that the game takes longer to move on higher
difficulty levels and slower computers. Mitigate this by computing
artifical delay after the completion of the search instead. (This means
the AI will now move a bit faster than before.)
Comment 5 Arnaud B. 2014-09-19 08:08:03 UTC
I don’t understand the technology you’re using, but it doesn’t work… The drawing and animation of the human player’s tile isn’t done before the AI finish its thinking (many seconds after you clicked the board). Try in level 3 (after the two first random move)…
Comment 6 Arnaud B. 2014-09-19 08:26:11 UTC
Oh, sorry, didn’t see the other bug[1].

(In reply to comment #1)
> ::: src/iagno-main.vala
> @@ +367,3 @@
> +            timeout_running = true;
> +            /* PIXMAP_FLIP_DELAY * 31 frames, needed for the animation */
> +            computer_timer1 = Timeout.add (620, computer_move_cb);
> 
> Does this fix the animation glitch that sometimes occurs on the last turn of
> the game?

I don’t know which glitch you’re talking about. Maybe. ^^ It should fix (even if I don’t tried) the fast-mode bug where tiles are blocked by the AI thinking, without requiring threads. But if we use threads… no need for me to change the (minimal) delays.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=736941
Comment 7 Michael Catanzaro 2014-09-19 13:56:18 UTC
(In reply to comment #5)
> I don’t understand the technology you’re using, but it doesn’t work… The
> drawing and animation of the human player’s tile isn’t done before the AI
> finish its thinking (many seconds after you clicked the board). Try in level 3
> (after the two first random move)…

Well, I didn't even notice this, so it's good that you pointed it out. But yeah, that's inadvertently fixed by the patch in bug #736941.

(In reply to comment #6)
> I don’t know which glitch you’re talking about. Maybe. ^^ It should fix (even
> if I don’t tried) the fast-mode bug where tiles are blocked by the AI thinking,
> without requiring threads.

I'm not familiar with this bug? Maybe a screencast (or longer description) will help me understand.

We really ought to run the search in another thread regardless; otherwise, the UI becomes unresponsive while the AI is thinking. It's only really apparent if you increase the search depth.
Comment 8 Michael Catanzaro 2014-09-19 13:56:46 UTC
Attachment 286550 [details] pushed as 1b5b968 - computer-player: split searching out of move()
Attachment 286551 [details] pushed as 14a996c - Calculate move delay after performing search