-
Notifications
You must be signed in to change notification settings - Fork 0
/
feld.cpp
147 lines (132 loc) · 3.44 KB
/
feld.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
147
#include<iostream>
#include"feld.h"
using namespace std;
feld::feld(int size): size(size), field(size, vector<stein>(size) ){
}
feld::feld(): size(10), field(10, vector<stein>(10) ){
}
int feld::getSize() const {
return this->size;
}
stein * feld::getField(int x, int y){
return &this->field[x][y];
}
stein * feld::getField(pair<int, int> s){
return &this->field[s.first][s.second];
}
vector<vector<stein> > feld::getField(){
return this->field;
}
player feld::getPlayer(int x, int y){
if((x < 0 && y >= this->size) || (x >= this->size && y < 0)) {
return empty;
} else if(x < 0 || x >= this->size) {
return playerTwo;
} else if(y < 0 || y >= this->size) {
return playerOne;
} else {
return this->field[x][y].getStatus();
}
}
player feld::getPlayer(pair<int, int> s){
return this->field[s.first][s.second].getStatus();
}
void feld::setzen(int x, int y, player p){
this->field[x][y].setzen(p);
}
void feld::setzen(pair<int, int> f, player p){
this->field[f.first][f.second].setzen(p);
}
bool feld::test(int x, int y, player p){
if (x < 0 || y < 0 || x >= this->size || y >= this->size){
return false;
}
else if (this->getField(x, y)->getCheck()){
return false;
}
else if (this->getField(x, y)->getStatus() != p){
this->field[x][y].check(true);
return false;
}
else if ((p == playerOne && y + 1 == this->size) || (p == playerTwo && x + 1 == this->size)){
this->field[x][y].check(true);
return true;
}
else {
this->field[x][y].check(true);
return test(x, y - 1, p) || test(x, y + 1, p) || test(x - 1, y, p) || test(x + 1, y, p) || test(x - 1, y + 1, p) || test(x + 1, y - 1, p); // returns True if any of the sub tests returns True
}
}
bool feld::pruefe(player p){
for (int x = 0; x < this->size; x++){
for(int y = 0; y < this->size; y++){
this->field[x][y].check(false);
}
}
bool res = false;
for (int i = 0; i < this->size; i++){
switch (p){
case playerOne:
res = res || this->test(i, 0, p);
break;
case playerTwo:
res = res || this->test(0, i, p);
break;
default:
res = false;
}
if (res){
return true;
}
}
for (int x = 0; x < this->size; x++){
for(int y = 0; y < this->size; y++){
this->field[x][y].check(false);
}
}
return res;
}
void feld::print(){
int i;
for (i = 0; i < this->size; ++i){
cout << " " << i + 1 << " ";
}
cout << "\n ";
for (i = 0; i < this->size; ++i){
cout << "@" << "/ \\"; // füllt die erste zeile der ausgabe mit "/ \" sowie "@"
}
cout << "\n";
for (int y = 0; y < this->size; ++y){
for (i = 0; i < y; ++i){ // setzt ausreichend leer zeichen vor das erste zeichen
cout << " "; // das das spielfeld richtig zu erkennen ist
}
cout << "X| ";
for (int x = 0; x < this->size; ++x){
switch(this->field[x][y].getStatus()){ // sorgt dafür das die jeweilige zeile mit steinen ausgegeben wird
case empty: // villeicht auch global setzen
cout << " ";
break;
case playerOne: // setzt das zeichen für player one (villeicht gegen globale variable zu ersetzuen)
cout << "@";
break;
case playerTwo: // selbige wie player one zu player two
cout << "X";
break;
}
cout << " | ";
}
cout << y + 1 << "\n";
for (i = 0; i < y; ++i){
cout << " ";
}
cout << " ";
for (i = 0; i < this->size; ++i){
cout << "\\ / "; // giebt den stuff zwischen den "wichtigen" zeilen aus ;D
}
if (i == this->size && y + 1 != this->size){
cout << "\\";
}
cout << "\n";
}
cout << "\n";
}