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
Rename NegaMax class to Search
  • Loading branch information
razvanfilea committed Nov 30, 2019
commit 220b4d773165fb35874cdc22da09eac26b282613
4 changes: 2 additions & 2 deletions ChessAndroid/app/src/main/cpp/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "chess/Stats.h"
#include "chess/data/Board.h"
#include "chess/persistence/MovesPersistence.h"
#include "chess/algorithm/NegaMax.h"
#include "chess/algorithm/Search.h"

JavaVM *jvm = nullptr;
jobject gameManagerInstance;
Expand Down Expand Up @@ -220,7 +220,7 @@ Java_net_theluckycoder_chess_Native_movePiece(JNIEnv */*pEnv*/, jclass /*type*/,
external JNIEXPORT jint JNICALL
Java_net_theluckycoder_chess_Native_getBestMoveFound(JNIEnv */*pEnv*/, jclass /*type*/)
{
return static_cast<jint>(NegaMax::getBestMoveFound());
return static_cast<jint>(Search::getBestMoveFound());
}


Expand Down
4 changes: 2 additions & 2 deletions ChessAndroid/app/src/main/cpp/chess/BoardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Stats.h"
#include "data/Board.h"
#include "algorithm/Hash.h"
#include "algorithm/NegaMax.h"
#include "algorithm/Search.h"
#include "algorithm/PieceAttacks.h"

Settings BoardManager::s_Settings(4u, std::thread::hardware_concurrency() - 1u, 100, true);
Expand Down Expand Up @@ -111,7 +111,7 @@ void BoardManager::moveComputerPlayer(const Settings &settings)
Stats::resetStats();
Stats::startTimer();

const RootMove bestMove = NegaMax::findBestMove(s_Board, settings);
const RootMove bestMove = Search::findBestMove(s_Board, settings);

Stats::stopTimer();
movePiece(bestMove.startSq, bestMove.destSq, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "NegaMax.h"
#include "Search.h"

#include <algorithm>
#include <atomic>
Expand All @@ -8,11 +8,11 @@
#include "../data/Board.h"
#include "../threads/NegaMaxThreadPool.h"

bool NegaMax::s_QuiescenceSearchEnabled{};
TranspositionTable NegaMax::s_SearchCache(1);
short NegaMax::s_BestMoveFound{};
bool Search::s_QuiescenceSearchEnabled{};
TranspositionTable Search::s_SearchCache(1);
short Search::s_BestMoveFound{};

RootMove NegaMax::findBestMove(const Board &board, const Settings &settings)
RootMove Search::findBestMove(const Board &board, const Settings &settings)
{
const auto validMoves = board.listValidMoves<RootMove>();
assert(!validMoves.empty());
Expand All @@ -37,12 +37,12 @@ RootMove NegaMax::findBestMove(const Board &board, const Settings &settings)
return negaMaxRoot(validMoves, std::min<unsigned>(threadCount, validMoves.size()), depth);
}

short NegaMax::getBestMoveFound()
short Search::getBestMoveFound()
{
return s_BestMoveFound;
}

RootMove NegaMax::negaMaxRoot(const std::vector<RootMove> &validMoves, const unsigned jobCount, const short ply)
RootMove Search::negaMaxRoot(const std::vector<RootMove> &validMoves, const unsigned jobCount, const short ply)
{
std::vector<ThreadPool::TaskFuture<void>> futures;
futures.reserve(jobCount);
Expand Down Expand Up @@ -91,12 +91,12 @@ RootMove NegaMax::negaMaxRoot(const std::vector<RootMove> &validMoves, const uns
for (auto &future : futures)
future.get(); // Wait for the Search to finish

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

return bestMove;
}

short NegaMax::negaMax(const Board &board, const short ply, short alpha, short beta, const short depth, const bool moveCountPruning)
short Search::negaMax(const Board &board, const short ply, short alpha, short beta, const short depth, const bool moveCountPruning)
{
if (board.state == State::DRAW)
return 0;
Expand Down Expand Up @@ -210,7 +210,7 @@ short NegaMax::negaMax(const Board &board, const short ply, short alpha, short b
return alpha;
}

short NegaMax::quiescence(const Board &board, short alpha, const short beta)
short Search::quiescence(const Board &board, short alpha, const short beta)
{
if (board.state == State::DRAW)
return 0;
Expand All @@ -225,8 +225,8 @@ short NegaMax::quiescence(const Board &board, short alpha, const short beta)
// Delta Pruning
if (board.getPhase() != Phase::ENDING) // Turn it off in the Endgame
{
constexpr short QUEEN_VALUE = 2529;
constexpr short PAWN_VALUE = 136;
constexpr short QUEEN_VALUE = 2538;
constexpr short PAWN_VALUE = 128;

short bigDelta = QUEEN_VALUE;
if (board.isPromotion)
Expand Down Expand Up @@ -257,7 +257,7 @@ short NegaMax::quiescence(const Board &board, short alpha, const short beta)
return alpha;
}

short NegaMax::negaScout(const Board &board, const short ply, short alpha, const short beta, const bool isWhite, const short depth)
short Search::negaScout(const Board &board, const short ply, short alpha, const short beta, const bool isWhite, const short depth)
{
if (board.state == State::DRAW)
return 0;
Expand Down Expand Up @@ -294,7 +294,7 @@ short NegaMax::negaScout(const Board &board, const short ply, short alpha, const
return bestScore;
}

inline short NegaMax::sideToMove(const Board &board)
inline short Search::sideToMove(const Board &board)
{
const short value = Evaluation::evaluate(board);
return board.colorToMove ? value : -value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class Board;
class RootMove;
class Settings;

class NegaMax final
class Search final
{
static bool s_QuiescenceSearchEnabled;
static TranspositionTable s_SearchCache;
static short s_BestMoveFound;

public:
NegaMax() = delete;
NegaMax(const NegaMax&) = delete;
NegaMax(NegaMax&&) = delete;
Search() = delete;
Search(const Search&) = delete;
Search(Search&&) = delete;

static RootMove findBestMove(const Board &board, const Settings &settings);
static short getBestMoveFound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_chess.*
import kotlinx.android.synthetic.main.dialog_restart.view.*
import net.theluckycoder.chess.utils.CapturedPieces
import net.theluckycoder.chess.utils.PieceResourceManager
import net.theluckycoder.chess.views.CustomView
import net.theluckycoder.chess.views.PieceView
import net.theluckycoder.chess.views.TileView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ data class Pos(
) {

constructor() : this(8, 8)
constructor(square: Byte) : this(square % 8, square / 8)

fun invertIf(invert: Boolean) = Pos(x, if (invert) 7 - y else y)
constructor(square: Byte) : this(square % 8, square / 8)

val isValid
get() = (x in 0..7 && y in 0..7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ class GameManager(
}

private external fun initBoardNative(restartGame: Boolean, isPlayerWhite: Boolean)
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package net.theluckycoder.chess
package net.theluckycoder.chess.utils

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.SparseArray
import net.theluckycoder.chess.R

object PieceResourceManager {

val piecesResources = arrayOf(
R.drawable.w_pawn, R.drawable.w_knight,
R.drawable.w_bishop, R.drawable.w_rook,
R.drawable.w_queen, R.drawable.w_king,
R.drawable.b_pawn, R.drawable.b_knight,
R.drawable.b_bishop, R.drawable.b_rook,
R.drawable.b_queen, R.drawable.b_king
R.drawable.w_pawn,
R.drawable.w_knight,
R.drawable.w_bishop,
R.drawable.w_rook,
R.drawable.w_queen,
R.drawable.w_king,
R.drawable.b_pawn,
R.drawable.b_knight,
R.drawable.b_bishop,
R.drawable.b_rook,
R.drawable.b_queen,
R.drawable.b_king
)

private val piecesBitmaps = SparseArray<Bitmap>(piecesResources.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.graphics.BlurMaskFilter
import android.graphics.Canvas
import android.graphics.Paint
import net.theluckycoder.chess.ChessActivity
import net.theluckycoder.chess.PieceResourceManager
import net.theluckycoder.chess.utils.PieceResourceManager
import net.theluckycoder.chess.Pos

@SuppressLint("ViewConstructor")
Expand Down