-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cpp
More file actions
109 lines (87 loc) · 2.51 KB
/
Board.cpp
File metadata and controls
109 lines (87 loc) · 2.51 KB
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
#include "Board.h"
#include "Square.h"
void Board::setBoard()
{
square[7][7].setPieceAndColor(ROOK, WHITE);
square[7][6].setPieceAndColor(KNIGHT, WHITE);
square[7][5].setPieceAndColor(BISHOP, WHITE);
square[7][4].setPieceAndColor(KING, WHITE);
square[7][3].setPieceAndColor(QUEEN, WHITE);
square[7][2].setPieceAndColor(BISHOP, WHITE);
square[7][1].setPieceAndColor(KNIGHT, WHITE);
square[7][0].setPieceAndColor(ROOK, WHITE);
square[0][0].setPieceAndColor(ROOK, BLACK);
square[0][1].setPieceAndColor(KNIGHT, BLACK);
square[0][2].setPieceAndColor(BISHOP, BLACK);
square[0][3].setPieceAndColor(QUEEN, BLACK);
square[0][4].setPieceAndColor(KING, BLACK);
square[0][5].setPieceAndColor(BISHOP, BLACK);
square[0][6].setPieceAndColor(KNIGHT, BLACK);
square[0][7].setPieceAndColor(ROOK, BLACK);
for (int i = 0; i < 8; i++)
{
square[6][i].setPieceAndColor(PAWN, WHITE);
square[1][i].setPieceAndColor(PAWN, BLACK);
}
for (int i = 2; i < 6; i++)
{
for (int j = 0; j < 8; j++)
square[i][j].setPieceAndColor(Name::EMPTY, Color::NONE);
}
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
{
square[i][j].setX(i);
square[i][j].setY(j);
}
}
void Board::printBoard() {
using namespace std;
cout << " C: 0 1 2 3 4 5 6 7 " << endl << "R:" << endl;
for (int i = 0; i < 8; i++)
{
cout << " " << i << " ";
for (int j = 0; j < 8; j++)
{
Name p = square[i][j].getPiece();
Color c = square[i][j].getColor();
switch (p)
{
case KING: (c == WHITE) ? cout << " K " : cout << " k ";
break;
case QUEEN: (c == WHITE) ? cout << " Q " : cout << " q ";
break;
case BISHOP:(c == WHITE) ? cout << " B " : cout << " b ";
break;
case KNIGHT:(c == WHITE) ? cout << " H " : cout << " h ";
break;
case ROOK: (c == WHITE) ? cout << " R " : cout << " r ";
break;
case PAWN: (c == WHITE) ? cout << " P " : cout << " p ";
break;
case EMPTY: cout << " " << "*" << " ";
break;
default: cout << "XXX";
break;
}
}
cout << endl;
}
}
void Board::testStaleMate()
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
square[i][j].setPieceAndColor(Name::EMPTY, Color::NONE);
}
square[7][4].setPieceAndColor(KING, WHITE);
square[1][5].setPieceAndColor(QUEEN, WHITE);
square[0][0].setPieceAndColor(KING, BLACK);
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
{
square[i][j].setX(i);
square[i][j].setY(j);
}
}