Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support Extinction Chess and Kinglet Chess
- Loading branch information
Showing
7 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
This file is part of Cute Chess. | ||
Cute Chess is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Cute Chess is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Cute Chess. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "extinctionboard.h" | ||
|
||
namespace Chess { | ||
|
||
ExtinctionBoard::ExtinctionBoard(const QSet<int>& set, | ||
bool allPromotions) | ||
: StandardBoard(), | ||
m_allPromotions(allPromotions) | ||
{ | ||
for (const auto& s: set) | ||
m_pieceSet.append(s); | ||
} | ||
|
||
Board* ExtinctionBoard::copy() const | ||
{ | ||
return new ExtinctionBoard(*this); | ||
} | ||
|
||
QString ExtinctionBoard::variant() const | ||
{ | ||
return "extinction"; | ||
} | ||
|
||
QString ExtinctionBoard::defaultFenString() const | ||
{ | ||
return "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; | ||
} | ||
|
||
bool ExtinctionBoard::kingsCountAssertion(int, int) const | ||
{ | ||
return extinctPiece(Side::White).isEmpty() | ||
|| extinctPiece(Side::Black).isEmpty(); | ||
} | ||
|
||
void ExtinctionBoard::addPromotions(int sourceSquare, | ||
int targetSquare, | ||
QVarLengthArray<Move>& moves) const | ||
{ | ||
if (m_allPromotions) | ||
StandardBoard::addPromotions(sourceSquare, targetSquare, moves); | ||
moves.append(Move(sourceSquare, targetSquare, King)); | ||
} | ||
|
||
bool ExtinctionBoard::inCheck(Side, int) const | ||
{ | ||
return false; | ||
} | ||
|
||
Piece ExtinctionBoard::extinctPiece(Side side) const | ||
{ | ||
for (const int type: m_pieceSet) | ||
{ | ||
bool pieceFound = false; | ||
for (int i = 0; i < arraySize(); i++) | ||
{ | ||
Piece piece = pieceAt(i); | ||
if (side == piece.side() && type == piece.type()) | ||
{ | ||
pieceFound = true; | ||
break; | ||
} | ||
} | ||
if (!pieceFound) | ||
return Piece(side, type); | ||
} | ||
return Piece(); | ||
} | ||
|
||
Result ExtinctionBoard::result() | ||
{ | ||
QString str; | ||
Side side = sideToMove(); | ||
// captures | ||
Piece piece = extinctPiece(side); | ||
if (!piece.isValid()) | ||
// promotions | ||
piece = extinctPiece(side.opposite()); | ||
if (piece.isValid()) | ||
{ | ||
Side winner = piece.side().opposite(); | ||
int type = piece.type(); | ||
str = tr("Missing %1: %2 wins") | ||
.arg(pieceString(type)) | ||
.arg(winner.toString()); | ||
return Result(Result::Win, winner, str); | ||
} | ||
|
||
// stalemate | ||
if (!canMove()) | ||
{ | ||
str = tr("Draw by stalemate"); | ||
return Result(Result::Draw, Side::NoSide, str); | ||
} | ||
|
||
// 50 move rule | ||
if (reversibleMoveCount() >= 100) | ||
{ | ||
str = tr("Draw by fifty moves rule"); | ||
return Result(Result::Draw, Side::NoSide, str); | ||
} | ||
|
||
// 3-fold repetition | ||
if (repeatCount() >= 2) | ||
{ | ||
str = tr("Draw by 3-fold repetition"); | ||
return Result(Result::Draw, Side::NoSide, str); | ||
} | ||
|
||
return Result(); | ||
} | ||
|
||
|
||
|
||
KingletBoard::KingletBoard() : | ||
ExtinctionBoard({Pawn}, false) | ||
{ | ||
} | ||
|
||
Board* KingletBoard::copy() const | ||
{ | ||
return new KingletBoard(*this); | ||
} | ||
|
||
QString KingletBoard::variant() const | ||
{ | ||
return "kinglet"; | ||
} | ||
|
||
} // namespace Chess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
This file is part of Cute Chess. | ||
Cute Chess is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Cute Chess is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Cute Chess. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef EXTINCTIONBOARD_H | ||
#define EXTINCTIONBOARD_H | ||
|
||
#include "standardboard.h" | ||
|
||
namespace Chess { | ||
|
||
/*! | ||
* \brief A board for Extinction Chess | ||
* | ||
* Extinction Chess (Survival of the Species by R. W. Schmittberger, USA, | ||
* 1985) is a variant of standard chess but has a different objective. | ||
* | ||
* A side wins if their opponent loses all pieces of any kind. | ||
* | ||
* The king has no royal obligation, so there is no check and the king | ||
* can be captured. Pawns can also promote to king. Castling is allowed. | ||
* | ||
* \note Rules: https://en.wikipedia.org/wiki/Extinction_chess | ||
* | ||
* ExtinctionBoard uses Polyglot-compatible zobrist position keys, | ||
* so adequate opening books in Polyglot format can be used. | ||
* | ||
* \note Standard Chess Rules: http://www.fide.com/component/handbook/?id=124&view=article | ||
* \sa PolyglotBook | ||
*/ | ||
class LIB_EXPORT ExtinctionBoard : public StandardBoard | ||
{ | ||
public: | ||
/*! Creates a new ExtinctionBoard object. | ||
* The \a set defines piece types that must not become extinct. | ||
* If \a allPromotions is set (default) then all promotion | ||
* types of standard chess are allowed (king anyhow). | ||
*/ | ||
ExtinctionBoard(const QSet<int>& set | ||
= QSet<int>{King, Queen, Rook, Bishop, Knight, Pawn}, | ||
bool allPromotions = true); | ||
|
||
// Inherited from StandardBoard | ||
virtual Board* copy() const; | ||
virtual QString variant() const; | ||
virtual QString defaultFenString() const; | ||
virtual Result result(); | ||
protected: | ||
// Inherited from StandardBoard | ||
virtual bool kingsCountAssertion(int whiteKings, | ||
int blackKings) const; | ||
virtual bool inCheck(Side side, int square = 0) const; | ||
virtual void addPromotions(int sourceSquare, | ||
int targetSquare, | ||
QVarLengthArray<Move>& moves) const; | ||
|
||
private: | ||
bool m_allPromotions; | ||
QVarLengthArray<int> m_pieceSet; | ||
Piece extinctPiece(Side side) const; | ||
}; | ||
|
||
|
||
/*! | ||
* \brief A board for Kinglet Chess | ||
* | ||
* Kinglet (V. R. Parton, UK 1953) is a standard chess variant similar to | ||
* Extinction Chess. There are two differences: | ||
* | ||
* A side wins if their opponent loses all pawns (by capture or promotion). | ||
* Pawns can only promote to king. | ||
* | ||
* The king has no royal obligation, so there is no check and the king can | ||
* be captured. Castling is allowed. Stalemate is a draw. | ||
* | ||
* \note Rules: https://en.wikipedia.org/wiki/V._R._Parton#Kinglet_Chess | ||
* \sa Extinction Chess | ||
*/ | ||
class LIB_EXPORT KingletBoard : public ExtinctionBoard | ||
{ | ||
public: | ||
KingletBoard(); | ||
virtual Board *copy() const; | ||
virtual QString variant() const; | ||
}; | ||
|
||
} // namespace Chess | ||
#endif // EXTINCTIONBOARD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters