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 737410 - [PATCH] Analyse the game at the end of turn.
[PATCH] Analyse the game at the end of turn.
Status: RESOLVED FIXED
Product: iagno
Classification: Applications
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: iagno-maint
iagno-maint
Depends on:
Blocks: 737715
 
 
Reported: 2014-09-26 09:36 UTC by Arnaud B.
Modified: 2014-10-01 17:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Analyse the game at the end of turn. (13.81 KB, patch)
2014-09-26 09:36 UTC, Arnaud B.
reviewed Details | Review
AI: Don't manage a pass as a move. (3.99 KB, patch)
2014-09-26 11:42 UTC, Arnaud B.
accepted-commit_now Details | Review
Don't make unnecessary moves. (6.53 KB, patch)
2014-09-26 12:54 UTC, Arnaud B.
reviewed Details | Review
Create get_possible_moves_sorted(). (2.08 KB, patch)
2014-09-26 13:22 UTC, Arnaud B.
none Details | Review
Do the first iteration in a different function. (6.31 KB, patch)
2014-09-26 19:19 UTC, Arnaud B.
reviewed Details | Review
Analyse the game at the end of turn. (13.59 KB, patch)
2014-09-27 05:56 UTC, Arnaud B.
reviewed Details | Review
AI: Don't manage a pass as a move. (3.99 KB, patch)
2014-09-27 06:02 UTC, Arnaud B.
committed Details | Review
Don't make unnecessary moves. (3.33 KB, patch)
2014-09-27 06:10 UTC, Arnaud B.
committed Details | Review
Do the first iteration in a different function. (6.61 KB, patch)
2014-09-27 06:30 UTC, Arnaud B.
committed Details | Review
Don't use six lines for a corner-case. (1.28 KB, patch)
2014-09-27 06:42 UTC, Arnaud B.
none Details | Review
Don't use six lines for a corner-case. (1.29 KB, patch)
2014-09-27 06:47 UTC, Arnaud B.
committed Details | Review
Analyse the game at the end of turn. (13.59 KB, patch)
2014-09-30 21:37 UTC, Arnaud B.
committed Details | Review
Remove view.redraw(). (1.40 KB, patch)
2014-09-30 22:21 UTC, Arnaud B.
committed Details | Review
Correct some end-of-game bugs. (1.87 KB, patch)
2014-09-30 22:24 UTC, Arnaud B.
committed Details | Review

Description Arnaud B. 2014-09-26 09:36:47 UTC
Created attachment 287134 [details] [review]
Analyse the game at the end of turn.

The ‘game’ file should help the others with providing useful information instead of letting them calculate all. This would allow some optimizations.
Comment 1 Arnaud B. 2014-09-26 11:42:15 UTC
Created attachment 287145 [details] [review]
AI: Don't manage a pass as a move.

Another way to write the AI loop.
Comment 2 Arnaud B. 2014-09-26 12:54:27 UTC
Created attachment 287153 [details] [review]
Don't make unnecessary moves.

We don’t need to apply the move when we’re just trying to know how many tiles it will flip.
Comment 3 Arnaud B. 2014-09-26 13:22:03 UTC
Created attachment 287157 [details] [review]
Create get_possible_moves_sorted().

What’s the Good Way™ to do this for having zero copy of the array?
Comment 4 Arnaud B. 2014-09-26 19:19:48 UTC
Created attachment 287205 [details] [review]
Do the first iteration in a different function.

Is that the Good Way™ to do this for having zero copy of the array? (This is a real patch, not as the previous one.)
Comment 5 Michael Catanzaro 2014-09-26 21:44:26 UTC
Review of attachment 287134 [details] [review]:

Eh, I feel like iagno.vala was simpler originally....

The computer-player changes LOOK safe, but I'm wary of any changes in this code. Just be sure to test carefully.

::: src/game.vala
@@ +32,3 @@
 
+    /* Indicate who's the next player who can move */
+    public bool current_can_move { get; private set; default = true; }

current_player_can_move

@@ +37,2 @@
     /* Indicate that a player should move */
+    public signal void emit_end_of_turn ();

turn_ended ();

