Skip to content

Commit

Permalink
Next() implementation and MVV-LVA
Browse files Browse the repository at this point in the history
  • Loading branch information
quesswho committed Nov 9, 2024
1 parent 5cede19 commit b7bbd27
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 10 deletions.
3 changes: 3 additions & 0 deletions milesChess.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<LanguageStandard>stdcpp20</LanguageStandard>
<AssemblerOutput>AssemblyCode</AssemblerOutput>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='RelDebug|x64'">
<ClCompile>
<LanguageStandard>stdcpp20</LanguageStandard>
<AssemblerOutput>AssemblyCode</AssemblerOutput>
</ClCompile>
<Link>
<OptimizeReferences>true</OptimizeReferences>
Expand All @@ -171,6 +173,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\MoveGen.cpp" />
<ClCompile Include="src\Position.cpp" />
<ClCompile Include="src\TableBase.cpp" />
<ClCompile Include="src\UCI.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions milesChess.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<ClCompile Include="src\Position.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\MoveGen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\LookupTables.h">
Expand Down
14 changes: 12 additions & 2 deletions src/Move.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ enum ColoredPieceType : uint8 {
};


static inline constexpr ushort OrderingPieceValue(ColoredPieceType piece) {
constexpr ushort piece_values[13] = {
0, 100, 300, 350, 500, 1100, 10000,
100, 300, 350, 500, 1100, 10000,
};
return piece_values[piece];
}

template<Color c>
static inline constexpr ColoredPieceType GetColoredPiece(PieceType T) {
static inline constexpr ColoredPieceType GetColoredPiece(PieceType type) {
constexpr ColoredPieceType pieceMap[2][7] = {
{ NOPIECE, BPAWN, BKNIGHT, BBISHOP, BROOK, BQUEEN, BKING },
{ NOPIECE, WPAWN, WKNIGHT, WBISHOP, WROOK, WQUEEN, WKING }
};
return pieceMap[c][T];
return pieceMap[c][type];
}

//static inline constexpr GetPieceType(ColoredPieceType )

// Move:
// from: 6 bits
// to: 6 bits
Expand Down
56 changes: 56 additions & 0 deletions src/MoveGen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "MoveGen.h"


MoveGen::MoveGen(Position& position, Move hashmove)
: m_Position(position), m_HashMove(hashmove), m_Current(&m_Moves[0]), m_End(&m_Moves[0])
{}

static bool movecomp(const ScoreMove& a, const ScoreMove& b) {
return a.score > b.score;
}

Move MoveGen::Next() {
while (true) {
switch (m_Stage) {
case TT_MOVE:
case QUIESCENCE_TT:
m_Stage++;
// TODO: Check if hashmove is legal
if (m_HashMove != 0) return m_HashMove;
break;
case CAPTURE_INIT:
GenerateMoves<QUIESCENCE>();
// sort
if(m_Current != m_End) std::sort(m_Current, m_End - 1, movecomp);
m_Stage++;
case CAPTURE_MOVE:
if (m_Current->move == m_HashMove) m_Current++;
if (m_Current != m_End) {
return (*(m_Current++)).move;
}
m_Stage++;
case QUIET_INIT:
GenerateMoves<SILENT>();
// sort
if (m_Current != m_End) std::sort(m_Current, m_End - 1, movecomp);
m_Stage++;
case QUIET_MOVE:
if (m_Current->move == m_HashMove) m_Current++;
if (m_Current != m_End) {
return (*(m_Current++)).move;
}
return 0; // Finished
case QUIESCENCE_INIT:
GenerateMoves<QUIESCENCE>();
// sort
if (m_Current != m_End) std::sort(m_Current, m_End - 1, movecomp);
m_Stage++;
case QUIESCENCE_MOVE:
if (m_Current->move == m_HashMove) m_Current++;
if (m_Current != m_End) {
return (*(m_Current++)).move;
}
return 0; // Finished
}
}
}
Loading

0 comments on commit b7bbd27

Please sign in to comment.