diff options
-rw-r--r-- | freecell.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/freecell.c b/freecell.c index 62cc81a..3400306 100644 --- a/freecell.c +++ b/freecell.c @@ -167,18 +167,22 @@ static uint moveDepth(uint src) { return n; } -static uint freeCells(uint list[], uint dst) { +static uint freeCells(uint cells[], uint dst) { uint len = 0; for (uint i = Cell1; i <= Tableau8; ++i) { if (i == dst) continue; - if (!stacks[i].len) list[len++] = i; + if (!stacks[i].len) cells[len++] = i; } return len; } static void moveColumn(uint dst, uint src) { + uint cells[StacksLen]; + uint free = freeCells(cells, dst); + uint depth; for (depth = moveDepth(src); depth; --depth) { + if (free < depth - 1) continue; if (valid(dst, stacks[src].cards[stacks[src].len - depth])) break; } if (depth < 2 || dst <= Cell4) { @@ -186,17 +190,13 @@ static void moveColumn(uint dst, uint src) { return; } - uint list[StacksLen]; - uint free = freeCells(list, dst); - if (free < depth - 1) return; - queue.u = queue.w; for (uint i = 0; i < depth - 1; ++i) { - enqueue(list[i], src); + enqueue(cells[i], src); } enqueue(dst, src); for (uint i = depth - 2; i < depth - 1; --i) { - enqueue(dst, list[i]); + enqueue(dst, cells[i]); } } |