Commit 01e25a03 authored by Loic Guegan's avatar Loic Guegan
Browse files

Start pgn parser

parent 97aa5abc
Pipeline #211178723 passed with stage
in 9 minutes and 1 second
<?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.1954196798">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1954196798" 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 artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.1954196798" name="Default" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=unix:///var/run/docker.sock" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1954196798.796053469" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1554761773" 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.756066971" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
<builder arguments="-j4" buildPath="${workspace_loc:/ochess/build}" command="make" id="cdt.managedbuild.target.gnu.builder.base.725048552" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.112412614" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.2073110971" 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.1351999227" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="/usr/include/wx-3.1/"/>
<listOptionValue builtIn="false" value="/usr/lib/wx/include/gtk3-unicode-3.1"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1478128016" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.231275253" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1802817762" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1759293641" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.858545524" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="gnu.cpp.link.option.paths.1490891234" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="gnu.cpp.link.option.libs.989520208" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.973561693" 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.1270414612" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1238848191" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="ochess.null.1478266371" name="ochess"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/ochess"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.1954196798;cdt.managedbuild.toolchain.gnu.base.1954196798.796053469;cdt.managedbuild.tool.gnu.c.compiler.base.231275253;cdt.managedbuild.tool.gnu.c.compiler.input.1802817762">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.1954196798;cdt.managedbuild.toolchain.gnu.base.1954196798.796053469;cdt.managedbuild.tool.gnu.cpp.compiler.base.2073110971;cdt.managedbuild.tool.gnu.cpp.compiler.input.1478128016">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cproject>
<?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>
......@@ -8,3 +8,5 @@ doc/latex
# Ignore Caches
*#*#
*#*
.vscode
<?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.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<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>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.toolchain.gnu.base.1954196798" 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="-692068618845725880" 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>
This diff is collapsed.
doxygen/doxygen_new_line_after_brief=true
doxygen/doxygen_use_brief_tag=false
doxygen/doxygen_use_javadoc_tags=true
doxygen/doxygen_use_pre_tag=false
doxygen/doxygen_use_structural_commands=false
eclipse.preferences.version=1
eclipse.preferences.version=1
formatter_settings_version=1
This diff is collapsed.
......@@ -15,7 +15,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra") # Be hard-liner
set(LOCAL_WX "${CMAKE_CURRENT_BINARY_DIR}/WX")
if(EXISTS "${LOCAL_WX}")
message(STATUS "Using local WxWidgets ${LOCAL_WX}")
#set(wxWidgets_ROOT_DIR "${LOCAL_WX}")
set(wxWidgets_ROOT_DIR "${LOCAL_WX}")
set(wxWidgets_CONFIG_EXECUTABLE "${LOCAL_WX}/build/wx-config")
set(wxWidgets_wxrc_EXECUTABLE "${LOCAL_WX}/lib/wxrc")
else()
......
......@@ -10,24 +10,24 @@
// ---------- wxWidgets ----------
#include <wx/wxprec.h>
/* #include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#endif */
// ---------- Boost ----------
#include <cctype> // For tolower()
// ---------- ochess ----------
#include "tools/log.hpp"
/* #include "tools/log.hpp"
#include "gui/MainFrame.hpp"
#include "tools/OchessInstance.hpp"
#include "engine/Engine.hpp"
using namespace ochess;
*/
//using namespace ochess;
/**
* Main Application
*/
class OChessApp: public wxApp {
/* class OChessApp: public wxApp {
public:
bool OnInit() override {
......@@ -39,23 +39,19 @@ public:
return true;
}
};
}; */
// int main(int argc, char *argv[])
// {
// (void)argc;
// (void)argv;
#include "pgn/pgn.hpp"
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
// engine::Engine p("engine");
// p.go(false,false);
// while(!p.IsBestMoveFound()){
// }
// BOOST_LOG_TRIVIAL(warning) << "Found the best move:" << p.GetBestMove();
// p.~UCIProc();
// exit(0);
ochess::pgn::PGN p("/home/loic/test.pgn");
// return 0;
// }
return 0;
}
// Create Main base on OChessApp
wxIMPLEMENT_APP(OChessApp);
/* wxIMPLEMENT_APP(OChessApp);
*/
\ No newline at end of file
#include <unordered_map>
#include <vector>
#include <string>
using namespace std;
namespace ochess
{
namespace pgn
{
typedef struct Line
{
Line *parent;
Line *main;
vector<Line*> variations;
char move[10];
string comment;
short moveId;
} Line;
class Game
{
private:
unordered_map<string, string> tags;
Line *line;
public:
void dumpLine(){
dump(line);
}
void dump(Line *l){
if(l!=nullptr){
cout << "Move id:" << l->move << endl;
dump(l->main);
}
}
void addTag(string key, string value);
string getTag(string key);
vector<string> listTag();
Line *getLine();
void setLine(Line *line);
};
void Game::addTag(string key, string value)
{
this->tags[key] = value;
}
string Game::getTag(string key){
return(tags[key]);
}
vector<string> Game::listTag()
{
std::vector<string> keys;
for (auto kv : tags)
keys.push_back(kv.first);
return (keys);
}
Line* Game::getLine(){
return(this->line);
}
void Game::setLine(Line *line){
this->line=line;
}
} // namespace pgn
} // namespace ochess
#include <iostream>
#include <string>
#include <fstream>
#include <string.h>
#include "Game.hpp"
#define IS_SPACE(c) ((c) == ' ' || (c) == '\t')
using namespace std;
namespace ochess
{
namespace pgn
{
class PGN
{
private:
ifstream file;
char read();
char nextChar();
void parse();
vector<Game> games;
Line *parseLine(Line *parent);
void parseComment(Line *line);
void skipSpaces();
string readWord();
public:
PGN(string file_path);
~PGN();
};
PGN::PGN(string file_path)
{
file.open(file_path);
parse();
}
PGN::~PGN()
{
file.close();
}
char PGN::read()
{
char c = file.get();
if (c == EOF)
{ // We should never reach EOF in this function
cout << "Unexpected end of file" << endl;
exit(0);
}
return c;
}
char PGN::nextChar()
{
return file.peek();
}
void PGN::skipSpaces()
{
while (IS_SPACE(nextChar()))
read();
}
string PGN::readWord()
{
string word;
while (!IS_SPACE(nextChar()))
word.push_back(read());
return (word);
}
void PGN::parse()
{
Game *g = new Game();
while (nextChar() != EOF)
{
if (nextChar() == '[')
{
read(); // Read the [
char c = read();
string tagKey, tagValue;
bool valueStart = false;
while (c != ']')
{
if (!valueStart)
{
if (c == ' ')
valueStart = true;
else
tagKey.push_back(c);
}
else
{
if (c != '"') // Remove all "
tagValue.push_back(c);
}
c = read();
}
g->addTag(tagKey, tagValue);
}
else if (nextChar() == '1')
{
//g->setLine(parseLine(nullptr));
//for (auto kv : g->listTag())
// cout << kv << " ----- " << g->getTag(kv) << endl;
g->dump(parseLine(nullptr));
exit(0);
g = new Game(); // Now we start parsing a new game
}
if (nextChar() != EOF)
read();
}
free(g); // Since their is no more game
}
Line *PGN::parseLine(Line *parent)
{
Line *root = new Line;
Line *l = root;
l->parent = parent;
while (nextChar() != EOF && nextChar() != '*' && nextChar() != ')')
{
skipSpaces(); // Goto next char
// Read move number
if (nextChar() >= '0' && nextChar() <= '9')
{
string moveId;
while (nextChar() != '.')
moveId.push_back(read());
l->moveId = stoi(moveId);
while (nextChar() == '.')
{ // Read the mandatory .
read();
}
skipSpaces();
}
// Read the move
string move;
while(!IS_SPACE(nextChar()) && nextChar()!=')')
move.push_back(read());
strcpy(l->move, move.c_str()); // Can leads to segfault if l.move is not large enough
skipSpaces();
// cout << l->moveId<< endl;
// cout << l->move<< endl;
// Check if there is a comment
if (nextChar() == '{')
{
parseComment(l);
skipSpaces();
}
// Read all variations
while (nextChar() == '(')
{
read(); // Skip parenthesis for the parseLine function
l->variations.push_back(parseLine(l));
skipSpaces();
}
// Create next Move
Line *newMove = new Line;
newMove->parent = l;
newMove->moveId = l->moveId; // By default same of id of the parent
l->main = newMove;
l = newMove;
}
if (root != l)
{// Last created move is not usefull anymore
l->parent->main = nullptr;
free(l);
}
skipSpaces();
if (nextChar() == ')') // Read the last parenthesis of a variation
read();
return (root);
} // namespace pgn
void PGN::parseComment(Line *line)
{
read(); // Read the {
while (nextChar() != '}')
{
line->comment.push_back(read());
}
read(); // Read the }
}
} // namespace pgn
} // namespace ochess
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment