Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6c0054b
Rewrite how the board is stored and moves are made
razvanfilea Nov 20, 2019
1c41cd3
Remove 'ToList' MoveGen template arg, make some fixes
razvanfilea Nov 22, 2019
2bfdff3
Fix a critical error with Board::doMove()
razvanfilea Nov 24, 2019
9db8df9
Fix getPhase always returning ENDGAME
razvanfilea Nov 24, 2019
8fd4e8c
Improve the Evaluation function performance
razvanfilea Nov 24, 2019
bee2ee1
Fix Board::hasValidState and update Pawn PSQT
razvanfilea Nov 26, 2019
68d9853
Switch to the previous Multi Threading model
razvanfilea Nov 28, 2019
7154003
Remove KING_DANGER MoveGen
razvanfilea Nov 28, 2019
eb1963c
Add age attribute to the TranspositionTable
razvanfilea Nov 29, 2019
2da9711
Fix crash when generating legal moves
razvanfilea Nov 30, 2019
f922ceb
Rewrite how the UI processes positions
razvanfilea Nov 30, 2019
220b4d7
Rename NegaMax class to Search
razvanfilea Nov 30, 2019
ee721fd
Work on the ThreadPool
razvanfilea Nov 30, 2019
9a9e5ac
Solve a bug with Castling and disable EnPassant for now
razvanfilea Nov 30, 2019
faba2c2
Add Generated Nodes to Stats
razvanfilea Dec 1, 2019
d73bb5c
Remake the Settings Screen
razvanfilea Dec 1, 2019
9b46c3e
Clean ThreadSafeQueue and ThreadPool
razvanfilea Dec 1, 2019
d5d5ae0
Revert to the old Pawn PSQT
razvanfilea Dec 8, 2019
1b60b38
Re-enable EnPassant
razvanfilea Dec 9, 2019
c0be29b
Add Platform Specific Implementations for BSF and BSR
razvanfilea Dec 10, 2019
8a64bbc
Remove StackVector
razvanfilea Dec 10, 2019
7889cfa
Fix compile errors
razvanfilea Dec 10, 2019
e35ab03
Remake the Pawn Evaluation add Connected Bonus
razvanfilea Dec 11, 2019
459400d
Merge Rays.h into Bitboard.h
razvanfilea Dec 11, 2019
9be2e38
Fix Pawn Move Generation from last commit
razvanfilea Dec 12, 2019
9a37891
Remove Light Theme, add Rook on Queen File Evaluation
razvanfilea Dec 15, 2019
b81a38c
Rewrite Piece class to only use 1 byte
razvanfilea Dec 15, 2019
3a122a9
New icon
razvanfilea Dec 15, 2019
99a93b5
Release 1.0
razvanfilea Dec 15, 2019
b8651a6
Fix issues with the Pull Request
razvanfilea Dec 15, 2019
8c8a8d9
Delete MoveOrdering.h
razvanfilea Dec 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix crash when generating legal moves
  • Loading branch information
razvanfilea committed Nov 30, 2019
commit 2da97110c0e80d31951136f2bc51ccd3a506f05d
21 changes: 12 additions & 9 deletions ChessAndroid/app/src/main/cpp/chess/BoardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void BoardManager::initBoardManager(const PieceChangeListener &listener, const b

s_MovesHistory.clear();
s_MovesHistory.reserve(200);
s_MovesHistory.emplace_back(0u, 0u, s_Board);
s_MovesHistory.emplace_back(64u, 64u, s_Board);

Stats::resetStats();

Expand All @@ -37,18 +37,22 @@ void BoardManager::loadGame(const std::vector<std::pair<byte, byte>> &moves, con

s_Board.initDefaultBoard();

s_MovesHistory.emplace_back(0u, 0u, s_Board);
s_MovesHistory.clear();
s_MovesHistory.emplace_back(64u, 64u, s_Board);

try {
for (const auto &move : moves)
{
s_Board.doMove(move.first, move.second);
s_Board.score = Evaluation::evaluate(s_Board);
s_MovesHistory.emplace_back(move.first, move.second, s_Board);
s_Board.doMove(move.first, move.second);
s_Board.score = Evaluation::evaluate(s_Board);
s_MovesHistory.emplace_back(move.first, move.second, s_Board);
}
} catch (...) {
// Couldn't load all moves correctly
}
// Couldn't load all moves correctly, fallback to the original board
s_Board.initDefaultBoard();
s_MovesHistory.clear();
s_MovesHistory.emplace_back(64u, 64u, s_Board);
}

s_Listener(s_Board.state, true, {});
}
Expand Down Expand Up @@ -107,13 +111,12 @@ void BoardManager::moveComputerPlayer(const Settings &settings)
Stats::resetStats();
Stats::startTimer();

assert(s_Board.colorToMove != toColor(s_IsPlayerWhite));
const RootMove bestMove = NegaMax::findBestMove(s_Board, settings);

Stats::stopTimer();
s_IsWorking = false;
movePiece(bestMove.startSq, bestMove.destSq, false);

s_IsWorking = false;
s_WorkerThread.detach();
}

Expand Down
5 changes: 3 additions & 2 deletions ChessAndroid/app/src/main/cpp/chess/algorithm/NegaMax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ short NegaMax::s_BestMoveFound{};
RootMove NegaMax::findBestMove(const Board &board, const Settings &settings)
{
const auto validMoves = board.listValidMoves<RootMove>();
assert(!validMoves.empty());

for (const RootMove &move : validMoves)
if (move.board.state == State::WINNER_WHITE || move.board.state == State::WINNER_BLACK)
Expand All @@ -25,7 +26,7 @@ RootMove NegaMax::findBestMove(const Board &board, const Settings &settings)
const auto threadCount = settings.getThreadCount();
s_QuiescenceSearchEnabled = settings.performQuiescenceSearch();

// If the Transposition Table wasn't resized, clean it
// If the Transposition Table wasn't resized, increment its age
if (!s_SearchCache.setSize(settings.getCacheTableSizeMb()))
s_SearchCache.incrementAge();
NegaMaxThreadPool::updateThreadCount(threadCount);
Expand Down Expand Up @@ -90,7 +91,7 @@ RootMove NegaMax::negaMaxRoot(const std::vector<RootMove> &validMoves, const uns
for (auto &future : futures)
future.get(); // Wait for the Search to finish

s_BestMoveFound = alpha;
s_BestMoveFound = validMoves.front().board.colorToMove ? alpha : -alpha;

return bestMove;
}
Expand Down
2 changes: 1 addition & 1 deletion ChessAndroid/app/src/main/cpp/chess/data/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ std::vector<Board> Board::listQuiescenceMoves() const

assert(possibleMoves == (possibleMoves & allPieces[oppositeColor(colorToMove)]));
// Make sure we are not capturing the king
possibleMoves &= getType(colorToMove, KING);
possibleMoves &= ~getType(colorToMove, KING);

while (possibleMoves)
{
Expand Down
2 changes: 1 addition & 1 deletion ChessAndroid/app/src/main/cpp/chess/data/Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ std::vector<T> Board::listValidMoves() const noexcept
U64 possibleMoves = selectedPiece.getPossibleMoves(startSq, *this);

// Make sure we are not capturing the king
possibleMoves &= getType(colorToMove, KING);
possibleMoves &= ~getType(colorToMove, KING);

while (possibleMoves)
{
Expand Down