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
Revert to the old Pawn PSQT
  • Loading branch information
razvanfilea committed Dec 8, 2019
commit d5d5ae0fb5e24703ab4aac970856f35cc0e560ff
49 changes: 20 additions & 29 deletions ChessAndroid/app/src/main/cpp/chess/algorithm/Evaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#define S Score

constexpr short TEMPO_BONUS = 20;
constexpr S CHECK_BONUS{ 30, 42 };

/*
* These values were imported from the Stockfish Chess Engine
*/
Expand Down Expand Up @@ -70,14 +73,16 @@ short Evaluation::simpleEvaluation(const Board &board) noexcept
if (board.state == State::WINNER_BLACK)
return VALUE_WINNER_BLACK;

short score[2]{};
Score score[2]{};
for (byte i = 0; i < 64u; i++)
{
const Piece &piece = board.getPiece(i);
score[piece.isWhite] += Psqt::s_Bonus[piece.type][i].mg;
score[piece.isWhite] += Psqt::s_Bonus[piece.type][i];
}

return score[WHITE] - score[BLACK];
const Phase phase = board.getPhase();
const Score finalScore = score[WHITE] - score[BLACK];
return phase == Phase::MIDDLE ? finalScore.mg : finalScore.eg;
}

short Evaluation::evaluate(const Board &board) noexcept
Expand All @@ -91,12 +96,10 @@ short Evaluation::evaluate(const Board &board) noexcept

Stats::incrementBoardsEvaluated();

Score totalScore;

Score totalScore[2]{};
byte pawnCount[2]{};
byte bishopCount[2]{};
short whiteNpm = 0;
short blackNpm = 0;
short npm[2]{};

const AttacksMap whiteMoves = Player::getAttacksPerColor(true, board);
const AttacksMap blackMoves = Player::getAttacksPerColor(false, board);
Expand Down Expand Up @@ -132,20 +135,15 @@ short Evaluation::evaluate(const Board &board) noexcept
if (theirAttacks[!isWhite][ROOK] & bb)
points -= ROOK_THREATS[piece.type];

if (isWhite) {
whiteNpm += getPieceValue(piece.type);
totalScore += points;
} else {
blackNpm += getPieceValue(piece.type);
totalScore -= points;
}
npm[piece.isWhite] += getPieceValue(piece.type);
totalScore[piece.isWhite] += points;
}

// 2 Bishops receive a bonus
if (bishopCount[WHITE] >= 2)
totalScore += 10;
totalScore[WHITE] += 10;
if (bishopCount[BLACK] >= 2)
totalScore -= 10;
totalScore[BLACK] += 10;

for (byte i = 0; i < 64u; i++)
if (const Piece &piece = board.getPiece(i); piece)
Expand All @@ -171,26 +169,19 @@ short Evaluation::evaluate(const Board &board) noexcept
}
}();

if (piece.isWhite) totalScore += points; else totalScore -= points;
totalScore[piece.isWhite] += points;
}

if (board.state == State::BLACK_IN_CHECK)
{
totalScore.mg += 30;
totalScore.eg += 40;
}
totalScore[WHITE] += CHECK_BONUS;
else if (board.state == State::WHITE_IN_CHECK)
{
totalScore.mg -= 30;
totalScore.eg -= 40;
}
totalScore[BLACK] += CHECK_BONUS;

// Tempo
const int tempo = board.colorToMove ? 20 : -20;
totalScore += tempo;
totalScore[board.colorToMove] += TEMPO_BONUS;

const Score finalScore = totalScore[WHITE] - totalScore[BLACK];
const Phase phase = board.getPhase();
return phase == Phase::MIDDLE ? totalScore.mg : totalScore.eg;
return phase == Phase::MIDDLE ? finalScore.mg : finalScore.eg;
}

