summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--freecell.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/freecell.c b/freecell.c
index 0e74793..3f1ec8d 100644
--- a/freecell.c
+++ b/freecell.c
@@ -96,11 +96,14 @@ static uint lcgRand(void) {
 }
 
 // <https://rosettacode.org/wiki/Deal_cards_for_FreeCell>
-static void deal(void) {
-	kingIndex = Cards_KingRight;
+static void deal(uint game) {
+	lcgState = game;
+
+	queue.r = queue.w = queue.u = 0;
 	for (uint i = 0; i < StacksLen; ++i) {
 		clear(&stacks[i]);
 	}
+	kingIndex = Cards_KingRight;
 
 	struct Stack deck = {0};
 	for (Card i = Cards_A; i <= Cards_K; ++i) {
@@ -338,13 +341,21 @@ static enum Choice chooseMove(void) {
 	return choice;
 }
 
+static void newGame(void) {
+	uint game = 1 + randUniform(32000);
+	deal(game);
+	char buf[sizeof("FreeCell Game #32000")];
+	snprintf(buf, sizeof(buf), "FreeCell Game #%u", game);
+	SDL_SetWindowTitle(window, buf);
+}
+
 static Card hiliteRank;
 static SDL_Point revealPoint;
 static uint fromStack = StacksLen;
 
 static bool keyDown(SDL_KeyboardEvent key) {
 	switch (key.keysym.sym) {
-		case SDLK_F2: deal(); return true;
+		case SDLK_F2: newGame(); return true;
 		case SDLK_BACKSPACE: return undo();
 	}
 	if (key.repeat) return false;
@@ -388,7 +399,7 @@ static bool mouseButtonDown(SDL_MouseButtonEvent button) {
 
 static bool mouseButtonUp(SDL_MouseButtonEvent button) {
 	if (win() && playAgain()) {
-		deal();
+		newGame();
 		return true;
 	}
 
@@ -581,7 +592,7 @@ int main(void) {
 	}
 
 	srand(time(NULL));
-	deal();
+	newGame();
 	
 	initRects();
 	for (;;) {