Commit 56b57ad8 authored by Loic Guegan's avatar Loic Guegan
Browse files

Integrate Move

parent acc78d6f
Pipeline #212668847 passed with stage
in 7 minutes and 12 seconds
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1447333956">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1447333956" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.1447333956" name="Default" optionalBuildProperties="" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1447333956.1739164414" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1472490621" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.633179379" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
<builder id="cdt.managedbuild.target.gnu.builder.base.1852103043" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.2071933852" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.473363231" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.2006386595" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="/home/loic/.local/usr/includes"/>
<listOptionValue builtIn="false" value="/home/loic/.local/usr/includes/gtk3-unicode-3.1"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1650509116" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.607229652" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1981959396" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1669386060" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1434525111" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.774148248" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1771600560" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="gnu.both.asm.option.include.paths.1365612002" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"/>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1425461887" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="ochess.null.398029181" name="ochess"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.827961589;cdt.managedbuild.toolchain.gnu.base.827961589.1528480849;cdt.managedbuild.tool.gnu.cpp.compiler.base.1773955433;cdt.managedbuild.tool.gnu.cpp.compiler.input.1542726464">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.1447333956;cdt.managedbuild.toolchain.gnu.base.1447333956.1739164414;cdt.managedbuild.tool.gnu.cpp.compiler.base.473363231;cdt.managedbuild.tool.gnu.cpp.compiler.input.1650509116">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.1447333956;cdt.managedbuild.toolchain.gnu.base.1447333956.1739164414;cdt.managedbuild.tool.gnu.c.compiler.base.607229652;cdt.managedbuild.tool.gnu.c.compiler.input.1981959396">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.827961589;cdt.managedbuild.toolchain.gnu.base.827961589.1528480849;cdt.managedbuild.tool.gnu.c.compiler.base.1592407247;cdt.managedbuild.tool.gnu.c.compiler.input.1482536630">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/ochess"/>
</configuration>
</storageModule>
</cproject>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/usr/bin/cmake"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="../"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/ochess}/build"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/usr/bin/make"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-j4"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/ochess}/build"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.eclipse.cdt.managedbuilder.core.genmakebuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ochess</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/CMake.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/Make.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.genmakebuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<filteredResources>
<filter>
<id>1604656593578</id>
<name></name>
<type>10</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-build</arguments>
</matcher>
</filter>
<filter>
<id>1604656593580</id>
<name></name>
<type>10</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-assets</arguments>
</matcher>
</filter>
<filter>
<id>1604656593582</id>
<name></name>
<type>10</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-icons</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.toolchain.gnu.base.1447333956" name="Default">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-692070016846007064" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension>
</configuration>
</project>
\ No newline at end of file
......@@ -26,11 +26,10 @@ void BoardController::Move(Coord src, Coord dst) {
<< "Engine is thinking...";
while (!BlackEngine->IsBestMoveFound()) {
}
model::Move m;
m.FromLA(BlackEngine->GetBestMove());
model::Move m=Move::FromLA(BlackEngine->GetBestMove());
G.Move(m.Src, m.Dst);
if (m.IsPromoting)
G.Promote(m.Promote);
if (m.isPromotion)
G.Promote(m.promoteTo);
}
}
}
......
#include "History.hpp"
namespace ochess {
namespace model {
namespace ochess
{
namespace model
{
History::History(std::string FEN) :
SavedState(NULL) {
InitialState.FEN = FEN;
CurrentState = &InitialState;
}
bool History::Next(Board<PPiece> *board, FenState *state) {
if (CurrentState->NextStates.size() > 0) {
CurrentState = CurrentState->NextStates.front();
Fen f(CurrentState->FEN);
f.BuildBoard(board);
*state = f.GetState();
return (true);
}
return (false);
}
History::History(std::string FEN) : SavedState(NULL)
{
InitialState.FEN = FEN;
CurrentState = &InitialState;
}
bool History::Next(Board<PPiece> *board, FenState *state)
{
if (!CurrentState->IsLeaf())
{
CurrentState = CurrentState->main;
Fen f(CurrentState->FEN);
f.BuildBoard(board);
*state = f.GetState();
return (true);
}
return (false);
}
bool History::Next() {
if (CurrentState->NextStates.size() > 0) {
CurrentState = CurrentState->NextStates.front();
return (true);
}
return (false);
}
bool History::Next()
{
if (!CurrentState->IsLeaf())
{
CurrentState = CurrentState->main;
return (true);
}
return (false);
}
void History::SaveState() {
SavedState = CurrentState;
}
void History::SaveState()
{
SavedState = CurrentState;
}
void History::RestoreState() {
if (SavedState != NULL)
CurrentState = SavedState;
}
void History::RestoreState()
{
if (SavedState != NULL)
CurrentState = SavedState;
}
bool History::Previous(Board<PPiece> *board, FenState *state) {
if (CurrentState->ParentState != NULL) {
CurrentState = CurrentState->ParentState;
Fen f(CurrentState->FEN);
f.BuildBoard(board);
*state = f.GetState();
return (true);
}
return (false);
}
bool History::Previous(Board<PPiece> *board, FenState *state)
{
if (CurrentState->parent != nullptr)
{
CurrentState = CurrentState->parent;
Fen f(CurrentState->FEN);
f.BuildBoard(board);
*state = f.GetState();
return (true);
}
return (false);
}
bool History::Previous() {
if (CurrentState->ParentState != NULL) {
CurrentState = CurrentState->ParentState;
return (true);
}
return (false);
}
bool History::Previous()
{
if (CurrentState->parent != nullptr)
{
CurrentState = CurrentState->parent;
return (true);
}
return (false);
}
void History::New(Board<PPiece> *board, FenState *state) {
GameState *newState = new GameState;
Fen f(board, *state);
newState->FEN = f.GetFen();
newState->ParentState = CurrentState;
CurrentState->NextStates.push_back(newState);
CurrentState = newState;
}
void History::New(Board<PPiece> *board, FenState *state)
{
Move *newState = new Move;
Fen f(board, *state);
newState->FEN = f.GetFen();
newState->parent = CurrentState;
CurrentState->expand(newState);
CurrentState = newState;
}
void History::Erase(Board<PPiece> *board, FenState *state) {
if (CurrentState != &InitialState) {
GameState *toErase = CurrentState;
Previous(board, state);
CurrentState->NextStates.erase(
std::remove(CurrentState->NextStates.begin(),
CurrentState->NextStates.end(), toErase));
Delete(toErase);
}
}
void History::Erase(Board<PPiece> *board, FenState *state)
{
if (CurrentState != &InitialState)
{
Move *toErase = CurrentState;
Previous(board, state);
if (CurrentState->main == toErase)
CurrentState->main=nullptr;
else
CurrentState->variations.erase(
std::remove(CurrentState->variations.begin(),
CurrentState->variations.end(), toErase));
SyncSavedState(toErase);
delete toErase;
}
}
void History::Delete(GameState *state) {
if (state == SavedState)
SavedState = NULL;
for (auto &cur_state : state->NextStates)
Delete(cur_state);
delete state;
}
void History::SyncSavedState(Move *state)
{
if (state == SavedState || state->main == SavedState)
SavedState = NULL;
for (auto &cur_state : state->variations)
SyncSavedState(cur_state);
}
} // namespace model
} // namespace model
} // namespace ochess
......@@ -2,6 +2,7 @@
#define HISTORY_HPP
#include "model/Fen.hpp"
#include "model/Move.hpp"
namespace ochess {
namespace model {
......@@ -9,7 +10,7 @@ namespace model {
/**
* @brief Node data structure of the game history tree.
*/
typedef struct GameState {
/* typedef struct GameState {
/// @brief Current node fen
std::string FEN;
/// @brief Parent node state
......@@ -17,7 +18,7 @@ typedef struct GameState {
/// @brief Current node child
std::vector<GameState*> NextStates;
} GameState;
*/
/**
* @class History
* @brief Very nice class to keep track of each move line in the game.
......@@ -26,17 +27,17 @@ class History {
private:
/// @brief Initial game state
GameState InitialState;
Move InitialState;
/// @brief Actual game state
GameState *CurrentState;
Move *CurrentState;
/// @brief Temporary saved state (to simplify tree navigation)
GameState *SavedState;
Move *SavedState;
/**
* @brief Delete a state and all his descendants
* @param state The state to delete.
*/
void Delete(GameState *state);
void SyncSavedState(Move *state);
public:
/**
......
#include "../model/Move.hpp"
namespace ochess {
namespace model {
namespace ochess
{
namespace model
{
Move::Move(): Promote(' '), IsPromoting(false){
void Move::freeMove(Move *m)
{
if (m->main == nullptr && m->variations.size() == 0)
delete (m);
if (m->main != nullptr)
freeMove(m->main);
for (auto v : m->variations)
freeMove(v);
}
}
Move::Move() : parent(nullptr), main(nullptr), isCheck(false), isPromotion(false),
isCheckMate(false), isPawn(false),
isCapture(false), isLongCastle(false), isShortCastle(false), promoteTo('?'), col('?'),
clk{0}, egt{0}, emt{0}, mct{0} {}
void Move::dump()
{
cout << "isCheck:" << isCheck << " isPromotion:" << isPromotion << " isCheckMate:" << isCheckMate << " isPawn:" << isPawn << " isCapture:" << isCapture << " isLongCastle:" << isLongCastle << " isShortCastle:" << isShortCastle << " dst:" << dst << " promoteTo:" << promoteTo << " col:" << col << " clk:" << clk[0] << ":" << clk[1] << ":" << clk[2];
}
void Move::FromLA(std::string move) {
Src = move.substr(0, 2);
Dst = move.substr(2, 2);
Promote=' ';
if (move.size() == 5){
IsPromoting=true;
Promote = move[4];
}
}
Move::~Move()
{
if (this->main != nullptr)
freeMove(this->main);
for (auto v : this->variations)
freeMove(v);
}
}
}
Move Move::FromLA(string move)
{
Move m;
m.Src = move.substr(0, 2);
m.Dst = move.substr(2, 2);
m.promoteTo = ' ';
if (move.size() == 5)
{
m.isPromotion = true;
m.promoteTo = move[4];
}
return (m);
}
bool Move::IsLeaf()
{
return (this->main == nullptr && this->variations.size() == 0);
}
void Move::expand(Move *m)
{
if(this->main==nullptr)
this->main=m;
else
this->variations.push_back(m);
}
} // namespace model
} // namespace ochess
......@@ -2,45 +2,73 @@
#define MOVE_HPP
#include <string>
#include <iostream>
#include "Coord.hpp"
namespace ochess {
namespace model {
/**
* @class Move
* @brief Represents a chess move.
*
* This class allow also to "unpack" the a move from a string
* (chess algebraic notation string etc..).
*
*/
class Move {
public:
/// @brief Piece source.
Coord Src;
/// @brief Piece destination.
Coord Dst;
/// @brief Contains piece promoting name (k is black king, K white king etc..).
char Promote;
/// @brief Contains true if @a Promote can be used.
bool IsPromoting;
/**
* @brief Create new empty move.
*/
Move();
/**
* Parse a long algebraic notation move
* @param move in the long algebraic notation format
* @return A struct containing the actual move.
*/
void FromLA(std::string move);
};
}
using namespace std;
namespace ochess
{
namespace model
{
/**
* @brief Node of a game Abstract Syntax Tree (AST)
*/
class Move
{
public:
/// @brief Piece source.
Coord Src;
/// @brief Piece destination.
Coord Dst;
Move *parent;
Move *main;
vector<Move *> variations;
string SANMove;
string dst;
string comment;
string FEN;
char piece;
bool isCheck;
bool isPromotion;
bool isCheckMate;
bool isPawn;
bool isCapture;
bool isLongCastle;
bool isShortCastle;