[hitori] Bug 575896 — Improve board generation algorithm
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hitori] Bug 575896 — Improve board generation algorithm
- Date: Thu, 28 Oct 2010 09:32:45 +0000 (UTC)
commit 9f3ec3ad305b266908488fc597ca4a40f9999cf0
Author: Philip Withnall <philip tecnocode co uk>
Date: Thu Oct 28 10:31:24 2010 +0100
Bug 575896 â?? Improve board generation algorithm
The algorithm wasn't allowing any painted cells at the edge of the board.
This fixes that problem, and improves the code documentation a little.
Closes: bgo#575896
src/generator.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/src/generator.c b/src/generator.c
index c7f12e4..c168dad 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -65,14 +65,15 @@ hitori_generate_board (Hitori *hitori, guint new_board_size, gint seed)
* cells, and only specifying it for 8x8 grids. This will change in the
* future. */
for (i = 0; i < total; i++) {
+ /* Generate pairs of coordinates until we find one which lies between unpainted cells (or at the edge of the board) */
do {
iter.x = rand () % hitori->board_size;
iter.y = rand () % hitori->board_size;
- if (iter.y >= 1 && (hitori->board[iter.x][iter.y-1].status & CELL_PAINTED) == FALSE &&
- iter.y + 1 < hitori->board_size && (hitori->board[iter.x][iter.y+1].status & CELL_PAINTED) == FALSE &&
- iter.x >= 1 && (hitori->board[iter.x-1][iter.y].status & CELL_PAINTED) == FALSE &&
- iter.x + 1 < hitori->board_size && (hitori->board[iter.x+1][iter.y].status & CELL_PAINTED) == FALSE)
+ if ((iter.y < 1 || (hitori->board[iter.x][iter.y-1].status & CELL_PAINTED) == FALSE) &&
+ (iter.y + 1 >= hitori->board_size || (hitori->board[iter.x][iter.y+1].status & CELL_PAINTED) == FALSE) &&
+ (iter.x < 1 || (hitori->board[iter.x-1][iter.y].status & CELL_PAINTED) == FALSE) &&
+ (iter.x + 1 >= hitori->board_size || (hitori->board[iter.x+1][iter.y].status & CELL_PAINTED) == FALSE))
break;
} while (TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]