Compare commits

..

No commits in common. "cc37d834fe6f514af1c54cea520b5ed1f75dbb12" and "c577c23f1f4ce6f11dce896a799b9e5d05c6698a" have entirely different histories.

4 changed files with 3 additions and 110 deletions

View file

@ -58,7 +58,7 @@ std::vector<Move> Rook::getLegalMoves(const Square &from, const Board &board) co
if (!target) { if (!target) {
moveList.push_back({from, moveList.push_back({from,
targetSquare}); targetSquare});
} else if (target && target->getColour() != this->getColour()) { } else if (target->getColour() != this->colour) {
moveList.push_back({from, moveList.push_back({from,
targetSquare}); targetSquare});
break; break;
@ -94,84 +94,6 @@ std::vector<Move> Bishop::getLegalMoves(const Square &from, const Board &board)
std::vector<Move> Pawn::getLegalMoves(const Square &from, const Board &board) const { std::vector<Move> Pawn::getLegalMoves(const Square &from, const Board &board) const {
std::vector<Move> moveList; std::vector<Move> moveList;
const int directions[2][4][2] = {
{ // black
{-1, 0}, // Up
{-2, 0}, // 2up first move
{-1, 1}, // attack to right
{-1, -1} // attack to left
},
{ // white
{1, 0}, // down
{2, 0}, // 2down first move
{1, 1}, // attack to right
{1, -1} // attack to left
}
};
if (this->getColour() == PIECE_BLACK) {
// go through black options
for (auto &dir : directions[0]) {
int r = from.rank + dir[0];
int f = from.file + dir[1];
if (r >= 0 && r < 8 && f >= 0 && f < 8) { // no need for a while loop as we only have finite moves in limited directions
const auto& target = board.boardGrid[r][f];
auto ra = static_cast<Rank> (r);
auto fi = static_cast<File> (f);
Square targetSquare = {ra, fi};
if (dir[0] == -2 && !this->checkIfMoved()) {
// then 2 is potentially legal
if (!target && !(board.boardGrid[r + 1][f])) // check both squares for pieces of any colour
moveList.push_back({from, targetSquare});
else
break;
} else if (abs(dir[1]) == 1) { // attempted capture (diagonal)
if (target && target->getColour() != this->getColour()) {
// legal capture
moveList.push_back({from, targetSquare});
} else {
break;
}
} else { // normal one square forward
if (!target)
moveList.push_back({from, targetSquare});
}
// now check if we are on 8th rank, for promotion
}
}
} else if (this->getColour() == PIECE_WHITE) {
for (auto &dir : directions[1]) {
// go through white options
int r = from.rank + dir[0];
int f = from.file + dir[1];
if (r >= 0 && r < 8 && f >= 0 && f < 8) { // no need for a while loop as we only have finite moves in limited directions
const auto& target = board.boardGrid[r][f];
auto ra = static_cast<Rank> (r);
auto fi = static_cast<File> (f);
Square targetSquare = {ra, fi};
if (dir[0] == 2 && !this->checkIfMoved()) {
// then 2 is potentially legal
if (!target && !(boardGrid[r - 1][f]))
moveList.push_back({from, targetSquare});
else
break;
} else if (abs(dir[1]) == 1) { // attempted capture (diagonal)
if (target && target->getColour() != this->getColour()) { // can only move there if it's a capture
// legal capture
moveList.push_back({from, targetSquare});
} else {
break;
}
} else { // normal one square forward
if (!target)
moveList.push_back({from, targetSquare});
}
// now check if we are on 8th rank, for promotion
}
}
}
return moveList; return moveList;
} }

View file

@ -54,7 +54,6 @@ protected:
bool hasMoved = false; bool hasMoved = false;
public: public:
Piece(PieceColour pColour) : colour(pColour) { Piece(PieceColour pColour) : colour(pColour) {
} }
virtual ~Piece(); virtual ~Piece();
@ -63,34 +62,17 @@ public:
PieceColour getColour() const { PieceColour getColour() const {
return colour; return colour;
} }
bool checkIfMoved() const {
return hasMoved;
}
}; };
class King : public Piece { class King : public Piece {
friend class Board;
public: public:
King(PieceColour colour) : Piece(colour) { King(PieceColour colour) : Piece(colour) {
} }
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override; virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override;
bool checkForCheck() const {
return inCheck;
}
bool checkForCastle() const {
return canCastle;
}
protected:
bool canCastle = true;
bool inCheck = false;
}; };
class Rook : public Piece { class Rook : public Piece {
friend class Board;
public: public:
Rook(PieceColour colour) : Piece(colour) { Rook(PieceColour colour) : Piece(colour) {
@ -99,7 +81,6 @@ public:
}; };
class Queen : public Piece { class Queen : public Piece {
friend class Board;
public: public:
Queen(PieceColour colour) : Piece(colour) { Queen(PieceColour colour) : Piece(colour) {
@ -108,7 +89,6 @@ public:
}; };
class Knight : public Piece { class Knight : public Piece {
friend class Board;
public: public:
Knight(PieceColour colour) : Piece(colour) { Knight(PieceColour colour) : Piece(colour) {
@ -117,7 +97,6 @@ public:
}; };
class Bishop : public Piece { class Bishop : public Piece {
friend class Board;
public: public:
Bishop(PieceColour colour) : Piece(colour) { Bishop(PieceColour colour) : Piece(colour) {
@ -126,7 +105,6 @@ public:
}; };
class Pawn : public Piece { class Pawn : public Piece {
friend class Board;
public: public:
Pawn(PieceColour colour) : Piece(colour) { Pawn(PieceColour colour) : Piece(colour) {

View file

@ -39,10 +39,6 @@
<itemPath>NeoPixel.cpp</itemPath> <itemPath>NeoPixel.cpp</itemPath>
</logicalFolder> </logicalFolder>
</logicalFolder> </logicalFolder>
<sourceRootList>
<Elem>.</Elem>
<Elem>inc</Elem>
</sourceRootList>
<projectmakefile>Makefile</projectmakefile> <projectmakefile>Makefile</projectmakefile>
<confs> <confs>
<conf name="Debug" type="2"> <conf name="Debug" type="2">

View file

@ -8,10 +8,7 @@
<make-project-type>0</make-project-type> <make-project-type>0</make-project-type>
<sourceEncoding>UTF-8</sourceEncoding> <sourceEncoding>UTF-8</sourceEncoding>
<make-dep-projects/> <make-dep-projects/>
<sourceRootList> <sourceRootList/>
<sourceRootElem>.</sourceRootElem>
<sourceRootElem>inc</sourceRootElem>
</sourceRootList>
<confList> <confList>
<confElem> <confElem>
<name>Debug</name> <name>Debug</name>