From 74bdd55bd57831574edefcf8dbff9a1987e3fd56 Mon Sep 17 00:00:00 2001 From: Murilo Pereira Date: Wed, 1 Jun 2011 02:18:53 -0300 Subject: [PATCH] Added actual klondlike solitaire rules for moving cards. --- src/game.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/game.c b/src/game.c index 80a2d3d..6f123be 100644 --- a/src/game.c +++ b/src/game.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -74,33 +73,31 @@ bool maneuvre_stack(struct stack *stack) { } bool valid_move(struct stack *origin, struct stack *destination) { - if (stock_stack(origin)) { - if (waste_pile_stack(destination)) { + if (origin->card->face == EXPOSED) { + if (stock_stack(origin) && waste_pile_stack(destination)) { return(true); - } else { - return(false); + } else if (foundation_stack(destination)) { + if (empty(destination)) { + if (origin->card->value == ACE) { + return(true); + } else if (origin->card->suit == destination->card->suit && + origin->card->value + 1 == destination->card->value) { + return(true); + } + } + } else if (maneuvre_stack(destination)) { + if (empty(destination)) { + if (origin->card->value == KING) { + return(true); + } + } else if ((origin->card->suit + destination->card->suit) % 2 == 1 && + origin->card->value + 1 == destination->card->value) { + return(true); + } } - } else if (waste_pile_stack(origin)) { - if (foundation_stack(destination) || maneuvre_stack(destination)) { - return(true); - } else { - return(false); - } - } else if (foundation_stack(origin)) { - if ((foundation_stack(destination) && origin != destination) || maneuvre_stack(destination)) { - return(true); - } else { - return(false); - } - } else if (maneuvre_stack(origin)) { - if ((maneuvre_stack(destination) && origin != destination) || foundation_stack(destination)) { - return(true); - } else { - return(false); - } - } else { - return(false); } + + return(false); } void move_card(struct stack **origin, struct stack **destination) {