Implemented game#valid_move.

This commit is contained in:
Murilo Pereira 2011-05-07 23:09:39 -03:00
parent 854184c2fd
commit e7706dfa4b
7 changed files with 488 additions and 19 deletions

View File

@ -66,8 +66,6 @@ void erase_stack(struct stack *stack) {
box(empty_stack, 0, 0);
wrefresh(empty_stack);
delwin(empty_stack);
return;
}
void draw_empty_stacks() {
@ -198,7 +196,16 @@ void draw_card(struct card *card) {
}
void draw_stack(struct stack *stack) {
if (!empty(stack)) {
erase_stack(stack);
if (empty(stack)) {
WINDOW *empty_stack = newwin(FRAME_HEIGHT,
FRAME_WIDTH,
stack->card->frame->start_y,
stack->card->frame->start_x);
box(empty_stack, 0, 0);
wrefresh(empty_stack);
delwin(empty_stack);
} else {
if (maneuvre_stack(stack)) {
struct stack *reversed_stack = reverse(stack);

View File

@ -8,23 +8,82 @@
#include "util.h"
#include "game.h"
bool stock_stack(struct stack *stack) {
return(stack && stack->card && stack->card->frame &&
(stack->card->frame->start_y == STOCK_STARTING_Y) &&
(stack->card->frame->start_x == STOCK_STARTING_X));
}
bool waste_pile_stack(struct stack *stack) {
return(stack && stack->card && stack->card->frame &&
(stack->card->frame->start_y == WASTE_PILE_STARTING_Y) &&
(stack->card->frame->start_x == WASTE_PILE_STARTING_X));
}
bool foundation_stack(struct stack *stack) {
return(stack && stack->card && stack->card->frame &&
stack->card->frame->start_y == FOUNDATION_STARTING_Y &&
(stack->card->frame->start_x == FOUNDATION_0_STARTING_X ||
stack->card->frame->start_x == FOUNDATION_1_STARTING_X ||
stack->card->frame->start_x == FOUNDATION_2_STARTING_X ||
stack->card->frame->start_x == FOUNDATION_3_STARTING_X));
}
bool maneuvre_stack(struct stack *stack) {
return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y);
return(stack && stack->card && stack->card->frame &&
stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y &&
(stack->card->frame->start_x == MANEUVRE_0_STARTING_X ||
stack->card->frame->start_x == MANEUVRE_1_STARTING_X ||
stack->card->frame->start_x == MANEUVRE_2_STARTING_X ||
stack->card->frame->start_x == MANEUVRE_3_STARTING_X ||
stack->card->frame->start_x == MANEUVRE_4_STARTING_X ||
stack->card->frame->start_x == MANEUVRE_5_STARTING_X ||
stack->card->frame->start_x == MANEUVRE_6_STARTING_X));
}
bool valid_move(struct stack *origin, struct stack *destination) {
if (stock_stack(origin)) {
if (waste_pile_stack(destination)) {
return(true);
} else {
return(false);
}
} 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);
}
}
void move_card(struct stack **origin, struct stack **destination) {
struct stack *stack = NULL;
struct stack *stack;
if (!empty(*origin)) {
(*origin)->card->frame->start_x = (*destination)->card->frame->start_x;
(*origin)->card->frame->start_y = (*destination)->card->frame->start_y;
}
if (!empty(*destination) && maneuvre_stack(*destination)) {
(*origin)->card->frame->start_y++;
}
if ((stack = pop(origin))) {
push(destination, stack->card);
}
return;
}
static void set_stacks_initial_coordinates(struct deck *deck) {

View File

@ -34,6 +34,8 @@ extern const char *program_name;
struct deck *deck;
struct cursor *cursor;
bool valid_move(struct stack *, struct stack *);
bool maneuvre_stack(struct stack *);
void move_card(struct stack **, struct stack **);
void greet_player();
void initialize_game();

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#include "card.h"
#include "game.h"
#include "display.h"
@ -90,19 +91,19 @@ static void handle_card_movement(struct cursor *cursor) {
move_cursor(cursor, RIGHT);
break;
case KEY_SPACEBAR:
if (!cursor_on_invalid_spot(cursor) &&
!cursor_on_stock(cursor) &&
!cursor_on_stack(cursor, origin)) {
destination = cursor_stack(cursor);
if (valid_move(origin, destination)) {
move_card(&origin, &destination);
draw_stack(origin);
draw_stack(destination);
}
return;
case 'q':
case 'Q':
end_curses();
exit(0);
}
}
return;
}
void handle_keyboard_event(int key) {
@ -131,6 +132,4 @@ void handle_keyboard_event(int key) {
}
break;
}
return;
}

View File

@ -1,4 +1,5 @@
#include <assert.h>
#include "test_helper.h"
#include "../lib/card.h"
void test_initialize_card() {

View File

@ -1,4 +1,5 @@
#include <assert.h>
#include "test_helper.h"
#include "../lib/frame.h"
void test_initialize_frame() {

View File

@ -94,8 +94,8 @@ void test_move_card_from_non_empty_stack_to_non_empty_stack() {
allocate_card(&card[1]);
initialize_card(card[0]);
initialize_card(card[1]);
set_card(card[0], ACE, SPADES, EXPOSED, 1, 1);
set_card(card[1], KING, HEARTS, EXPOSED, 1, 1);
set_card(card[0], ACE, SPADES, EXPOSED, 99, 99);
set_card(card[1], KING, HEARTS, EXPOSED, 99, 99);
allocate_stack(&origin);
allocate_stack(&destination);
@ -116,7 +116,407 @@ void test_move_card_from_non_empty_stack_to_non_empty_stack() {
return;
}
void test_valid_move_from_stock_to_stock() {
struct stack *stock_0, *stock_1;
allocate_stack(&stock_0);
allocate_stack(&stock_1);
initialize_stack(stock_0);
initialize_stack(stock_1);
set_card(stock_0->card, ACE, SPADES, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
set_card(stock_1->card, KING, HEARTS, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
assert(!valid_move(stock_0, stock_0));
assert(!valid_move(stock_0, stock_1));
assert(!valid_move(stock_1, stock_0));
assert(!valid_move(stock_1, stock_1));
free_stack(stock_0);
free_stack(stock_1);
}
void test_valid_move_from_stock_to_waste_pile() {
struct stack *stock, *waste_pile;
allocate_stack(&stock);
allocate_stack(&waste_pile);
initialize_stack(stock);
initialize_stack(waste_pile);
set_card(stock->card, ACE, SPADES, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
set_card(waste_pile->card, KING, HEARTS, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
assert(valid_move(stock, waste_pile));
free_stack(stock);
free_stack(waste_pile);
}
void test_valid_move_from_stock_to_foundation_stacks() {
struct stack *stock, *foundation_stacks[4];
allocate_stack(&stock);
initialize_stack(stock);
set_card(stock->card, ACE, SPADES, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
for (int i = 0; i < 4; i++) {
allocate_stack(&foundation_stacks[i]);
initialize_stack(foundation_stacks[i]);
}
set_card(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X);
set_card(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X);
set_card(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X);
set_card(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X);
for (int i = 0; i < 4; i++) {
assert(!valid_move(stock, foundation_stacks[i]));
}
free_stack(stock);
for (int i = 0; i < 4; i++) {
free_stack(foundation_stacks[i]);
}
}
void test_valid_move_from_stock_to_maneuvre_stacks() {
struct stack *stock, *maneuvre_stacks[7];
allocate_stack(&stock);
initialize_stack(stock);
set_card(stock->card, ACE, SPADES, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
for (int i = 0; i < 7; i++) {
allocate_stack(&maneuvre_stacks[i]);
initialize_stack(maneuvre_stacks[i]);
}
set_card(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X);
set_card(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X);
set_card(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X);
set_card(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X);
set_card(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X);
set_card(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X);
set_card(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X);
for (int i = 0; i < 7; i++) {
assert(!valid_move(stock, maneuvre_stacks[i]));
}
free_stack(stock);
for (int i = 0; i < 7; i++) {
free_stack(maneuvre_stacks[i]);
}
}
void test_valid_move_from_waste_pile_to_stock() {
struct stack *stock, *waste_pile;
allocate_stack(&stock);
allocate_stack(&waste_pile);
initialize_stack(stock);
initialize_stack(waste_pile);
set_card(stock->card, ACE, SPADES, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
set_card(waste_pile->card, KING, HEARTS, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
assert(!valid_move(waste_pile, stock));
free_stack(stock);
free_stack(waste_pile);
}
void test_valid_move_from_waste_pile_to_waste_pile() {
struct stack *waste_pile_0, *waste_pile_1;
allocate_stack(&waste_pile_0);
allocate_stack(&waste_pile_1);
initialize_stack(waste_pile_0);
initialize_stack(waste_pile_1);
set_card(waste_pile_0->card, ACE, SPADES, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
set_card(waste_pile_1->card, KING, HEARTS, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
assert(!valid_move(waste_pile_0, waste_pile_0));
assert(!valid_move(waste_pile_0, waste_pile_1));
assert(!valid_move(waste_pile_1, waste_pile_0));
assert(!valid_move(waste_pile_1, waste_pile_1));
free_stack(waste_pile_0);
free_stack(waste_pile_1);
}
void test_valid_move_from_waste_pile_to_foundation_stacks() {
struct stack *waste_pile, *foundation_stacks[4];
allocate_stack(&waste_pile);
initialize_stack(waste_pile);
set_card(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
for (int i = 0; i < 4; i++) {
allocate_stack(&foundation_stacks[i]);
initialize_stack(foundation_stacks[i]);
}
set_card(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X);
set_card(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X);
set_card(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X);
set_card(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X);
for (int i = 0; i < 4; i++) {
assert(valid_move(waste_pile, foundation_stacks[i]));
}
free_stack(waste_pile);
for (int i = 0; i < 4; i++) {
free_stack(foundation_stacks[i]);
}
}
void test_valid_move_from_waste_pile_to_maneuvre_stacks() {
struct stack *waste_pile, *maneuvre_stacks[7];
allocate_stack(&waste_pile);
initialize_stack(waste_pile);
set_card(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
for (int i = 0; i < 7; i++) {
allocate_stack(&maneuvre_stacks[i]);
initialize_stack(maneuvre_stacks[i]);
}
set_card(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X);
set_card(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X);
set_card(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X);
set_card(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X);
set_card(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X);
set_card(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X);
set_card(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X);
for (int i = 0; i < 7; i++) {
assert(valid_move(waste_pile, maneuvre_stacks[i]));
}
free_stack(waste_pile);
for (int i = 0; i < 7; i++) {
free_stack(maneuvre_stacks[i]);
}
}
void test_valid_move_from_foundation_stack_to_stock() {
struct stack *stock, *foundation_stacks[4];
allocate_stack(&stock);
initialize_stack(stock);
set_card(stock->card, ACE, SPADES, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
for (int i = 0; i < 4; i++) {
allocate_stack(&foundation_stacks[i]);
initialize_stack(foundation_stacks[i]);
}
set_card(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X);
set_card(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X);
set_card(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X);
set_card(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X);
for (int i = 0; i < 4; i++) {
assert(!valid_move(foundation_stacks[i], stock));
}
free_stack(stock);
for (int i = 0; i < 4; i++) {
free_stack(foundation_stacks[i]);
}
}
void test_valid_move_from_foundation_stack_to_waste_pile() {
struct stack *waste_pile, *foundation_stacks[4];
allocate_stack(&waste_pile);
initialize_stack(waste_pile);
set_card(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
for (int i = 0; i < 4; i++) {
allocate_stack(&foundation_stacks[i]);
initialize_stack(foundation_stacks[i]);
}
set_card(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X);
set_card(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X);
set_card(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X);
set_card(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X);
for (int i = 0; i < 4; i++) {
assert(!valid_move(foundation_stacks[i], waste_pile));
}
free_stack(waste_pile);
for (int i = 0; i < 4; i++) {
free_stack(foundation_stacks[i]);
}
}
void test_valid_move_from_foundation_stack_to_foundation_stacks() {
struct stack *foundation_stacks[4];
for (int i = 0; i < 4; i++) {
allocate_stack(&foundation_stacks[i]);
initialize_stack(foundation_stacks[i]);
}
set_card(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X);
set_card(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X);
set_card(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X);
set_card(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (i == j) {
assert(!valid_move(foundation_stacks[i], foundation_stacks[j]));
} else {
assert(valid_move(foundation_stacks[i], foundation_stacks[j]));
}
}
}
for (int i = 0; i < 4; i++) {
free_stack(foundation_stacks[i]);
}
}
void test_valid_move_from_foundation_stack_to_maneuvre_stacks() {
struct stack *foundation_stacks[4];
struct stack *maneuvre_stacks[7];
for (int i = 0; i < 4; i++) {
allocate_stack(&foundation_stacks[i]);
initialize_stack(foundation_stacks[i]);
}
set_card(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X);
set_card(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X);
set_card(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X);
set_card(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X);
for (int i = 0; i < 7; i++) {
allocate_stack(&maneuvre_stacks[i]);
initialize_stack(maneuvre_stacks[i]);
}
set_card(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X);
set_card(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X);
set_card(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X);
set_card(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X);
set_card(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X);
set_card(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X);
set_card(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 7; j++) {
assert(valid_move(foundation_stacks[i], maneuvre_stacks[j]));
}
}
for (int i = 0; i < 4; i++) {
free_stack(foundation_stacks[i]);
}
for (int i = 0; i < 7; i++) {
free_stack(maneuvre_stacks[i]);
}
}
void test_valid_move_from_maneuvre_stack_to_stock() {
struct stack *stock, *maneuvre_stacks[7];
allocate_stack(&stock);
initialize_stack(stock);
set_card(stock->card, ACE, SPADES, EXPOSED, STOCK_STARTING_Y, STOCK_STARTING_X);
for (int i = 0; i < 7; i++) {
allocate_stack(&maneuvre_stacks[i]);
initialize_stack(maneuvre_stacks[i]);
}
set_card(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X);
set_card(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X);
set_card(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X);
set_card(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X);
set_card(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X);
set_card(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X);
set_card(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X);
for (int i = 0; i < 7; i++) {
assert(!valid_move(maneuvre_stacks[i], stock));
}
free_stack(stock);
for (int i = 0; i < 7; i++) {
free_stack(maneuvre_stacks[i]);
}
}
void test_valid_move_from_maneuvre_stack_to_waste_pile() {
struct stack *waste_pile, *maneuvre_stacks[7];
allocate_stack(&waste_pile);
initialize_stack(waste_pile);
set_card(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_STARTING_Y, WASTE_PILE_STARTING_X);
for (int i = 0; i < 7; i++) {
allocate_stack(&maneuvre_stacks[i]);
initialize_stack(maneuvre_stacks[i]);
}
set_card(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X);
set_card(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X);
set_card(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X);
set_card(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X);
set_card(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X);
set_card(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X);
set_card(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X);
for (int i = 0; i < 7; i++) {
assert(!valid_move(maneuvre_stacks[i], waste_pile));
}
free_stack(waste_pile);
for (int i = 0; i < 7; i++) {
free_stack(maneuvre_stacks[i]);
}
}
void test_valid_move_from_maneuvre_stack_to_foundation_stacks() {
struct stack *foundation_stacks[4];
struct stack *maneuvre_stacks[7];
for (int i = 0; i < 4; i++) {
allocate_stack(&foundation_stacks[i]);
initialize_stack(foundation_stacks[i]);
}
set_card(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_0_STARTING_X);
set_card(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_1_STARTING_X);
set_card(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_2_STARTING_X);
set_card(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_STARTING_Y, FOUNDATION_3_STARTING_X);
for (int i = 0; i < 7; i++) {
allocate_stack(&maneuvre_stacks[i]);
initialize_stack(maneuvre_stacks[i]);
}
set_card(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X);
set_card(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X);
set_card(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X);
set_card(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X);
set_card(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X);
set_card(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X);
set_card(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X);
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 4; j++) {
assert(valid_move(maneuvre_stacks[i], foundation_stacks[j]));
}
}
for (int i = 0; i < 4; i++) {
free_stack(foundation_stacks[i]);
}
for (int i = 0; i < 7; i++) {
free_stack(maneuvre_stacks[i]);
}
}
void test_valid_move_from_maneuvre_stack_to_maneuvre_stacks() {
struct stack *maneuvre_stacks[7];
for (int i = 0; i < 7; i++) {
allocate_stack(&maneuvre_stacks[i]);
initialize_stack(maneuvre_stacks[i]);
}
set_card(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_0_STARTING_X);
set_card(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_1_STARTING_X);
set_card(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_2_STARTING_X);
set_card(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_3_STARTING_X);
set_card(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_4_STARTING_X);
set_card(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_5_STARTING_X);
set_card(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_STARTING_Y, MANEUVRE_6_STARTING_X);
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if (i == j) {
assert(!valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
} else {
assert(valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
}
}
}
for (int i = 0; i < 7; i++) {
free_stack(maneuvre_stacks[i]);
}
}
void test_game() {
test_valid_move_from_stock_to_stock();
test_valid_move_from_stock_to_waste_pile();
test_valid_move_from_stock_to_foundation_stacks();
test_valid_move_from_stock_to_maneuvre_stacks();
test_valid_move_from_waste_pile_to_stock();
test_valid_move_from_waste_pile_to_waste_pile();
test_valid_move_from_waste_pile_to_foundation_stacks();
test_valid_move_from_waste_pile_to_maneuvre_stacks();
test_valid_move_from_foundation_stack_to_stock();
test_valid_move_from_foundation_stack_to_waste_pile();
test_valid_move_from_foundation_stack_to_foundation_stacks();
test_valid_move_from_foundation_stack_to_maneuvre_stacks();
test_valid_move_from_maneuvre_stack_to_stock();
test_valid_move_from_maneuvre_stack_to_waste_pile();
test_valid_move_from_maneuvre_stack_to_foundation_stacks();
test_valid_move_from_maneuvre_stack_to_maneuvre_stacks();
test_move_card_from_empty_stack_to_empty_stack();
test_move_card_from_empty_stack_to_non_empty_stack();
test_move_card_from_non_empty_stack_to_empty_stack();