-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfreecell.h
More file actions
118 lines (100 loc) · 2.99 KB
/
Copy pathfreecell.h
File metadata and controls
118 lines (100 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* freecell.h
*
* Created on: Sep 25, 2014
* Author: ryan
*/
#ifndef FREECELL_H_
#define FREECELL_H_
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#define DECKSIZE 52
#define SUITSIZE 13
#define NUMCOLS 8
#define COLSIZE 20 /* can't have more than 19 cards in a column */
#define CELLS 4 /* both freecells and stacks */
#define BUFSIZE 80
#define ANSI_COLOR_BG_WHITE "\x1b[47m"
#define ANSI_COLOR_BLACK "\x1b[30m"
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
//#define MAX_DEPTH 5
//Hash table size is 2^(size)
#define GLOBAL_HASH_SIZE 15
#define PATH_HASH_SIZE 15
enum suits {
DIAMONDS, HEARTS, SPADES, CLUBS
};
enum colors {
RED, BLACK
};
typedef struct cardrec /* one of these per card */
{
int num; /* values 1-13, for A through K */
int suit; /* one of enum suits */
int color; /* one of enum colors */
int played; /* flag: test that all cards are present */
} Card;
typedef struct State State;
struct State /* the state of the game at each possible move */
{
char column[NUMCOLS][COLSIZE]; /* 8 columns of up to 20 cards each */
char freecell[CELLS]; /* 4 freecells */
char stack[CELLS]; /* 4 stacks: stores top card only */
char colheight[NUMCOLS]; /* this and previous 2 used for hashing */
char** path;
int p_size;
};
typedef struct States {
State** states;
int size;
} States;
typedef struct _list_t_ {
State *state;
struct _list_t_ *next;
} list_t;
typedef struct _hash_table_t_ {
int size;
list_t **table;
} hash_table_t;
//Functions to work with state
void dumpstate(State *x);
int endstate(State *s);
int checkStack(const State *state, int card);
int checkCardToColumn(const State *state, int card, int column);
int checkFreeCell(const State *state, int card);
int possibleMoves(const State * state);
int sameState(State *s1, State *s2);
State* subtreeSearch(State* state, hash_table_t* hashTable, int depth);
//Search needs input to build initial state
State* search();
States* hashCheck(States* states, hash_table_t *hashTable);
//GenerateNextStates should produce all of the states that can be reached
//from s in one move.
States* generateNextStates(State* s);
bool hashCheckSingle(State* s, hash_table_t *hashTable);
int scoreState(State* s, int (*scoringFunc)(State*));
//
void initdeck(void);
int getinputline(char *s, int n);
int mapnum(char c);
int mapsuit(char c);
int getindex(int num, int suit);
void readinitconfig(void);
void dumpcard(char index);
void dumpcardPlain(char * src, char index, char *message);
//
hash_table_t *create_hash_table(int size);
unsigned int hash(hash_table_t *hashtable, State *s);
State *lookup_state(hash_table_t *hashtable, State *s);
int add_state(hash_table_t *hashtable, State *s);
void free_table(hash_table_t *hashtable);
#endif /* FREECELL_H_ */