Merge branch 'master' into respect-flags
This commit is contained in:
commit
c45969623a
8
Makefile
8
Makefile
@ -1,6 +1,8 @@
|
|||||||
|
VERSION = 1.0.0
|
||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
CFLAGS ?= -g
|
CFLAGS ?= -g
|
||||||
CFLAGS += -W -Wall -pedantic -ansi -std=c99 -g
|
CFLAGS += -W -Wall -pedantic -ansi -std=c99 -DTS_VERSION=\"$(VERSION)\"
|
||||||
|
|
||||||
# OS X installs ncurses with wide character support, but not as "libncurses"
|
# OS X installs ncurses with wide character support, but not as "libncurses"
|
||||||
ifeq ($(shell uname -s),Darwin)
|
ifeq ($(shell uname -s),Darwin)
|
||||||
@ -9,7 +11,7 @@ else
|
|||||||
LDFLAGS += -lncursesw
|
LDFLAGS += -lncursesw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
EXECUTABLE = ttysolitaire
|
EXECUTABLE = ttysolitaire
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
@ -40,6 +42,8 @@ TESTS_OBJECTS = $(TESTS_DIR)/frame_test.o \
|
|||||||
|
|
||||||
.PHONY: test clean install uninstall
|
.PHONY: test clean install uninstall
|
||||||
|
|
||||||
|
all: ${EXECUTABLE}
|
||||||
|
|
||||||
ttysolitaire: $(SRC_OBJECTS)
|
ttysolitaire: $(SRC_OBJECTS)
|
||||||
$(CC) $(CFLAGS) $(SRC) -o $(EXECUTABLE) $(SRC_OBJECTS) $(LDFLAGS)
|
$(CC) $(CFLAGS) $(SRC) -o $(EXECUTABLE) $(SRC_OBJECTS) $(LDFLAGS)
|
||||||
|
|
||||||
|
19
src/game.c
19
src/game.c
@ -129,7 +129,6 @@ void move_block(struct stack **origin, struct stack **destination, int block_siz
|
|||||||
stack_free(tmp);
|
stack_free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void fill_deck(struct deck *deck) {
|
static void fill_deck(struct deck *deck) {
|
||||||
struct card *card[NUMBER_OF_CARDS];
|
struct card *card[NUMBER_OF_CARDS];
|
||||||
|
|
||||||
@ -166,10 +165,10 @@ static void shuffle_deck(struct deck *deck) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void deal_cards(struct deck *deck) {
|
static void deal_cards(struct deck *deck) {
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) {
|
||||||
move_card(&(deck->stock), &(deck->maneuvre[i]));
|
move_card(&(deck->stock), &(deck->maneuvre[i]));
|
||||||
card_expose(deck->maneuvre[i]->card);
|
card_expose(deck->maneuvre[i]->card);
|
||||||
for (int j = i + 1; j < 7; j++) {
|
for (int j = i + 1; j < MANEUVRE_STACKS_NUMBER; j++) {
|
||||||
move_card(&(deck->stock), &(deck->maneuvre[j]));
|
move_card(&(deck->stock), &(deck->maneuvre[j]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,8 +206,14 @@ void game_end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool game_won() {
|
bool game_won() {
|
||||||
return(stack_length(deck->foundation[0]) == 13 &&
|
// if any card is covered, game is not won
|
||||||
stack_length(deck->foundation[1]) == 13 &&
|
for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++)
|
||||||
stack_length(deck->foundation[2]) == 13 &&
|
for (struct stack *j = deck->maneuvre[i]; j!= NULL; j = j->next)
|
||||||
stack_length(deck->foundation[3]) == 13);
|
if (j->card->face == COVERED)
|
||||||
|
return false;
|
||||||
|
// else look in stock and waste pile
|
||||||
|
if (stack_empty(deck->stock) &&
|
||||||
|
stack_empty(deck->waste_pile))
|
||||||
|
return true;
|
||||||
|
else return false;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,18 @@ static void handle_card_movement(struct cursor *cursor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'M':
|
||||||
|
if (origin == cursor_stack(cursor) && maneuvre_stack(*origin)) {
|
||||||
|
for (struct stack *i = *origin; i && i->next; i = i->next) {
|
||||||
|
if (i->next->card->face == EXPOSED &&
|
||||||
|
(i->card->frame->begin_y - i->next->card->frame->begin_y) > 1) {
|
||||||
|
erase_stack(*origin);
|
||||||
|
card_mark(i->next->card);
|
||||||
|
draw_stack(*origin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (origin == cursor_stack(cursor) && maneuvre_stack(*origin)) {
|
if (origin == cursor_stack(cursor) && maneuvre_stack(*origin)) {
|
||||||
for (struct stack *i = (*origin)->next; i; i = i->next) {
|
for (struct stack *i = (*origin)->next; i; i = i->next) {
|
||||||
@ -116,6 +128,15 @@ static void handle_card_movement(struct cursor *cursor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'N':
|
||||||
|
if (origin == cursor_stack(cursor) && maneuvre_stack(*origin)) {
|
||||||
|
erase_stack(*origin);
|
||||||
|
unmark_cards(*origin);
|
||||||
|
card_mark((*origin)->card);
|
||||||
|
draw_stack(*origin);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case KEY_SPACEBAR:;
|
case KEY_SPACEBAR:;
|
||||||
/* http://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg259382.html */
|
/* http://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg259382.html */
|
||||||
struct stack **destination = cursor_stack(cursor);
|
struct stack **destination = cursor_stack(cursor);
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#ifndef TS_VERSION
|
||||||
|
#define TS_VERSION "n/a"
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *program_name;
|
const char *program_name;
|
||||||
struct game game;
|
struct game game;
|
||||||
|
|
||||||
@ -123,14 +127,5 @@ void usage(const char *program_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void version() {
|
void version() {
|
||||||
FILE *version_file;
|
printf("%s\n", TS_VERSION);
|
||||||
char version_string[6];
|
|
||||||
|
|
||||||
if (!(version_file = fopen("VERSION", "rb"))) {
|
|
||||||
tty_solitaire_generic_error(errno, __FILE__, __LINE__);
|
|
||||||
}
|
|
||||||
fread(version_string, 1, 5, version_file);
|
|
||||||
version_string[5] = '\0';
|
|
||||||
printf("%s\n", version_string);
|
|
||||||
fclose(version_file);
|
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,7 @@ void test_valid_move_from_waste_pile_to_foundation_stacks() {
|
|||||||
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||||
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
// TODO: fix error here
|
||||||
assert(valid_move(waste_pile, foundation_stacks[i]));
|
assert(valid_move(waste_pile, foundation_stacks[i]));
|
||||||
}
|
}
|
||||||
stack_free(waste_pile);
|
stack_free(waste_pile);
|
||||||
@ -155,6 +156,7 @@ void test_valid_move_from_waste_pile_to_maneuvre_stacks() {
|
|||||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
|
// TODO: fix error here
|
||||||
assert(valid_move(waste_pile, maneuvre_stacks[i]));
|
assert(valid_move(waste_pile, maneuvre_stacks[i]));
|
||||||
}
|
}
|
||||||
stack_free(waste_pile);
|
stack_free(waste_pile);
|
||||||
@ -225,6 +227,7 @@ void test_valid_move_from_foundation_stack_to_foundation_stacks() {
|
|||||||
if (i == j) {
|
if (i == j) {
|
||||||
assert(!valid_move(foundation_stacks[i], foundation_stacks[j]));
|
assert(!valid_move(foundation_stacks[i], foundation_stacks[j]));
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: fix error here
|
||||||
assert(valid_move(foundation_stacks[i], foundation_stacks[j]));
|
assert(valid_move(foundation_stacks[i], foundation_stacks[j]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,6 +262,7 @@ void test_valid_move_from_foundation_stack_to_maneuvre_stacks() {
|
|||||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int j = 0; j < 7; j++) {
|
for (int j = 0; j < 7; j++) {
|
||||||
|
// TODO: fix error here
|
||||||
assert(valid_move(foundation_stacks[i], maneuvre_stacks[j]));
|
assert(valid_move(foundation_stacks[i], maneuvre_stacks[j]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,6 +351,7 @@ void test_valid_move_from_maneuvre_stack_to_foundation_stacks() {
|
|||||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
|
// TODO: fix error here
|
||||||
assert(valid_move(maneuvre_stacks[i], foundation_stacks[j]));
|
assert(valid_move(maneuvre_stacks[i], foundation_stacks[j]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -377,6 +382,7 @@ void test_valid_move_from_maneuvre_stack_to_maneuvre_stacks() {
|
|||||||
if (i == j) {
|
if (i == j) {
|
||||||
assert(!valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
assert(!valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: fix error here
|
||||||
assert(valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
assert(valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ void test_stack_reverse_on_stack_empty_stack() {
|
|||||||
old_stack = stack;
|
old_stack = stack;
|
||||||
stack_reversed_stack = stack_reverse(stack);
|
stack_reversed_stack = stack_reverse(stack);
|
||||||
|
|
||||||
assert(stack_reversed_stack == old_stack);
|
assert(stacks_equal(stack_reversed_stack, old_stack));
|
||||||
|
|
||||||
stack_free(stack);
|
stack_free(stack);
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ void test_stack_reverse_on_stack_with_one_element() {
|
|||||||
old_stack = stack;
|
old_stack = stack;
|
||||||
stack_reversed_stack = stack_reverse(stack);
|
stack_reversed_stack = stack_reverse(stack);
|
||||||
|
|
||||||
assert(stack_reversed_stack == old_stack);
|
assert(stacks_equal(stack_reversed_stack, old_stack));
|
||||||
|
|
||||||
stack_free(stack);
|
stack_free(stack);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user