-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect_four.h
More file actions
154 lines (141 loc) · 4.03 KB
/
connect_four.h
File metadata and controls
154 lines (141 loc) · 4.03 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* connect_four.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: byoung-w <byoung-w@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/09/08 14:49:06 by byoung-w #+# #+# */
/* Updated: 2014/12/25 07:29:01 by byoung-w ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CONNECT_FOUR_H
# define CONNECT_FOUR_H
# include "libft/libft.h"
# include "ft_printf/ft_printf.h"
# include "libft/get_next_line.h"
# include "vector.h"
# include <time.h>
# include <stdlib.h>
# include <stdint.h>
# include <ncurses.h>
# define MIN_WIDTH 7
# define MIN_HEIGHT 6
# define MAX_HEIGHT 60
# define MAX_WIDTH 70
# define MAX_HARD_WIDTH 9
# define MAX_HARD_BITS 64
# define ID_PLAYER 1
# define ID_COMPUTER 2
# define ERROR_INPUT 1;
# define STATE_PLAY 1
# define STATE_SELECT_DIFF 1
# define DIFFICULTY_EASY 1
# define DIFFICULTY_MEDIUM 2
# define DIFFICULTY_HARD 3
# define RENDER_TERMINAL 1
# define RENDER_NCURSES 2
# define NCURSES_INPUT_LIMIT 3
# define I g_connect.i
# define J g_connect.j
# define W g_connect.input_w
# define H g_connect.input_h
# define D_HARD_P1 g_connect.d_hard
# define NC_W (((W * 2) < 30) ? 30 : (W * 2))
# define NC_H H * 2
# define H_X D_HARD_P1.x
# define H_Y D_HARD_P1.y
# define H_DY D_HARD_P1.dy
# define H_DX D_HARD_P1.dx
# define H_NB D_HARD_P1.nb
# define GRID g_connect.grid
# define NCURSES g_connect.r_ncurses
# define P g_easy.placed
typedef struct s_easy
{
int count2;
int count;
int pos_i;
int pos_j;
int pos_h;
int pos_v;
int placed;
} t_easy;
t_easy g_easy;
typedef struct s_ncurses
{
WINDOW *game_window;
WINDOW *border_window;
int offsetx;
int offsety;
int max_y;
int max_x;
int margin_x;
int margin_y;
t_bool graphics_end;
char *score;
char *instruction;
int ch;
char *round_string;
int cursor;
char input_number[NCURSES_INPUT_LIMIT + 1];
} t_ncurses;
typedef struct s_connect
{
t_easy d_easy;
t_ncurses r_ncurses;
int render_mode;
int error;
int winner;
int difficulty;
int input_w;
int input_h;
int first_turn;
t_bool is_play;
t_bool input_enter;
int **grid;
char *buffer;
int draw;
int round;
int state;
int insert_c;
int i;
int j;
} t_connect;
t_connect g_connect;
void setup_difficulty(void);
void setup_render(void);
void game_input(void);
void player_stack(int id);
void process_input(void);
void game_render(void);
void game_loop(void);
void setup_game(void);
void end_game(void);
t_bool check_win(int p);
void computer_turn(void);
int easy_verif(int p);
void easy_random_pick(void);
t_easy easy_compar(t_easy *compar, int p);
void easy_place(int v, int h, int v_under, int h_under);
int easy_counter_win_v(t_easy *verif);
int easy_counter_win_h(t_easy *verif);
int easy_counter_win_g(t_easy *verif);
int easy_counter_win_d(t_easy *verif);
int medium_verif(int p);
void medium_random_pick(void);
t_easy medium_compar(t_easy *compar, int p);
void medium_place(int v, int h, int v_under, int h_under);
int medium_counter_win_v(t_easy *verif);
int medium_counter_win_h(t_easy *verif);
int medium_counter_win_g(t_easy *verif);
int medium_counter_win_d(t_easy *verif);
void render_ncurses(void);
void render_terminal(void);
t_bool ncurses_input(void);
void graphics_start();
void graphics_end();
void render_start();
void render_map();
void render_end();
#endif