-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
146 lines (143 loc) · 2.73 KB
/
main.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
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
#include <iostream>
#include <stdlib.h>
using namespace std;
enum Point{
empty,
white,
black,
};
class Board
{
int size;
Point ** arr;
bool ** visited;
public:
Board(int s)
{
size=s;
int i,j;
// Inicializa arr (tabuleiro)
arr = (Point**) malloc(size * sizeof(Point*));
for(i=0;i<size;i++)
arr[i] = (Point*) malloc(size*sizeof(Point));
for(i=0;i<size;i++)
for(j=0;j<size;j++)
arr[i][j]=empty;
// Inicializa visited
visited = (bool**) malloc(size * sizeof(bool*));
for(i=0;i<size;i++)
visited[i] = (bool*) malloc(size*sizeof(bool));
cleanup_visited();
}
void cleanup_visited(void)
{
int i,j;
for(i=0;i<size;i++)
for(j=0;j<size;j++)
visited[i][j]=false;
}
void show(void)
{
cout<<endl<<endl;
int i,j;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
switch (arr[i][j])
{
case(empty):
cout<<". ";
break;
case(white):
cout<<"O ";
break;
case(black):
cout<<"X ";
break;
default:
cout<<endl<<"algo errado no codigo "<<endl;
return;
}
cout<<" "<<i+1<<endl<<endl;
}
for(j=1;j<=size;j++)
{
cout<<j<<" ";
if (j<10) cout<<" ";
}
cout<<endl;
}
void show_v(void)
{
int i,j;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
cout<<visited[i][j]<<" ";
cout<<endl;
}
cout<<endl;
}
bool is_legal(int x, int y)
{
return true;
}
bool alive(int x, int y)
{
x=1; y=1;
visited[x][y] = true;
if(((0<x)&&
(arr[x-1][y]==empty
|| (arr[x-1][y]==arr[x][y] && !visited[x-1][y] && alive(x+1,y))))
|| ((0<y)&&
(arr[x][y-1]==empty
|| (arr[x][y-1]==arr[x][y] && !visited[x][y-1] && alive(x,y-1))))
|| ((x<size)&&
(arr[x+1][y]==empty
|| (arr[x+1][y]==arr[x][y] && !visited[x+1][y] && alive(x+1,y))))
|| ((y<size)&&
(arr[x][y+1]==empty
|| (arr[x][y+1]==arr[x][y] && !visited[x][y+1] && alive(x,y+1))))
)
{
cleanup_visited();
return true;
}
cleanup_visited();
return false;
}
bool put(int x, int y,Point value)
{
x-=1;y-=1;
if (arr[x][y]==empty)
{
arr[x][y]=value;
}else{
return false;
}
return true;
}
};
int main()
{
Board board(19);
board.show();
string S="";
int a=0, b=0;
Point current_player=black;
while (a!=-1)
{
cout<<"Digite a sua jogada ";
cin>>a>>b;
if(board.put(a,b,current_player))
{
board.show();
current_player = (current_player==black) ? white : black;
}else{
cout<<"Jogada invalida"<<endl;
}
}
cout<<board.alive(1,1)<<endl;
board.cleanup_visited();
return 0;
}