-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpelen.h
141 lines (131 loc) · 2.85 KB
/
Spelen.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
133
134
135
136
137
138
139
140
141
enum richting {
boven, rechts, onder, links
};
bool zetKan(int x, int y, richting springKant){
switch( springKant ){
case boven:
return y > 1 && gaten[x][y-1] == knikker && gaten[x][y-2] == open;
case rechts:
return x < 5 && gaten[x+1][y] == knikker && gaten[x+2][y] == open;
case onder:
return y < 5 && gaten[x][y+1] == knikker && gaten[x][y+2] == open;
case links:
return x > 1 && gaten[x-1][y] == knikker && gaten[x-2][y] == open;
}
return false;
}
bool zetKan(int x, int y, int toX, int toY){
if( toX == x ){
if( toY == y-2 ){
return zetKan(x,y,boven);
}
if( toY == y+2 ){
return zetKan(x,y,onder);
}
}
if( toY == y ){
if( toX == x-2 ){
return zetKan(x,y,links);
}
if( toX == x+2 ){
return zetKan(x,y,rechts);
}
}
return false;
}
void doeZet(int x, int y, richting springKant){
gaten[x][y] = open;
switch( springKant ){
case boven:
gaten[x][y-1] = open;
gaten[x][y-2] = knikker;
return;
case rechts:
gaten[x+1][y] = open;
gaten[x+2][y] = knikker;
return;
case onder:
gaten[x][y+1] = open;
gaten[x][y+2] = knikker;
return;
case links:
gaten[x-1][y] = open;
gaten[x-2][y] = knikker;
return;
}
}
bool holeIsOnBoard(int x, int y){
return !( (x < 2 || x > 4) && (y < 2 || y > 4) );
}
void beginSituatie(){
for( int y = 0; y < 7; ++y ){
for( int x = 0; x < 7; ++x ){
if( holeIsOnBoard(x,y) ){
gaten[x][y] = knikker;
} else {
gaten[x][y] = bestaatNiet;
}
}
}
gaten[3][3] = open;
}
void doeZet(int x, int y, int toX, int toY){
if( toX == x ){
if( toY == y-2 ){
doeZet(x,y,boven);
}
if( toY == y+2 ){
doeZet(x,y,onder);
}
}
if( toY == y ){
if( toX == x-2 ){
doeZet(x,y,links);
}
if( toX == x+2 ){
doeZet(x,y,rechts);
}
}
}
void zetTerug(int x, int y, richting springKant){
gaten[x][y] = knikker;
switch( springKant ){
case boven:
gaten[x][y-1] = knikker;
gaten[x][y-2] = open;
return;
case rechts:
gaten[x+1][y] = knikker;
gaten[x+2][y] = open;
return;
case onder:
gaten[x][y+1] = knikker;
gaten[x][y+2] = open;
return;
case links:
gaten[x-1][y] = knikker;
gaten[x-2][y] = open;
return;
}
}
void zetTerug(int x, int y, int toX, int toY){
int middleX = (x + toX) / 2;
int middleY = (y + toY) / 2;
gaten[x][y] = knikker;
gaten[middleX][middleY] = knikker;
gaten[toX][toY] = open;
}
bool gewonnen(){
for( int y = 0; y < 7; ++y ){
for( int x = 0; x < 7; ++x ){
if( (x == 3 && y == 3) != (gaten[x][y] == knikker) ){
return false;
}
}
}
return true;
}
bool gewonnen(bordKengetal state){
bordKengetal middleMask = gatMask(3,3);
return state == middleMask;
}