-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiece.cpp
147 lines (118 loc) · 3.14 KB
/
Piece.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
//
// Created by Sindre Nistad on 6/19/16.
//
#include <cassert>
#include "Piece.h"
using namespace std;
bool Piece::canMovePawn(Board* board, std::string move_to){
}
bool Piece::canMove(Board* board, std::string move_to) {
switch (Piece::type){
case Type::pawn:
// First move: move one or two up (or down)
break;
case Type::knight:
break;
case Type::bishop:
break;
case Type::rook:
break;
case Type::king:
break;
case Type::queen:
break;
default:
return false;
}
};
void Piece::setPosition(Position pos){
this->position = pos;
}
void Piece::setPosition(int column, int row) {
this->position = Position(row, column);
}
Piece::Piece(Type t, Color c, int column, int row) {
Piece::Piece(t, c, Position(row, column));
}
Piece::Piece(Type t, Color c, Position position) {
this->type = t;
this->color = c;
this->position = position;
}
//Piece::Piece(Type t, Color c) {
// this->type = t;
// this->color = c;
// this->position = NULL;
//}
Piece::Piece() {
this->type = Type::none;
this->position = NULL;
}
Piece::~Piece() {
// delete this->position;
// delete this->type;
// delete this->color;
// delete this->hasMoved;
// delete this;
}
Position Piece::getPosition(void) {
return this->position;
}
Type Piece::getType(void) {
return type;
}
Color Piece::getColor(void) {
return color;
}
char Piece::to_string() {
if (this == nullptr || this == NULL) return ' ';
switch (this->getType()) {
case Type::pawn:
return (this->getColor() == Color::black) ? PAWNBLACK : PAWNWHITE;
case Type::knight:
return (this->getColor() == Color::black) ? KNIGHTBLACK : KNIGHTWHITE;
case Type::bishop:
return (this->getColor() == Color::black) ? BISHOPBLACK : BISHOPWHITE;
case Type::rook:
return (this->getColor() == Color::black) ? ROOKBLACK : ROOKWHITE;
case Type::queen:
return (this->getColor() == Color::black) ? QUEENBLACK : QUEENWHITE;
case Type::king:
return (this->getColor() == Color::black) ? KINGBLACK : KINGWHITE;
default:
return ' ';
}
}
/*
* Implementation of the Position class
*/
Position::Position(int row, int column){
assert(0 <= row && row < BOARDSIZE);
assert(0 <= column && column < BOARDSIZE);
char letter = column + 'a';
char number = row + '1';
char p[3] = {letter, number, '\0'};
this->row = row;
this->column = column;
this->position = p;
}
Position::Position(std::string position) {
int letter = position[0] - 'a';
int number = position[1] - '1'; // In chess, it goes from 1 - 8.
assert(0 <= letter && letter < BOARDSIZE);
assert(0 <= number && number < BOARDSIZE);
this->column = letter;
this->row = number;
this->position = position;
}
int Position::getColumn() {
return this->column;
}
int Position::getRow() {
return this->row;
}
std::string Position::getPosition() {
return this->position;
}
Position::Position() {
}