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 710123 - Don't allow computer vs computer games
Don't allow computer vs computer games
Status: RESOLVED FIXED
Product: iagno
Classification: Applications
Component: general
git master
Other Linux
: Normal enhancement
: ---
Assigned To: iagno-maint
iagno-maint
Depends on:
Blocks:
 
 
Reported: 2013-10-14 17:20 UTC by Allan Day
Modified: 2014-04-07 14:13 UTC
See Also:
GNOME target: ---
GNOME version: 3.11/3.12


Attachments
Don't allow computer vs computer games (9.62 KB, patch)
2014-02-18 17:10 UTC, Alex Muñoz
needs-work Details | Review
Don't allow computer vs computer games (10.14 KB, patch)
2014-02-20 01:05 UTC, Alex Muñoz
needs-work Details | Review
Don't allow computer vs computer games (10.07 KB, patch)
2014-02-21 20:04 UTC, Alex Muñoz
needs-work Details | Review
Don't allow computer vs computer games (10.20 KB, patch)
2014-02-25 18:29 UTC, Alex Muñoz
committed Details | Review

Description Allan Day 2013-10-14 17:20:23 UTC
It doesn't make any sense, and causes the game to crash.

To do this, you will need to get rid of the player comboboxes in the preferences dialog. You can probably do this by fixing bug 664976.
Comment 1 Michael Catanzaro 2013-10-15 02:48:01 UTC
I agree, but I haven't seen it crash; could you post a stacktrace if you can reproduce that?
Comment 2 Alex Muñoz 2014-02-18 17:10:44 UTC
Created attachment 269580 [details] [review]
Don't allow computer vs computer games
Comment 3 Michael Catanzaro 2014-02-19 01:46:53 UTC
Review of attachment 269580 [details] [review]:

Cool, thanks!

Can you please move Play As above Opposing Player, and ensure Play As is insensitive whenever Opposing Player is set to Human?  Also, it might be good to rename Opposing Player to simply Opponent, to remove all the whitespace currently underneath the word player.  (If you don't want to rename it, then it should read Opposing player with a lowercase "player.")

I'm also noticing some weirdness regarding the computer player's moves: you might be calling computer_player.move () too often.  There should be at least a two-second delay between my move and the computer's next move.

::: data/org.gnome.iagno.gschema.xml
@@ +8,1 @@
       <default>1</default>

Let's default to 2 (for dark) so that the human still plays first by default.

::: src/iagno.vala
@@ +31,3 @@
     private Gtk.Label light_score_label;
 
+    private ComputerPlayer? player = null;

This field should be removed (see below)

@@ +247,1 @@
             undo_action.set_enabled (false);

See the comment above for why this branch now needs to be removed (it prevents you from using Undo).

@@ +367,3 @@
         cancel_pending_computer_moves ();
+        if (game.current_color == settings.get_int("play-as"))
+            player.move ();

But player is always null, so I think this will cause criticals.  You don't need this branch (or the player field) at all: calling move() just starts the AI thinking.

@@ +444,1 @@
     }

Looks like there's an extra blank line here

I'm also worried about:

* What will happen if the player changes the difficulty while the AI is currently pondering its next move: does the game hang forever? (Scratch that, I see you addressed it below.)
* If I play the game on Easy, then change the difficulty to Hard before my final move, will the result be recorded in my high scores for Hard?

So please don't change the difficulty of the AI in the middle of the match -- it's best if this setting isn't applied until the next game.

