-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.cpp
92 lines (81 loc) · 2.1 KB
/
logic.cpp
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
//most of the game logic
#include <iostream>
//things in other files
void printboard(int board[3][3]);
int charconvert(char input){//converts char to appropriate int
if (input == '1'){return 0;}
if (input == '2'){return 1;}
if (input == '3'){return 2;}
if (input == 'a'){return 0;}
if (input == 'b'){return 1;}
if (input == 'c'){return 2;}
return 6;
}
void extrude(int board[3][3], int turn){
int x;
int y;
char input[2];
std::cout << "Extrude: ";
std::cin >> input;
x = charconvert(input[0]);
y = charconvert(input[1]);
if (board[x][y] == turn){
board[x][y] = 0;
}
else extrude(board, turn);
}
void insert(int board[3][3], int turn){
int x;
int y;
char input[2];
std::cout << "Insert: ";
std::cin >> input;
x = charconvert(input[0]);
y = charconvert(input[1]);
if (board[x][y] == 0){
board[x][y] = turn;
}
else insert(board, turn);
}
int inputfunk(int board[3][3], bool turn){//handles input and sets board acordingly
int count = 0;
int intturn = turn + 1;
for (int x = 0; x < 3; x++){
for (int y = 0; y < 3; y++){
if (board[x][y] == intturn){
count++;
}
}
}
if (count > 2){
extrude(board, intturn);
printboard(board);
insert(board, intturn);
}
else {
insert(board, intturn);
}
return 0;
}
bool checkWin(int board[3][3], bool turn){
//check if win condition is met
//reurn 0 if no win && 1 if win
int intturn = turn + 1;
for (int x = 0; x < 3; x++){
if (board[x][0] == intturn && board[x][1] == intturn && board[x][2] == intturn){
return 1;
}
}
for (int y = 0; y < 3; y++){
if (board[0][y] == intturn && board[1][y] == intturn && board[2][y] == intturn){
return 1;
}
}
if (board[0][0] == intturn && board[1][1] == intturn && board[2][2] == intturn){
return 1;
}
if (board[2][0] == intturn && board[1][1] == intturn && board[0][2] == intturn){
return 1;
}
return 0;
}