Score Evaluation::evaluatePawn(const Piece &piece, const byte square, const Board &board,
Expand Down
5 changes: 2 additions & 3 deletions ChessAndroid/app/src/main/cpp/chess/algorithm/Evaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Board;

class Evaluation final
{
constexpr static short PIECE_VALUE[] = { 0, 136, 782, 830, 1289, 2529, 0 };
constexpr static short PIECE_VALUE[] = { 0, 128, 781, 825, 1276, 2538, 0 };

public:
Evaluation() = delete;
Expand All @@ -29,6 +29,5 @@ class Evaluation final
static Score evaluateBishop(const Piece &piece, byte square, const Board &board) noexcept;
static Score evaluateRook(const Piece &piece, byte square, const Board &board) noexcept;
static Score evaluateQueen(const Piece &piece, const byte square, const Board &board) noexcept;
inline static Score
evaluateKing(const Piece &piece, const byte square, const Board &board) noexcept;
inline static Score evaluateKing(const Piece &piece, const byte square, const Board &board) noexcept;
};
1 change: 0 additions & 1 deletion ChessAndroid/app/src/main/cpp/chess/algorithm/Hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <random>

#include "../data/Pos.h"
#include "../data/Board.h"

Hash::HashArray Hash::s_Pieces{};
Expand Down
15 changes: 8 additions & 7 deletions ChessAndroid/app/src/main/cpp/chess/data/Psqt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ constexpr static S QUEEN_SCORE(2538, 2682);

constexpr static S PAWN_SQUARE[][8] = {
{ },
{ S( 3, -10), S( 3, -6), S( 10, 10), S( 19, 0), S(16, 14), S( 19, 7), S( 7, -5), S( -5, -19) },
{ S(-9, -10), S(-15, -10), S( 11, -10), S( 15, 4), S(32, 4), S( 22, 3), S( 5, -6), S(-22, -4) },
{ S(-8, 6), S(-23, -2), S( 6, -8), S( 20, -4), S(40, -13), S( 17, -12), S( 4, -10), S(-12, -9) },
{ S(13, 9), S( 0, 4), S(-13, 3), S( 1, -12), S(11, -12), S( -2, -6), S(-13, 13), S( 5, 8) },
{ S(-5, 28), S(-12, 20), S( -7, 21), S( 22, 28), S(-8, 30), S( -5, 7), S(-15, 6), S(-18, 13) },
{ S(-7, 0), S( 7, -11), S( -3, 12), S(-13, 21), S( 5, 25), S(-16, 19), S( 10, 4), S( -8, 7) }
{ S(-11, -3), S( 7, -1), S( 7, 7), S(17, 2) },
{ S(-16, -2), S( -3, 2), S( 23, 6), S(23, -1) },
{ S(-14, 7), S( -7, -4), S( 20, -8), S(24, 2) },
{ S( -5, 13), S( -2, 10), S( -1, -1), S(12, -8) },
{ S(-11, 16), S(-12, 6), S( -2, 1), S( 4, 16) },
{ S( -2, 1), S( 20, -12), S(-10, 6), S(-2, 25) },
{ }
};

constexpr static S KNIGHT_SQUARE[][4] = {
Expand Down Expand Up @@ -89,7 +90,7 @@ const Psqt::ScoreArray Psqt::s_Bonus = [] {
const byte y = row(i);
const byte queen_side_y = std::min<byte>(y, 7u - y);

bonuses[PAWN][i] = PAWN_SCORE + PAWN_SQUARE[x][y];
bonuses[PAWN][i] = PAWN_SCORE + PAWN_SQUARE[x][queen_side_y];
bonuses[KNIGHT][i] = KNIGHT_SCORE + KNIGHT_SQUARE[x][queen_side_y];
bonuses[BISHOP][i] = BISHOP_SCORE + BISHOP_SQUARE[x][queen_side_y];
bonuses[ROOK][i] = ROOK_SCORE + ROOK_SQUARE[x][queen_side_y];
Expand Down
2 changes: 1 addition & 1 deletion ChessAndroid/app/src/main/cpp/chess/data/Score.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Score final
{
public:
short mg = 0, eg = 0;
short mg{}, eg{};

Score() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Intent
import android.graphics.Point
import android.os.Bundle
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.FrameLayout
import android.widget.RelativeLayout
import androidx.appcompat.app.AlertDialog
Expand Down Expand Up @@ -68,7 +69,7 @@ class ChessActivity : AppCompatActivity(), CustomView.ClickListener, GameManager
AlertDialog.Builder(this)
.setTitle(R.string.new_game)
.setView(view)
.setPositiveButton(R.string.action_restart) { _, _ ->
.setPositiveButton(R.string.action_start) { _, _ ->
val playerWhite = when (view.sp_side.selectedItemPosition) {
0 -> true
1 -> false
Expand Down Expand Up @@ -244,7 +245,7 @@ class ChessActivity : AppCompatActivity(), CustomView.ClickListener, GameManager
val pos = Pos(i % 8, i / 8)
val isWhite = (pos.x + pos.y) % 2 == 1

val xSize = pos.x * viewSize
val xSize = invertIf(!isPlayerWhite, pos.x) * viewSize
val ySize = invertIf(isPlayerWhite, pos.y) * viewSize

val tileView = TileView(this, isWhite, pos, this).apply {
Expand All @@ -271,7 +272,7 @@ class ChessActivity : AppCompatActivity(), CustomView.ClickListener, GameManager

val pos = Pos(it.x, it.y)

val xSize = pos.x * viewSize
val xSize = invertIf(!isPlayerWhite, pos.x) * viewSize
val ySize = invertIf(isPlayerWhite, pos.y) * viewSize

val pieceView = PieceView(this, clickable, resource, pos, this).apply {
Expand All @@ -298,13 +299,14 @@ class ChessActivity : AppCompatActivity(), CustomView.ClickListener, GameManager
it.pos = destPos

// Calculate the new View Position
val xPos = destPos.x * viewSize
val xPos = invertIf(!isPlayerWhite, destPos.x) * viewSize
val yPos = invertIf(isPlayerWhite, destPos.y) * viewSize

it.animate()
.x(xPos.toFloat())
.y(yPos.toFloat())
.setDuration(250L)
.setInterpolator(AccelerateDecelerateInterpolator())
.start()
}

Expand All @@ -313,8 +315,11 @@ class ChessActivity : AppCompatActivity(), CustomView.ClickListener, GameManager
layout_board.removeView(destView)

val type = PieceResourceManager.piecesResources.indexOf(destView.res) + 1
val piece =
Piece(destView.pos.x, invertIf(isPlayerWhite, destView.pos.y), type.toByte())
val piece = Piece(
invertIf(!isPlayerWhite, destView.pos.x),
invertIf(isPlayerWhite, destView.pos.y),
type.toByte()
)

if (isPlayerWhite)
capturedPieces.addBlackPiece(piece)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GameManager(

fun initBoard(restartGame: Boolean, playerWhite: Boolean = true) {
initBoardNative(restartGame, playerWhite)
Native.enableStats(advancedStatsEnabled)

if (initialized) {
if (isPlayerWhite != playerWhite) {
Expand Down
2 changes: 1 addition & 1 deletion ChessAndroid/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="tile_white">#eeeed2</color>
<color name="tile_black">#769656</color>
<color name="tile_black">#769655</color>
<color name="tile_selected">#ef4fc3f7</color>
<color name="tile_possible">#CC32BF37</color>
<color name="tile_last_moved">#8CFBC02D</color>
Expand Down
2 changes: 1 addition & 1 deletion ChessAndroid/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<string name="basic_stats">Time Needed: %.3f millis\nCurrent Board is evaluated at: %d\nBest Move Found: %d%s</string>
<string name="new_game">New Game</string>
<string name="side">Side:</string>
<string name="action_restart">Restart</string>
<string name="action_start">Start</string>
<string name="settings">Settings</string>
<string name="undo_move">Undo Move</string>

Expand Down
2 changes: 1 addition & 1 deletion ChessAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down