@@ +461,3 @@
     private void propbox_response_cb (Gtk.Widget widget, int response_id)
     {
+        game_move_cb (game);

This causes the piece flip sound to play.  I take it this is to start the AI thinking if the player changed the difficulty level in the middle of the match? Then computer_move_cb() should suffice. (But I think it's best we remove this entirely, as I wrote above.)
Comment 4 Alex Muñoz 2014-02-20 01:05:46 UTC
Created attachment 269743 [details] [review]
Don't allow computer vs computer games
Comment 5 Alex Muñoz 2014-02-20 01:56:46 UTC
Thanks for your comments.
the level and the color setting are not applied until the next game, the reason is same that you wrote: change the color before the final move.
Comment 6 Michael Catanzaro 2014-02-20 03:54:44 UTC
Review of attachment 269743 [details] [review]:

::: src/iagno.vala
@@ +36,2 @@
+    /* Human player */
+    private int player_color = 1;

I think this is nicer than using settings.get_int() everywhere was, but please use the existing Player enum instead of an int.  Also, the default value is not meaningful and can be omitted.

It's a bit hard to think of a meaningful name... player_color doesn't really make sense as there could be two players.  Maybe player_one?  (Well, that doesn't really seem great either.)

@@ +229,3 @@
+            computer = null;
+
+        player_color = settings.get_int("play-as");

Don't forget the space before the opening parentheses.

@@ +237,3 @@
          * thinking - but only a short delay for the first move)
          */
+        if (Player.DARK != player_color)

This is a Yoda conditional; how about if (player_color != Player.DARK)

@@ +272,2 @@
         /* Undo once if the human player just moved, otherwise undo both moves */
+        if (computer != null)

This breaks undo after you have moved, but before the computer player has moved.  We really do need to compare game.current_color against the identity of the computer, which is the opposite color of player_one/human_player if and only if computer != null.

Try something like:

if (computer != null &&
(human_player == Player.LIGHT && game.current_color == Player.DARK) ||
(human_player == Player.DARK && game.current_color == Player.LIGHT))

@@ +353,3 @@
          * but not so long as to become boring.
          */
+        if (computer != null)

Again, I think this is causing the AI to start on the human's turn.

It occurs to me that the check you need here is exactly the same as the one you need above, so how about splitting it into a new boolean function is_computer_player_to_move()

@@ +497,3 @@
         box.add (grid);
 
+

Extra blank line

@@ +525,3 @@
         grid.attach (label, 0, 1, 1, 1);
+        var combo = new Gtk.ComboBox ();
+        combo.changed.connect (() => computer_level_changed_cb(combo, color_combo));

Missing space before opening parenthesis

@@ +551,3 @@
             combo.set_active_iter (iter);
         grid.attach (combo, 1, 1, 1, 1);
+        

Still got the extra blank line here
Comment 7 Alex Muñoz 2014-02-21 20:04:40 UTC
Created attachment 269948 [details] [review]
Don't allow computer vs computer games
Comment 8 Michael Catanzaro 2014-02-22 00:31:32 UTC
Review of attachment 269948 [details] [review]:

Much better: all the weirdness with the AI is fixed.

I messed up one of my previous review comments where I asked you to move Play As above Opponent in the preferences dialog.  Since changing the state of Opponent affects the sensitivity of Play As, Opponent needs to be on top.  It was right the first time; sorry about that.

::: src/iagno.vala
@@ +36,2 @@
+    /* Human player */
+    private int player_one;

Again, this should be declared as a Player, not an int.

@@ +237,3 @@
          * thinking - but only a short delay for the first move)
          */
+        if (player_one != Player.DARK)

Also, make sure computer != null
Comment 9 Alex Muñoz 2014-02-25 18:29:58 UTC
Created attachment 270301 [details] [review]
Don't allow computer vs computer games
Comment 10 Michael Catanzaro 2014-02-25 18:46:44 UTC
Review of attachment 270301 [details] [review]:

Seems good. Thanks for the work and for iterating on it!

It's too late for this to go into 3.12 since we're already into UI freeze and this is a relatively minor issue, but I'll commit it after branching.
Comment 11 André Klapper 2014-04-07 13:09:56 UTC
(In reply to comment #10)
> It's too late for this to go into 3.12 since we're already into UI freeze and
> this is a relatively minor issue, but I'll commit it after branching.

ping
Comment 12 Michael Catanzaro 2014-04-07 14:13:55 UTC
Oops, thanks for the ping!

Attachment 270301 [details] pushed as 778f5b8 - Don't allow computer vs computer games