summary refs log tree commit diff
path: root/freecell.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--freecell.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/freecell.c b/freecell.c
index eae8413..62cc81a 100644
--- a/freecell.c
+++ b/freecell.c
@@ -70,7 +70,7 @@ static void enqueue(uint dst, uint src) {
 
 static void dequeue(void) {
 	struct Move move = queue.moves[queue.r++ % QueueLen];
-	stackPush(&stacks[move.dst], stackPop(&stacks[move.src]));
+	push(&stacks[move.dst], pop(&stacks[move.src]));
 	if (move.dst <= Foundation4) {
 		kingIndex = Cards_KingRight;
 	} else if (move.dst <= Cell4) {
@@ -83,7 +83,7 @@ static bool undo(void) {
 	if (!len || len > QueueLen) return false;
 	for (uint i = len - 1; i < len; --i) {
 		struct Move move = queue.moves[(queue.u + i) % QueueLen];
-		stackPush(&stacks[move.src], stackPop(&stacks[move.dst]));
+		push(&stacks[move.src], pop(&stacks[move.dst]));
 	}
 	queue.r = queue.w = queue.u;
 	return true;
@@ -91,12 +91,12 @@ static bool undo(void) {
 
 static void deal(void) {
 	for (uint i = 0; i < StacksLen; ++i) {
-		stackClear(&stacks[i]);
+		clear(&stacks[i]);
 	}
 	struct Stack deck = Deck;
-	stackShuffle(&deck);
+	shuffle(&deck);
 	for (uint i = Tableau1; i <= Tableau8; ++i) {
-		stackFlipTo(&stacks[i], &deck, (i < Tableau5 ? 7 : 6));
+		flipTo(&stacks[i], &deck, (i < Tableau5 ? 7 : 6));
 	}
 	kingIndex = Cards_KingRight;
 }
@@ -109,16 +109,16 @@ static bool win(void) {
 }
 
 static bool valid(uint dst, Card card) {
-	Card top = stackTop(&stacks[dst]);
-	if (dst >= Foundation1 && dst <= Foundation4) {
-		if (!top) return cardRank(card) == Cards_A;
-		return cardSuit(card) == cardSuit(top)
-			&& cardRank(card) == cardRank(top) + 1;
+	Card top = peek(&stacks[dst]);
+	if (dst <= Foundation4) {
+		if (!top) return rank(card) == Cards_A;
+		return suit(card) == suit(top)
+			&& rank(card) == rank(top) + 1;
 	}
 	if (!top) return true;
-	if (dst >= Tableau1 && dst <= Tableau8) {
-		return cardColor(card) != cardColor(top)
-			&& cardRank(card) == cardRank(top) - 1;
+	if (dst >= Tableau1) {
+		return color(card) != color(top)
+			&& rank(card) == rank(top) - 1;
 	}
 	return false;
 }
@@ -128,17 +128,17 @@ static void autoEnqueue(void) {
 	for (uint i = Cell1; i <= Tableau8; ++i) {
 		for (uint j = 0; j < stacks[i].len; ++j) {
 			Card card = stacks[i].cards[j];
-			if (cardRank(card) < min[cardColor(card)]) {
-				min[cardColor(card)] = cardRank(card);
+			if (rank(card) < min[color(card)]) {
+				min[color(card)] = rank(card);
 			}
 		}
 	}
 
 	for (uint src = Cell1; src <= Tableau8; ++src) {
-		Card card = stackTop(&stacks[src]);
+		Card card = peek(&stacks[src]);
 		if (!card) continue;
-		if (cardRank(card) > Cards_2) {
-			if (min[!cardColor(card)] < cardRank(card)) continue;
+		if (rank(card) > Cards_2) {
+			if (min[!color(card)] < rank(card)) continue;
 		}
 		for (uint dst = Foundation1; dst <= Foundation4; ++dst) {
 			if (valid(dst, card)) {
@@ -150,7 +150,7 @@ static void autoEnqueue(void) {
 }
 
 static void moveSingle(uint dst, uint src) {
-	if (valid(dst, stackTop(&stacks[src]))) {
+	if (valid(dst, peek(&stacks[src]))) {
 		queue.u = queue.w;
 		enqueue(dst, src);
 	}
@@ -161,8 +161,8 @@ static uint moveDepth(uint src) {
 	if (stack.len < 2) return stack.len;
 	uint n = 1;
 	for (uint i = stack.len - 2; i < stack.len; --i, ++n) {
-		if (cardColor(stack.cards[i]) == cardColor(stack.cards[i + 1])) break;
-		if (cardRank(stack.cards[i]) != cardRank(stack.cards[i + 1]) + 1) break;
+		if (color(stack.cards[i]) == color(stack.cards[i + 1])) break;
+		if (rank(stack.cards[i]) != rank(stack.cards[i + 1]) + 1) break;
 	}
 	return n;
 }
@@ -475,7 +475,7 @@ static void renderStack(uint stack) {
 			revealRect = rect;
 		}
 		bool hilite = (stack == fromStack && i == stacks[stack].len - 1);
-		renderCard(rect, card, hilite || cardRank(card) == hiliteRank);
+		renderCard(rect, card, hilite || rank(card) == hiliteRank);
 		rect.y += StackDeltaY;
 	}
 	if (revealCard) {
@@ -485,9 +485,9 @@ static void renderStack(uint stack) {
 
 static void renderStacks(void) {
 	for (uint i = Foundation1; i <= Cell4; ++i) {
-		Card card = stackTop(&stacks[i]);
+		Card card = peek(&stacks[i]);
 		if (!card) continue;
-		bool hilite = (i == fromStack || cardRank(card) == hiliteRank);
+		bool hilite = (i == fromStack || rank(card) == hiliteRank);
 		renderCard(rects[i], card, hilite);
 	}
 	for (uint i = Tableau1; i <= Tableau8; ++i) {