Skip to content

Commit

Permalink
Merge remote-tracking branch 'fairy/master' into nnue
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfab committed Jun 1, 2024
2 parents 9b9501b + 81e3cee commit 5afc012
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 6 deletions.
34 changes: 32 additions & 2 deletions src/movegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,37 @@ inline bool operator<(const ExtMove& f, const ExtMove& s) {
template<GenType>
ExtMove* generate(const Position& pos, ExtMove* moveList);

constexpr size_t moveListSize = sizeof(ExtMove) * MAX_MOVES;

/// The MoveList struct is a simple wrapper around generate(). It sometimes comes
/// in handy to use this class instead of the low level generate() function.
template<GenType T>
struct MoveList {

explicit MoveList(const Position& pos) : last(generate<T>(pos, moveList)) {}

#ifdef USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST
explicit MoveList(const Position& pos)
{
this->moveList = (ExtMove*)malloc(moveListSize);
if (this->moveList == 0)
{
printf("Error: Failed to allocate memory in heap.");
exit(1);
}
this->last = generate<T>(pos, this->moveList);
}

~MoveList()
{
free(this->moveList);
}
#else
explicit MoveList(const Position& pos) : last(generate<T>(pos, moveList))
{
;
}
#endif

const ExtMove* begin() const { return moveList; }
const ExtMove* end() const { return last; }
size_t size() const { return last - moveList; }
Expand All @@ -69,7 +94,12 @@ struct MoveList {
}

private:
ExtMove moveList[MAX_MOVES], *last;
ExtMove* last;
#ifdef USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST
ExtMove* moveList = 0;
#else
ExtMove moveList[MAX_MOVES];
#endif
};

} // namespace Stockfish
Expand Down
4 changes: 2 additions & 2 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
Piece captured = piece_on(type_of(m) == EN_PASSANT ? capture_square(to) : to);
if (to == from)
{
assert((type_of(m) == PROMOTION && sittuyin_promotion()) || (is_pass(m) && pass(us)));
assert((type_of(m) == PROMOTION && sittuyin_promotion()) || (is_pass(m) && (pass(us) || var->wallOrMove )));
captured = NO_PIECE;
}
st->capturedpromoted = is_promoted(to);
Expand Down Expand Up @@ -2128,7 +2128,7 @@ void Position::undo_move(Move m) {

assert(type_of(m) == DROP || empty(from) || type_of(m) == CASTLING || is_gating(m)
|| (type_of(m) == PROMOTION && sittuyin_promotion())
|| (is_pass(m) && pass(us)));
|| (is_pass(m) && (pass(us) || var->wallOrMove)));
assert(type_of(st->capturedPiece) != KING);

// Reset wall squares
Expand Down
13 changes: 11 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,22 @@ typedef uint64_t Bitboard;
constexpr int SQUARE_BITS = 6;
#endif

//When defined, move list will be stored in heap. Delete this if you want to use stack to store move list. Using stack can cause overflow (Segmentation Fault) when the search is too deep.
#define USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST

#ifdef ALLVARS
constexpr int MAX_MOVES = 8192;
constexpr int MAX_PLY = 60;
#ifdef USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST
constexpr int MAX_PLY = 246;
#else
constexpr int MAX_PLY = 60;
#endif
/// endif USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST
#else
constexpr int MAX_MOVES = 1024;
constexpr int MAX_PLY = 246;
constexpr int MAX_PLY = 246;
#endif
/// endif ALLVARS

/// A move needs 16 bits to be stored
///
Expand Down
46 changes: 46 additions & 0 deletions src/variants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ promotionPawnTypes = -
maxRank = 6
maxFile = 6
startFen = 2bnrk/5p/6/6/P5/KRNB2
promotionPieceTypes = nbr
promotionRegionWhite = *6
doubleStep = false

#https://www.chess.com/variants/rookmate
[rookmate:chess]
Expand Down Expand Up @@ -1927,3 +1930,46 @@ customPiece2 = p:mW
connectValue = loss
stalemateValue = win
connectPieceTypes = m

#https://www.pychess.org/variants/shinobiplus
[shinobiplus:crazyhouse]
pieceToCharTable = -
commoner = c
bers = d
dragonHorse = f
archbishop = j
fers = m
shogiKnight = h
lance = l
promotionRegionWhite = *7 *8
promotionRegionBlack = *1 *2 *3
promotionPieceTypes = -
promotedPieceType = p:c m:b h:n l:r
mandatoryPiecePromotion = true
stalemateValue = loss
nFoldRule = 4
perpetualCheckIllegal = true
startFen = rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/4K3[JDFCLHM] w kq - 0 1
capturesToHand = false
whiteDropRegion = *1 *2 *3 *4
immobilityIllegal = true
flagPiece = k
flagRegionWhite = *8
flagRegionBlack = *1

#https://www.pychess.org/variants/khans
[khans:chess]
pieceToCharTable = -
centaur = h
knibis = a
kniroo = l
customPiece1 = t:mNcK
customPiece2 = s:mfhNcfW
promotionPawnTypesBlack = s
promotionPieceTypesBlack = t
stalemateValue = loss
nMoveRuleTypesBlack = s
flagPiece = k
flagRegionWhite = *8
flagRegionBlack = *1
startFen = lhatkahl/ssssssss/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1

0 comments on commit 5afc012

Please sign in to comment.