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 737007 - [PATCH] Remove is_complete().
[PATCH] Remove is_complete().
Status: RESOLVED FIXED
Product: iagno
Classification: Applications
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: iagno-maint
iagno-maint
Depends on: 737004
Blocks:
 
 
Reported: 2014-09-20 03:20 UTC by Arnaud B.
Modified: 2014-09-20 17:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Remove is_complete(). (2.91 KB, patch)
2014-09-20 03:20 UTC, Arnaud B.
reviewed Details | Review
Rework game.vala. (6.37 KB, patch)
2014-09-20 04:23 UTC, Arnaud B.
none Details | Review
Rework game.vala. (6.38 KB, patch)
2014-09-20 04:29 UTC, Arnaud B.
reviewed Details | Review
Better import/export. (10.16 KB, patch)
2014-09-20 06:22 UTC, Arnaud B.
reviewed Details | Review
Rework is_complete(). (1.17 KB, patch)
2014-09-20 16:56 UTC, Arnaud B.
committed Details | Review

Description Arnaud B. 2014-09-20 03:20:08 UTC
Created attachment 286673 [details] [review]
Remove is_complete().

There’s a function I already talked about[1] that I dislike because of how it works, and that does twice the job needed whereas it is called many-many times during the game (used notably by the AI). Here is an elegant way for removing it.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=735615
Comment 1 Arnaud B. 2014-09-20 04:23:12 UTC
Created attachment 286674 [details] [review]
Rework game.vala.

Some cleanings. Notably renames place_tile() in try_placing_tile(), as this function is called in blind mode.
Comment 2 Arnaud B. 2014-09-20 04:29:41 UTC
Created attachment 286675 [details] [review]
Rework game.vala.

Ooops, that was a devel patch. Here it should work.
Comment 3 Arnaud B. 2014-09-20 06:22:17 UTC
Created attachment 286681 [details] [review]
Better import/export.

When using the game or even running the tests, we never see the importation/exportation of game managed by [Game]Game.from_strings() and [Game]to_string(). But sometimes, when debugging, we need to have a function that prints the game in console in a readable way. And I hate having to recode it each time. So here is a patch that makes to_string() human-readable (and helps reading test-iagno.vala).
Comment 4 Michael Catanzaro 2014-09-20 14:15:57 UTC
Review of attachment 286673 [details] [review]:

Can you rebase this series please? (Sorry!)

I like this approach, but instead of removing is_complete(), just leave it as a wrapper around can_move(null), since game.is_complete() is more understandable than game.can_move().

::: src/game.vala
@@ +161,3 @@
     }
 
+    public bool can_move (Player? color = null)

Then you can consider not adding the default argument here, since I'd rather we always call game.is_complete() instead.
Comment 5 Michael Catanzaro 2014-09-20 14:30:39 UTC
Review of attachment 286675 [details] [review]:

::: src/game.vala
@@ +189,3 @@
     \*/
 
+    public int try_placing_tile (int x, int y)

Don't rename this. What if every function that could fail was named try_doing_something()?

You could make it throw a checked exception if you want. That would be better for the tests, too.

@@ +254,3 @@
             xt += x_step;
             yt += y_step;
+        } while (is_valid_location (xt, yt) && tiles[xt, yt] == enemy);

This is wrong!
Comment 6 Michael Catanzaro 2014-09-20 14:37:41 UTC
Review of attachment 286681 [details] [review]:

OK, but please split this into two patches and post them both in a new bug.
Comment 7 Arnaud B. 2014-09-20 16:56:59 UTC
Created attachment 286694 [details] [review]
Rework is_complete().

(In reply to comment #4)
> I like this approach, but instead of removing is_complete(), just leave it as a
> wrapper around can_move(null), since game.is_complete() is more understandable
> than game.can_move().

That won’t help my little mind, but at least the code won’t do unnecessary works. Here’s the patch.
Comment 8 Michael Catanzaro 2014-09-20 17:00:03 UTC
Closing, but note the two unpushed patches!

Attachment 286694 [details] pushed as 8c9c480 - Rework is_complete().
Comment 9 Michael Catanzaro 2014-09-20 17:28:20 UTC
Review of attachment 286675 [details] [review]:

::: src/game.vala
@@ +254,3 @@
             xt += x_step;
             yt += y_step;
+        } while (is_valid_location (xt, yt) && tiles[xt, yt] == enemy);

Just kidding, the comment "Count number of enemy pieces we are beside" is wrong.