-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cpp
More file actions
88 lines (70 loc) · 2.07 KB
/
Board.cpp
File metadata and controls
88 lines (70 loc) · 2.07 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
//
// Created by Sindre Nistad on 6/19/16.
//
#include <boost/concept_check.hpp>
#include <iostream>
#include "Board.h"
void createFirstRow(Piece*** board, Color color){
int i = (color == Color::black) ? 0: 7;
// Place rooks
board[i][0] = new Piece(Type::rook, color);
board[i][7] = new Piece(Type::rook, color);
// Place knights
board[i][1] = new Piece(Type::knight, color);
board[i][6] = new Piece(Type::knight, color);
// Place bishops
board[i][2] = new Piece(Type::bishop, color);
board[i][5] = new Piece(Type::bishop, color);
// Place the queen
board[i][3] = new Piece(Type::queen, color);
// Place the king
board[i][4] = new Piece(Type::king, color);
}
void placePawns(Piece*** board, Color color){
int i = (color == Color::black) ? 1: 6;
for (int j = 0; j < BOARDSIZE; ++j) {
board[i][j] = new Piece(Type::pawn, color);
}
}
Piece*** createBoard(){
Piece*** board = 0;
board = new Piece**[BOARDSIZE];
for (int i = 0; i < BOARDSIZE; ++i) {
board[i] = new Piece*[BOARDSIZE];
if (i == 0){
// Create first row of black
createFirstRow(board, Color::black);
}else if (i == 1){
// Place black pawns
placePawns(board, Color::black);
}else if (i == 6){
// Place white pawns
placePawns(board, Color::white);
}else if (i == 7){
// Place white pieces
createFirstRow(board, Color::white);
}
for (int j = 0; j < BOARDSIZE; ++j) {
board[i][j]->setPosition(i, j);
}
}
return board;
}
void Board::printBoard() {
for (int i = 0; i < BOARDSIZE; ++i) {
for (int j = 0; j < BOARDSIZE; ++j) {
// std::cout << piece2char(this->board[i][j]) << '\t';
std::cout << this->board[i][j]->to_string() << '\t';
}
std::cout << std::endl;
}
}
Board::Board(){
this->board = createBoard();
}
Board::~Board() {
for (int i = 0; i < BOARDSIZE; ++i) {
delete[] board[i];
}
delete[] board;
}