(Certainly don't name signals with "emit"...)

@@ +242,3 @@
+        var enemy = Player.flip_color (current_color);
+        var opponent_can_move = false;
+        for (var x = 0; x < size; x++)

On loops, I use braces if the body is more than one line long, even if it is all one statement.

@@ +337,3 @@
         if (count == 2)
             undo (1);
+        else

I only omit braces around conditionals if the body of every conditional in the chain is one line long.

::: src/iagno.vala
@@ +386,3 @@
         }
 
+        play_sound ("flip-piece");

Why can't you call this at the top of game_move_cb/turn_ended_cb? Having it in three places instead of one is hardly nice.

@@ +430,3 @@
     }
 
+    private void game_emit_end_of_turn ()

turn_ended_cb ()

@@ +441,3 @@
+    }
+
+    private void should_move ()

I don't like this name. The function should be named for what it does, not when it's called, and this name doesn't even clearly convey that much.

@@ +459,3 @@
     }
 
+    private void cannot_move ()

This function also needs a better name.

@@ +462,2 @@
     {
+        play_sound ("flip-piece");

Actually, why do you play this sound if it's a pass?

@@ -471,2 @@
         if (game.n_light_tiles > game.n_dark_tiles)
-        {

I use braces if there's multiple lines in the body, even if one is just a comment.
Comment 6 Michael Catanzaro 2014-09-26 21:54:36 UTC
Review of attachment 287145 [details] [review]:

I bet this breaks something. :(
Comment 7 Michael Catanzaro 2014-09-26 21:58:26 UTC
Review of attachment 287153 [details] [review]:

::: src/game.vala
@@ +196,3 @@
     \*/
 
+    public int place_tile (int x, int y, bool apply)

You could use a default argument here, since it's public; then you don't have to change the other calls, since the extra boolean parameter is hard to read.  My rule of thumb is to err on the side of default arguments to public functions, but not to private functions.

@@ +271,3 @@
             return 0;
 
+        if (apply)

Braces here.
Comment 8 Michael Catanzaro 2014-09-26 22:02:46 UTC
Review of attachment 287205 [details] [review]:

This patch is terrifying too. Make sure to test a lot more than usual.  Integrating Dr. Paul's tests would be great....

::: src/computer-player.vala
@@ +178,3 @@
          * strategy. */
+        var g = new Game.copy (game);
+        var depth = difficulty_level * 2;

Don't change the depth in this patch.

@@ +262,3 @@
+    private void get_possible_moves_sorted (Game g, ref List<PossibleMove?> moves)
+    {
+        for (var x = 0; x < g.size; x++)

Braces here
Comment 9 Arnaud B. 2014-09-27 05:56:41 UTC
Created attachment 287226 [details] [review]
Analyse the game at the end of turn.

(In reply to comment #5)
> Eh, I feel like iagno.vala was simpler originally....

I “just” splitted the code of game_move_cb() in two function, as it was called in both cases if the player can move and if he cannot (!), and managed which iagno.vala’s function is called in iagno.vala instead of in game.vala (via signals).

> +        play_sound ("flip-piece");
> 
> Why can't you call this at the top of game_move_cb/turn_ended_cb? Having it in
> three places instead of one is hardly nice.

The sound “flip-piece” isn’t played when you or your opponent flip pieces and finish the game (in game_complete()). That is quite strange, but I didn’t changed it. A patch may be required.

> +    private void should_move ()
> 
> I don't like this name. The function should be named for what it does, not when
> it's called, and this name doesn't even clearly convey that much.

The problem is that this function doesn’t do much, notably on a two-players game. It could be called end_of_turn_and_after_move(), I just used game_wants_move(), is that better? feel free to change.

> +        play_sound ("flip-piece");
> 
> Actually, why do you play this sound if it's a pass?

For the same reason we had this line at the beginning of game_move_cb().
Comment 10 Arnaud B. 2014-09-27 06:02:17 UTC
Created attachment 287227 [details] [review]
AI: Don't manage a pass as a move.

Just replaced a “g.current_can_move”.
Comment 11 Arnaud B. 2014-09-27 06:10:30 UTC
Created attachment 287228 [details] [review]
Don't make unnecessary moves.
Comment 12 Arnaud B. 2014-09-27 06:30:38 UTC
Created attachment 287229 [details] [review]
Do the first iteration in a different function.

(In reply to comment #8)
> Integrating Dr. Paul's tests would be great....

Not sure it would help for this.

> ::: src/computer-player.vala
> @@ +178,3 @@
>           * strategy. */
> +        var g = new Game.copy (game);
> +        var depth = difficulty_level * 2;
> 
> Don't change the depth in this patch.

The depth changes because we do the initial iteration without decreasing it.
Comment 13 Arnaud B. 2014-09-27 06:42:00 UTC
Created attachment 287230 [details] [review]
Don't use six lines for a corner-case.

A clear way to correct that.
Comment 14 Arnaud B. 2014-09-27 06:47:01 UTC
Created attachment 287231 [details] [review]
Don't use six lines for a corner-case.

…with a clearer comment. ^^
Comment 15 Arnaud B. 2014-09-27 07:18:08 UTC
There is a bug that exists in master: when you finish a game (in your turn), go to the new-game screen, go back to the (finished) game, the computer tries to play (and the game crashes).

(Don’t forget to use `jhbuild run iagno --size 4 --level 1 --second`. ^^ )
Comment 16 Michael Catanzaro 2014-09-29 20:32:11 UTC
Review of attachment 287226 [details] [review]:

::: src/game.vala
@@ +238,3 @@
+    }
+
+    private void test_moves ()

Can you think about how to make the meaning of this function more clear? I think it'd be fine with just a better name, but I can't think of what to name it.  As it stands I had to squint a bit too long to see what it does (update current_player_can_move and is_complete).

This is admittedly the sort of nitpicking I would often let slide, but for a patch that just shuffles code around....

::: src/iagno.vala
@@ +439,3 @@
+    }
+
+    private void game_wants_move ()

Yeah, these names didn't work well either. It might be best to just have a longer turn_ended_cb()....
Comment 17 Michael Catanzaro 2014-09-29 20:32:50 UTC
Review of attachment 287228 [details] [review]:

OK.
Comment 18 Michael Catanzaro 2014-09-29 20:34:57 UTC
Review of attachment 287229 [details] [review]:

Oh, duh.  I was even looking for that when I saw it.  And it was 5 PM when I made that review, so I can't have been tired....
Comment 19 Michael Catanzaro 2014-09-29 20:37:10 UTC
Review of attachment 287231 [details] [review]:

Should work.
Comment 20 Arnaud B. 2014-09-30 21:37:29 UTC
Created attachment 287482 [details] [review]
Analyse the game at the end of turn.

(In reply to comment #16)
> This is admittedly the sort of nitpicking I would often let slide, but for a
> patch that just shuffles code around....

Let’s say that… ^^’

> Yeah, these names didn't work well either. It might be best to just have a
> longer turn_ended_cb()....

Not a good idea, the function won’t be easily understandable. Here’s another proposition.
Comment 21 Arnaud B. 2014-09-30 22:21:53 UTC
Created attachment 287484 [details] [review]
Remove view.redraw().
Comment 22 Arnaud B. 2014-09-30 22:24:50 UTC
Created attachment 287485 [details] [review]
Correct some end-of-game bugs.

Here is a correction of the crasher bug, and some others of type “bad headerbar subtitle” (when game finished, depending of who finished; and going back from the new-game screen to a finished game).
Comment 23 Michael Catanzaro 2014-10-01 15:01:25 UTC
Review of attachment 287485 [details] [review]:

::: src/iagno.vala
@@ +278,3 @@
             computer.move_async.begin (SLOW_MOVE_DELAY);
+        else if (game.is_complete)
+            game_complete (false);

Why don't you want to play the sound?
Comment 24 Michael Catanzaro 2014-10-01 15:01:58 UTC
Attachment 287227 [details] pushed as fc29247 - AI: Don't manage a pass as a move.
Attachment 287228 [details] pushed as f07ee51 - Don't make unnecessary moves.
Attachment 287229 [details] pushed as f9cb9bf - Do the first iteration in a different function.
Attachment 287482 [details] pushed as b066c3d - Analyse the game at the end of turn.
Comment 25 Arnaud B. 2014-10-01 16:18:43 UTC
(In reply to comment #23)
> Why don't you want to play the sound?

Why should it play a sound when coming back from new-game screen? Is something happening in the game?
Comment 26 Michael Catanzaro 2014-10-01 17:04:54 UTC
Attachment 287485 [details] pushed as 3f74d09 - Correct some end-of-game bugs.