[gnome-mahjongg] Reshuffle until shuffling opened a move
- From: Mario Wenzel <mariowenzel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mahjongg] Reshuffle until shuffling opened a move
- Date: Fri, 29 Aug 2014 12:09:42 +0000 (UTC)
commit bec42d351f05528f819213cea3b0ca90150fd138
Author: Mario Wenzel <maweki gmail com>
Date: Fri Aug 29 14:09:31 2014 +0200
Reshuffle until shuffling opened a move
https://bugzilla.gnome.org/show_bug.cgi?id=732225
src/game.vala | 27 +++++++++++++++------------
1 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index 85673bb..2e0c61b 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -192,18 +192,21 @@ public class Game : Object
public void shuffle_remaining (bool redraw = true) {
// Fisher Yates Shuffle
var n = tiles.length();
- for (var i = n-1; i > 0; i--) {
- int j = Random.int_range(0,(int)i+1);
- // switch internal positions
- switch_tiles (tiles.nth_data(j), tiles.nth_data(i));
- }
- // resort for drawing order
- tiles.sort(compare_tiles);
- // reset moves and move numbers
- move_number = 1;
- foreach (var tile in tiles)
- tile.move_number = 0;
- find_matches ();
+ do {
+ for (var i = n-1; i > 0; i--) {
+ int j = Random.int_range(0,(int)i+1);
+ // switch internal positions
+ switch_tiles (tiles.nth_data(j), tiles.nth_data(i));
+ }
+ // resort for drawing order
+ tiles.sort(compare_tiles);
+ // reset moves and move numbers
+ move_number = 1;
+ foreach (var tile in tiles)
+ tile.move_number = 0;
+ find_matches ();
+ } while (!can_move && visible_tiles > 1);
+ // only continue shuffling when there is a possible pairing
moved ();
if (redraw)
redraw_all_tiles ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]