2011-02-06 05:44:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2011-06-03 05:48:26 +00:00
|
|
|
|
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
|
|
|
|
2011-06-06 05:04:03 +00:00
|
|
|
void deck_malloc(struct deck **deck) {
|
2011-02-06 05:44:45 +00:00
|
|
|
if (!(*deck = malloc(sizeof(**deck)))) {
|
2011-06-19 22:36:29 +00:00
|
|
|
tty_solitaire_generic_error(errno, __FILE__, __LINE__);
|
2011-02-06 05:44:45 +00:00
|
|
|
}
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_malloc(&((*deck)->stock));
|
|
|
|
stack_malloc(&((*deck)->waste_pile));
|
2011-06-03 05:48:26 +00:00
|
|
|
for (int i = 0; i < FOUNDATION_STACKS_NUMBER; i++) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_malloc(&((*deck)->foundation[i]));
|
2011-05-29 20:12:52 +00:00
|
|
|
}
|
2011-06-03 05:48:26 +00:00
|
|
|
for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_malloc(&((*deck)->maneuvre[i]));
|
2011-05-29 20:12:52 +00:00
|
|
|
}
|
2010-04-05 07:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 05:04:03 +00:00
|
|
|
void deck_init(struct deck *deck) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_init(deck->stock);
|
|
|
|
stack_init(deck->waste_pile);
|
2011-06-03 05:48:26 +00:00
|
|
|
for (int i = 0; i < FOUNDATION_STACKS_NUMBER; i++) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_init(deck->foundation[i]);
|
2011-05-29 20:12:52 +00:00
|
|
|
}
|
2011-06-03 05:48:26 +00:00
|
|
|
for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_init(deck->maneuvre[i]);
|
2011-05-29 20:12:52 +00:00
|
|
|
}
|
2010-04-05 07:33:10 +00:00
|
|
|
}
|
2010-04-07 00:59:21 +00:00
|
|
|
|
2011-06-06 05:04:03 +00:00
|
|
|
void deck_free(struct deck *deck) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_free(deck->stock);
|
|
|
|
stack_free(deck->waste_pile);
|
2011-06-03 05:48:26 +00:00
|
|
|
for (int i = 0; i < FOUNDATION_STACKS_NUMBER; i++) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_free(deck->foundation[i]);
|
2011-06-03 05:48:26 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) {
|
2011-06-06 04:57:52 +00:00
|
|
|
stack_free(deck->maneuvre[i]);
|
2011-02-12 03:26:03 +00:00
|
|
|
}
|
2010-04-07 00:59:21 +00:00
|
|
|
free(deck);
|
|
|
|
}
|