dev: Continue to write the chess logic, working through it bit by bit
This commit is contained in:
parent
d6eb6b69c2
commit
ba64e2bcf3
4 changed files with 96 additions and 15 deletions
54
Piece.cpp
54
Piece.cpp
|
|
@ -7,9 +7,57 @@
|
|||
|
||||
#include "Piece.hpp"
|
||||
|
||||
std::vector<std::pair<int, int>> King::getLegalMoves(int x, int y, const Board& board) const {
|
||||
std::vector<std::pair<int, int>> moveList;
|
||||
|
||||
Piece::~Piece() {
|
||||
return;
|
||||
}
|
||||
|
||||
// because the Piece class is instantiated in another class using
|
||||
// unique_ptr, non-pure virtual functions apparently *must*
|
||||
// have definitions, or the linker freaks out
|
||||
// so this is just a stub that does nothing. it doesn't matter
|
||||
// because only the derived class versions should be called.
|
||||
|
||||
std::vector<Move> Piece::getLegalMoves(const Square &from, const Board &board) const {
|
||||
std::vector<Move> moveList;
|
||||
return moveList;
|
||||
}
|
||||
|
||||
std::vector<Move> King::getLegalMoves(const Square &from, const Board &board) const {
|
||||
std::vector<Move> moveList;
|
||||
|
||||
}
|
||||
|
||||
std::vector<Move> Rook::getLegalMoves(const Square &from, const Board &board) const {
|
||||
std::vector<Move> moveList;
|
||||
const int directions[8][2] = {
|
||||
{-1, 0}, // Up
|
||||
{1, 0}, // Down
|
||||
{0, -1}, // Left
|
||||
{0, 1} // Right
|
||||
};
|
||||
for (auto& dir : directions) {
|
||||
int r = from.rank + dir[0];
|
||||
int f = from.file + dir[1];
|
||||
|
||||
while (r >= 0 && r < 8 && f >= 0 && f < 8) {
|
||||
const auto& target = board[r][f];
|
||||
|
||||
if (!target) {
|
||||
moves.push_back({from,
|
||||
{r, f}});
|
||||
} else if (target->color != this->color) {
|
||||
moves.push_back({from,
|
||||
{r, f}});
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
r += dir[0];
|
||||
f += dir[1];
|
||||
}
|
||||
}
|
||||
|
||||
// calculate legal moves somehow
|
||||
return moveList;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue