-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.pde
153 lines (146 loc) · 3.3 KB
/
functions.pde
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
int[] emptyIndices() {
int board[] = {
0, 0, 0,
0, 0, 0,
0, 0, 0};
int i = 0;
for (int x = 0; x < map.length; x++) {
for (int y = 0; y < map[0].length; y++) {
board[i] = map[x][y];
i++;
}
}
int c = 0;
for (int j = 0; j < 9; j++) {
if (board[j] == 0) {
c++;
}
}
int l = 0;
int[] ind = new int[c];
for (int k = 0; k < 9; k++) {
if (board[k] == 0) {
ind[l] = k;
l++;
}
}
return ind;
}
void mouseReleased() {
if (map[select_map[0]][select_map[1]] == 0) {
if (is1P) {
map[select_map[0]][select_map[1]] = 1;
} else {
map[select_map[0]][select_map[1]] = 2;
}
is1P = !is1P;
}
if (game_over) {
game_end = millis() - 1750;
}
}
boolean winning(int player) {
int board[] = {
0, 0, 0,
0, 0, 0,
0, 0, 0};
int i = 0;
for (int x = 0; x < map.length; x++) {
for (int y = 0; y < map[0].length; y++) {
board[i] = map[x][y];
i++;
}
}
if (
(board[0] == player && board[1] == player && board[2] == player) ||
(board[3] == player && board[4] == player && board[5] == player) ||
(board[6] == player && board[7] == player && board[8] == player) ||
(board[0] == player && board[3] == player && board[6] == player) ||
(board[1] == player && board[4] == player && board[7] == player) ||
(board[2] == player && board[5] == player && board[8] == player) ||
(board[0] == player && board[4] == player && board[8] == player) ||
(board[2] == player && board[4] == player && board[6] == player)
) {
return true;
} else {
return false;
}
}
int good() {
return 1;
}
void draw_map(int x, int y, int map_size) {
push();
translate(x, y);
int step = map_size/3;
strokeWeight(1);
stroke(white);
noFill();
rect(0, 0, map_size, map_size);
strokeWeight(10);
//vertical
line(step, 0, step, step*3);
line(step*2, 0, step*2, step*3);
//horisontal
line(0, step, step*3, step);
line(0, step*2, step*3, step*2);
pop();
}
void draw_x(int mx, int my, int x, int y, int map_size, boolean selecting) {
push();
int step = map_size/3;
translate(mx + map_size/3, my + map_size/3);
translate(x - step, y - step);
strokeWeight(12.5);
if (selecting) {
stroke(s_red, 200);
} else {
stroke(red);
}
line(25, 25, step-25, step-25);
line(25, step-25, step-25, 25);
pop();
}
void draw_o(int mx, int my, int x, int y, int map_size, boolean selecting) {
push();
int step = map_size/3;
translate(mx + map_size/3, my + map_size/3);
translate(x - map_size/6, y - map_size/6);
noFill();
strokeWeight(12.5);
if (selecting) {
stroke(s_blue, 200);
} else {
stroke(blue);
}
ellipse(0, 0, step - 25, step - 25);
pop();
}
int testWiner() {
int res = 0;
for (int i = 0; i < 3; i++) {
if (map[0][i] == map[1][i] && map[1][i] == map[2][i]) {
res = map[0][i];
} else if (map[i][0] == map[i][1] && map[i][1] == map[i][2]) {
res = map[i][0];
}
}
if (map[0][0] == map[1][1] && map[1][1] == map[2][2]) {
res = map[1][1];
}
if (map[2][0] == map[1][1] && map[1][1] == map[0][2]) {
res = map[1][1];
}
int empty = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (map[i][j] == 0) {
empty++;
}
}
}
if (empty == 0) {
res = 3;
}
return res;
}