2011-02-06 05:44:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-04-05 07:33:10 +00:00
|
|
|
#include <malloc.h>
|
2011-02-06 05:44:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2010-04-05 07:33:10 +00:00
|
|
|
#include "deck.h"
|
2011-05-08 23:20:22 +00:00
|
|
|
#include "common.h"
|
2010-04-05 07:33:10 +00:00
|
|
|
|
|
|
|
void allocate_deck(struct deck **deck) {
|
2011-02-06 05:44:45 +00:00
|
|
|
if (!(*deck = malloc(sizeof(**deck)))) {
|
2011-05-08 23:20:22 +00:00
|
|
|
fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
|
2011-02-06 05:44:45 +00:00
|
|
|
exit(errno);
|
|
|
|
}
|
2010-04-05 07:33:10 +00:00
|
|
|
|
|
|
|
allocate_stack(&((*deck)->stock));
|
2010-04-09 03:12:06 +00:00
|
|
|
allocate_stack(&((*deck)->waste_pile));
|
2010-04-05 07:33:10 +00:00
|
|
|
|
|
|
|
allocate_stack(&((*deck)->foundation_0));
|
|
|
|
allocate_stack(&((*deck)->foundation_1));
|
|
|
|
allocate_stack(&((*deck)->foundation_2));
|
|
|
|
allocate_stack(&((*deck)->foundation_3));
|
|
|
|
|
|
|
|
allocate_stack(&((*deck)->maneuvre_0));
|
|
|
|
allocate_stack(&((*deck)->maneuvre_1));
|
|
|
|
allocate_stack(&((*deck)->maneuvre_2));
|
|
|
|
allocate_stack(&((*deck)->maneuvre_3));
|
|
|
|
allocate_stack(&((*deck)->maneuvre_4));
|
|
|
|
allocate_stack(&((*deck)->maneuvre_5));
|
|
|
|
allocate_stack(&((*deck)->maneuvre_6));
|
|
|
|
}
|
|
|
|
|
|
|
|
void initialize_deck(struct deck *deck) {
|
|
|
|
initialize_stack(deck->stock);
|
2010-04-09 03:12:06 +00:00
|
|
|
initialize_stack(deck->waste_pile);
|
2010-04-05 07:33:10 +00:00
|
|
|
|
|
|
|
initialize_stack(deck->foundation_0);
|
|
|
|
initialize_stack(deck->foundation_1);
|
|
|
|
initialize_stack(deck->foundation_2);
|
|
|
|
initialize_stack(deck->foundation_3);
|
|
|
|
|
|
|
|
initialize_stack(deck->maneuvre_0);
|
|
|
|
initialize_stack(deck->maneuvre_1);
|
|
|
|
initialize_stack(deck->maneuvre_2);
|
|
|
|
initialize_stack(deck->maneuvre_3);
|
|
|
|
initialize_stack(deck->maneuvre_4);
|
|
|
|
initialize_stack(deck->maneuvre_5);
|
|
|
|
initialize_stack(deck->maneuvre_6);
|
|
|
|
}
|
2010-04-07 00:59:21 +00:00
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
void free_deck(struct deck *deck) {
|
2011-02-12 03:26:03 +00:00
|
|
|
if (deck) {
|
2011-02-14 02:10:47 +00:00
|
|
|
free_stack(deck->waste_pile);
|
2010-04-07 00:59:21 +00:00
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
free_stack(deck->foundation_0);
|
|
|
|
free_stack(deck->foundation_1);
|
|
|
|
free_stack(deck->foundation_2);
|
|
|
|
free_stack(deck->foundation_3);
|
2010-04-07 00:59:21 +00:00
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
free_stack(deck->maneuvre_0);
|
|
|
|
free_stack(deck->maneuvre_1);
|
|
|
|
free_stack(deck->maneuvre_2);
|
|
|
|
free_stack(deck->maneuvre_3);
|
|
|
|
free_stack(deck->maneuvre_4);
|
|
|
|
free_stack(deck->maneuvre_5);
|
|
|
|
free_stack(deck->maneuvre_6);
|
2011-02-12 03:26:03 +00:00
|
|
|
}
|
2010-04-07 00:59:21 +00:00
|
|
|
free(deck);
|
|
|
|
}
|