Skip to content

Commit

Permalink
Merge v2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jakhac committed Feb 18, 2021
2 parents d55d427 + 2550d2c commit a551cd0
Show file tree
Hide file tree
Showing 24 changed files with 695 additions and 9,480 deletions.
3 changes: 3 additions & 0 deletions GoogleTest/GoogleTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="testZugzwang.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\chAI\chAI.vcxproj">
Expand Down Expand Up @@ -89,6 +90,8 @@
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<LanguageStandard>Default</LanguageStandard>
<SupportJustMyCode>false</SupportJustMyCode>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down
48 changes: 37 additions & 11 deletions GoogleTest/testSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace {
};

// Mating positions
TEST_F(SearchTest, MateIn5) {
pBoard->parseFen("2rnqb2/1b1n1Nk1/p2PB1Pp/1p6/4Q3/8/PP4PP/R4RK1 w - - 1 0");
TEST_F(SearchTest, MateIn5_1) {
pBoard->parseFen("r7/3bb1kp/q4p1N/1pnPp1np/2p4Q/2P5/1PB3P1/2B2RK1 w - - 1 0");
pSearch->depth = 5;
pSearch->depthSet = true;
pSearch->timeSet = false;
Expand All @@ -33,29 +33,55 @@ namespace {
}

// Mating positions
TEST_F(SearchTest, MateIn4_1) {
pBoard->parseFen("r7/3bb1kp/q4p1N/1pnPp1np/2p4Q/2P5/1PB3P1/2B2RK1 w - - 1 0");
pSearch->depth = 4;
TEST_F(SearchTest, MateIn5_2) {
pBoard->parseFen("rnb1Qb1r/pq3Bpp/4p3/B2n4/3P2kP/4P3/1P3PP1/R3K2R w KQ - 1 0");
pSearch->depth = 5;
pSearch->depthSet = true;
pSearch->timeSet = false;

EXPECT_GE(search(pBoard, pSearch), ISMATE);
}

// Mating positions
TEST_F(SearchTest, MateIn4_2) {
pBoard->parseFen("rnb1Qb1r/pq3Bpp/4p3/B2n4/3P2kP/4P3/1P3PP1/R3K2R w KQ - 1 0");
pSearch->depth = 4;
TEST_F(SearchTest, MateIn7_1) {
pBoard->parseFen("7k/2rR3p/1Pp1qp1B/p1p3p1/P3P3/7P/5PP1/6K1 w - - 1 0");
pSearch->depth = 7;
pSearch->depthSet = true;
pSearch->timeSet = false;

EXPECT_GE(search(pBoard, pSearch), ISMATE);
}

// Mating positions
TEST_F(SearchTest, MateIn7) {
pBoard->parseFen("7k/2rR3p/1Pp1qp1B/p1p3p1/P3P3/7P/5PP1/6K1 w - - 1 0");
pSearch->depth = 7;
pBoard->parseFen("2rnqb2/1b1n1Nk1/p2PB1Pp/1p6/4Q3/8/PP4PP/R4RK1 w - - 1 0");
pSearch->depth = 4; // forced mate found in quiescence
pSearch->depthSet = true;
pSearch->timeSet = false;

EXPECT_GE(search(pBoard, pSearch), ISMATE);
}

TEST_F(SearchTest, Fisher_4) {
pBoard->parseFen("5r2/2Q4p/3P2p1/1k3p2/qp5P/2r2P2/2P3P1/1K1RR3 w - - 1 0");
pSearch->depth = 4;
pSearch->depthSet = true;
pSearch->timeSet = false;

EXPECT_GE(search(pBoard, pSearch), ISMATE);
}

TEST_F(SearchTest, Fisher_3) {
pBoard->parseFen("3r1k2/1q1P4/5b2/p3p2p/1p6/1B3P2/PPPQ4/1K1R4 w - - 1 0");
pSearch->depth = 3;
pSearch->depthSet = true;
pSearch->timeSet = false;

EXPECT_GE(search(pBoard, pSearch), ISMATE);
}

TEST_F(SearchTest, Fisher_5) {
pBoard->parseFen("1r4r1/q2b1p1k/p4P1p/1pn1P1p1/3N4/5B2/PPP2R1Q/4R1K1 w - - 1 0");
pSearch->depth = 5;
pSearch->depthSet = true;
pSearch->timeSet = false;

Expand Down
83 changes: 83 additions & 0 deletions GoogleTest/testZugzwang.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "pch.h"
#include "search.h"

namespace {
class Zugzwang : public ::testing::Test {

protected:
Board* pBoard;

virtual void SetUp() {
pBoard = new Board();
pBoard->initHashKeys();

initClearSetMask();
initSquareToRankFile();
initAttackerMasks();

initRookMasks();
initRookMagicTable();
initBishopMasks();
initBishopMagicTable();

initObstructed();
initLine();
}

virtual void TearDown() {
delete pBoard;
}

};

TEST_F(Zugzwang, KingVSKing) {
pBoard->parseFen("2k5/8/8/8/8/8/8/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 1);
}

TEST_F(Zugzwang, NoPawns) {
pBoard->parseFen("2k1n3/8/1q1r1r2/1R6/B7/R7/4N3/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 1);
}

TEST_F(Zugzwang, PawnOnly) {
pBoard->parseFen("2k5/8/1p1ppp2/pP6/8/P4P2/4P3/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 1);
}

TEST_F(Zugzwang, PawnKnight1) {
pBoard->parseFen("2k5/5n2/1p1ppp2/pP1N4/8/P4P2/4PN2/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 1);
}

TEST_F(Zugzwang, PawnKnight2) {
pBoard->parseFen("2k5/5n2/1p1ppp2/pP1N4/8/P4P2/4PN2/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 1);
}

TEST_F(Zugzwang, PawnBlocks1) {
pBoard->parseFen("2k5/5n2/1p1p4/pP6/5Q2/1P2RP2/4PN2/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 1);
}

TEST_F(Zugzwang, PawnPushPossible1) {
pBoard->parseFen("2k5/5n2/1p1p4/pP1N4/5Q2/1P3P2/4PN2/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 0);
}

TEST_F(Zugzwang, PawnPushPossible2) {
pBoard->parseFen("2k5/5n2/1p1p4/pP1N4/P4Q2/2P2P2/4PN2/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 0);
}

TEST_F(Zugzwang, NoPawnPushPossible) {
pBoard->parseFen("2k5/5n2/1p1p4/pP1N4/P4Q2/2P2P2/4PN2/2K5 b - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 1);
}

TEST_F(Zugzwang, ValidPos1) {
pBoard->parseFen("2k5/5n2/1p1ppp2/pP1N4/5Q2/P4P2/4PN2/2K5 w - - 0 1");
EXPECT_EQ(zugzwang(pBoard), 0);
}

} // namespace zw test
42 changes: 42 additions & 0 deletions chai/assertLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,45 @@ At Sat Jan 16 00:52:06 2021
At Sat Jan 16 00:52:48 2021
Error in:F:\SmartGit-Repositories\chai\chai\search.cpp at line 516

At Sat Jan 30 23:23:22 2021
Error in:F:\SmartGit-Repositories\chai\chai\search.cpp at line 197

At Sat Jan 30 23:25:22 2021
Error in:F:\SmartGit-Repositories\chai\chai\search.cpp at line 203

At Mon Feb 1 00:55:56 2021
Error in:F:\SmartGit-Repositories\chai\chai\tt.cpp at line 29

At Mon Feb 1 00:56:26 2021
Error in:F:\SmartGit-Repositories\chai\chai\tt.cpp at line 29

At Mon Feb 1 01:10:32 2021
Error in:F:\SmartGit-Repositories\chai\chai\tt.cpp at line 84

At Sat Feb 6 22:11:36 2021
Error in:F:\SmartGit-Repositories\chai\chai\board.cpp at line 568

At Sat Feb 6 22:37:26 2021
Error in:F:\SmartGit-Repositories\chai\chai\tt.cpp at line 135

At Sun Feb 7 00:55:53 2021
Error in:F:\SmartGit-Repositories\chai\chai\moveOrdering.cpp at line 148

At Sun Feb 7 00:57:00 2021
Error in:F:\SmartGit-Repositories\chai\chai\moveOrdering.cpp at line 153

At Sun Feb 7 00:57:36 2021
Error in:F:\SmartGit-Repositories\chai\chai\moveOrdering.cpp at line 154

At Sun Feb 7 00:58:10 2021
Error in:F:\SmartGit-Repositories\chai\chai\moveOrdering.cpp at line 156

At Sun Feb 7 01:01:01 2021
Error in:F:\SmartGit-Repositories\chai\chai\moveOrdering.cpp at line 156

At Sun Feb 7 01:03:01 2021
Error in:F:\SmartGit-Repositories\chai\chai\moveOrdering.cpp at line 157

At Sun Feb 7 01:03:53 2021
Error in:F:\SmartGit-Repositories\chai\chai\moveOrdering.cpp at line 158

18 changes: 9 additions & 9 deletions chai/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,12 @@ void Board::pushCastle(int clearRookSq, int setRookSq, int side) {
void Board::pushNull() {
Assert(!isCheck(side));

undo_t undo_s[1]{};
undo_s->enPas = enPas;
undo_s->castle = castlePermission;
undo_s->zobKey = zobristKey;
undo_s->pawnKey = zobristPawnKey;
undo_s->move = NULL_MOVE;
undo_t undo_s{};
undo_s.enPas = enPas;
undo_s.castle = castlePermission;
undo_s.zobKey = zobristKey;
undo_s.pawnKey = zobristPawnKey;
undo_s.move = NULL_MOVE;

zobristKey ^= pieceKeys[EMPTY][enPas]; // ep out
enPas = 0;
Expand All @@ -587,8 +587,8 @@ void Board::pushNull() {

// update gameState variable and store in undo struct

undo_s->fiftyMove = fiftyMove;
undoHistory[undoPly] = *undo_s;
undo_s.fiftyMove = fiftyMove;
undoHistory[undoPly] = undo_s;

fiftyMove++; // might cause negative ply in isRepetition() check
halfMoves++;
Expand Down Expand Up @@ -626,7 +626,7 @@ undo_t Board::pop() {
enPas = undo.enPas;

// trivial case for null moves
if (undo.move == -1) {
if (undo.move == NULL_MOVE) {
Assert(ply >= 0);
return undo;
}
Expand Down
6 changes: 3 additions & 3 deletions chai/chAI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp14</LanguageStandard>
<LanguageStandard>Default</LanguageStandard>
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>false</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
Expand Down
27 changes: 17 additions & 10 deletions chai/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ using namespace std;
#include "move.h"
#include "types.h"

#define VERSION "v2.2"

#define VERSION "v2.3.2"

//#define TESTING
//#define ASSERT
Expand All @@ -38,6 +37,21 @@ inline void logDebug(string logMsg, string file, string line) {
ofs.close();
}

inline void logDebug(string logMsg) {
time_t now = time(0);
tm gmtm[1];
char buffer[26];

gmtime_s(gmtm, &now);
asctime_s(buffer, gmtm);

ofstream ofs("iid.txt", std::ios_base::app | std::ios_base::app);

string streamMsg = "At " + string(buffer) + logMsg + "\n\n";
ofs << streamMsg;
ofs.close();
}

#ifndef ASSERT
#define Assert(n)
#else
Expand All @@ -59,18 +73,11 @@ const int MAX_POSITION_MOVES = 256;
const int MAX_DEPTH = 64;
const int NO_SCORE = 10000000;
const int NO_MOVE = 0;
const int NULL_MOVE = 129; // B1-B1 used as nullmove (impossible move, never generated)

const int INF = 30000;
const int MATE = 29000;
const int ISMATE = MATE - MAX_DEPTH;
const int R_NULL = 2;

constexpr auto NULL_MOVE = -1;

const bool IS_PV = true;
const bool NO_PV = false;
const bool DO_NULL = true;
const bool NO_NULL = false;

const bitboard_t RANK_1_HEX = 0xFF;
const bitboard_t RANK_2_HEX = 0xFF00;
Expand Down
Loading

0 comments on commit a551cd0

Please sign in to comment.