forked from clinew/2048
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
132 lines (102 loc) · 2.73 KB
/
board.h
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright 2014 by Wade T. Cline
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef board_H
#define board_H
#include <stdio.h>
#define BOARD_COLUMNS 4
#define BOARD_ROWS 4
// Likelihood of a '4' appearing on the board represented as a percentage
// multiplied by 100.
#define BOARD_4SPAWN_CHANCE 15
/**
* Represents the in-game board.
*/
struct board {
// Holds the value of each tile.
unsigned tiles[BOARD_ROWS][BOARD_COLUMNS];
};
/**
* Returns 0 if the game is not over; >0 if the game is over and the user
* has won, or <0 if the user has lost.
*/
int board_done(struct board* board);
/**
* Returns the number of empty tiles in the board.
*/
unsigned board_get_tiles_empty(struct board* board);
/**
* Initializes the specified board.
*/
void board_init(struct board* board);
/**
* Merge tiles in the board downwards.
*/
int board_merge_down(struct board* board);
/**
* Merge tiles in the board leftwards.
*/
int board_merge_left(struct board* board);
/**
* Merge tiles in the board rightwards.
*/
int board_merge_right(struct board* board);
/**
* Merge tiles in the board upwards.
*/
int board_merge_up(struct board* board);
/**
* Processes user move-down request.
*/
int board_move_down(struct board* board);
/**
* Process user move-left request.
*/
int board_move_left(struct board* board);
/**
* Process user move-right request.
*/
int board_move_right(struct board* board);
/**
* Process user move-up request.
*/
int board_move_up(struct board* board);
/**
* Spawn a new tile on the board.
*
* I didn't know what to call this, so "plopping" a value on the board sounds
* legit enough.
*/
void board_plop(struct board* board);
/**
* Print the board to 'stdout'.
*/
void board_print(struct board* board);
/**
* Shift all the elements in the board down.
*/
int board_shift_down(struct board* board);
/**
* Shift all the elements in the board left.
*/
int board_shift_left(struct board* board);
/**
* Shift all the elements in the board right.
*/
int board_shift_right(struct board* board);
/**
* Shift all the elements in the board up.
*/
int board_shift_up(struct board* board);
#endif // board_H