Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Loic Guegan
ochess
Commits
5ef228c2
Commit
5ef228c2
authored
Nov 07, 2020
by
Loic Guegan
Browse files
Cleaning source code
parent
56b57ad8
Pipeline
#213050087
passed with stage
in 7 minutes and 28 seconds
Changes
41
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
41 changed files
with
430 additions
and
316 deletions
+430
-316
CMakeLists.txt
CMakeLists.txt
+5
-7
icons/ochess2.svg
icons/ochess2.svg
+208
-0
src/command/CMD_MovePiece.hpp
src/command/CMD_MovePiece.hpp
+1
-1
src/command/Command.hpp
src/command/Command.hpp
+0
-0
src/command/CommandManager.hpp
src/command/CommandManager.hpp
+1
-1
src/config/ConfigManager.cpp
src/config/ConfigManager.cpp
+0
-0
src/config/ConfigManager.hpp
src/config/ConfigManager.hpp
+1
-1
src/config/Configurable.cpp
src/config/Configurable.cpp
+0
-0
src/config/Configurable.hpp
src/config/Configurable.hpp
+0
-0
src/engine/Engine.hpp
src/engine/Engine.hpp
+1
-1
src/engine/UCIProc.hpp
src/engine/UCIProc.hpp
+2
-3
src/gui/MainFrame.cpp
src/gui/MainFrame.cpp
+2
-3
src/gui/MainFrame.hpp
src/gui/MainFrame.hpp
+1
-2
src/gui/board/BoardPanel.cpp
src/gui/board/BoardPanel.cpp
+2
-2
src/gui/board/BoardPanel.hpp
src/gui/board/BoardPanel.hpp
+2
-4
src/gui/board/controller/BoardController.hpp
src/gui/board/controller/BoardController.hpp
+1
-1
src/gui/board/controller/Skin.cpp
src/gui/board/controller/Skin.cpp
+2
-3
src/gui/board/controller/Skin.hpp
src/gui/board/controller/Skin.hpp
+2
-2
src/gui/engine/EngineView.hpp
src/gui/engine/EngineView.hpp
+2
-2
src/gui/engine/controller/EngineController.hpp
src/gui/engine/controller/EngineController.hpp
+1
-1
src/log.hpp
src/log.hpp
+2
-2
src/model/Algorithm.cpp
src/model/Algorithm.cpp
+21
-0
src/model/Algorithm.hpp
src/model/Algorithm.hpp
+1
-0
src/model/Board.hpp
src/model/Board.hpp
+1
-1
src/model/Fen.hpp
src/model/Fen.hpp
+2
-1
src/model/Game.cpp
src/model/Game.cpp
+8
-1
src/model/Game.hpp
src/model/Game.hpp
+23
-0
src/model/History.cpp
src/model/History.cpp
+77
-93
src/model/Move.cpp
src/model/Move.cpp
+7
-0
src/model/Move.hpp
src/model/Move.hpp
+1
-0
src/ochess.cpp
src/ochess.cpp
+14
-22
src/ochess.hpp
src/ochess.hpp
+18
-0
src/pgn/Game.cpp
src/pgn/Game.cpp
+0
-40
src/pgn/Game.hpp
src/pgn/Game.hpp
+0
-51
src/tools/OchessInstance.cpp
src/tools/OchessInstance.cpp
+0
-6
src/tools/OchessInstance.hpp
src/tools/OchessInstance.hpp
+0
-49
src/utils/Chrono.cpp
src/utils/Chrono.cpp
+0
-0
src/utils/Chrono.hpp
src/utils/Chrono.hpp
+2
-2
src/utils/pgn.cpp
src/utils/pgn.cpp
+14
-12
src/utils/pgn.hpp
src/utils/pgn.hpp
+3
-1
tests/engine/engine.cpp
tests/engine/engine.cpp
+2
-1
No files found.
CMakeLists.txt
View file @
5ef228c2
...
...
@@ -35,15 +35,13 @@ link_directories(${wxWidgets_LIBRARIES_DIRS})
# Define variables
set
(
SRC
${
CMAKE_SOURCE_DIR
}
/src
)
# Model Module
file
(
GLOB_RECURSE
MODEL
${
SRC
}
/
model
/*.cpp
)
# Engine Module
file
(
GLOB_RECURSE
CMD
${
SRC
}
/
command
/*.cpp
)
file
(
GLOB_RECURSE CNF
${
SRC
}
/config/*.cpp
)
file
(
GLOB_RECURSE ENGINE
${
SRC
}
/engine/*.cpp
)
# Tools Module
file
(
GLOB_RECURSE TOOLS
${
SRC
}
/tools/*.cpp
)
# PGN Module
file
(
GLOB_RECURSE PGN
${
SRC
}
/pgn/*.cpp
)
file
(
GLOB_RECURSE MODEL
${
SRC
}
/model/*.cpp
)
file
(
GLOB_RECURSE UTILS
${
SRC
}
/utils/*.cpp
)
# Combine for reusability
add_library
(
libochess OBJECT
${
MODEL
}
${
TOOLS
}
${
ENGINE
}
${
PGN
}
)
add_library
(
libochess OBJECT
${
CMD
}
${
CNF
}
${
ENGINE
}
${
MODEL
}
${
UTILS
}
)
# GUI Module
file
(
GLOB_RECURSE GUI
${
SRC
}
/gui/*.cpp
)
# Generate Executable
...
...
icons/ochess2.svg
0 → 100644
View file @
5ef228c2
This diff is collapsed.
Click to expand it.
src/
model/
command
s
/CMD_MovePiece.hpp
→
src/command/CMD_MovePiece.hpp
View file @
5ef228c2
#ifndef MOVE_HPP
#define MOVE_HPP
#include "Command.hpp"
#include "model/Board.hpp"
#include "tools/Command.hpp"
using
namespace
ochess
;
using
namespace
ochess
::
model
;
...
...
src/
tools
/Command.hpp
→
src/
command
/Command.hpp
View file @
5ef228c2
File moved
src/
tools
/CommandManager.hpp
→
src/
command
/CommandManager.hpp
View file @
5ef228c2
#ifndef COMMANDMANAGER_HPP
#define COMMANDMANAGER_HPP
#include "Command.hpp"
#include <stack>
#include <memory> // Shared pointer
#include "Command.hpp"
#define RUN_CMD(CMD) ochess::OchessInstance::GetCommandManager().run(std::shared_ptr<Command>(CMD));
#define REDO() ochess::OchessInstance::GetCommandManager().redo();
...
...
src/
tools/
config/ConfigManager.cpp
→
src/config/ConfigManager.cpp
View file @
5ef228c2
File moved
src/
tools/
config/ConfigManager.hpp
→
src/config/ConfigManager.hpp
View file @
5ef228c2
#ifndef CONFIGMANAGER_HPP
#define CONFIGMANAGER_HPP
#include "Configurable.hpp"
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <vector>
#include <cstdlib>
#include "Configurable.hpp"
using
namespace
boost
::
property_tree
;
using
namespace
std
;
...
...
src/
tools/
config/Configurable.cpp
→
src/config/Configurable.cpp
View file @
5ef228c2
File moved
src/
tools/
config/Configurable.hpp
→
src/config/Configurable.hpp
View file @
5ef228c2
File moved
src/engine/Engine.hpp
View file @
5ef228c2
...
...
@@ -5,7 +5,7 @@
#include <boost/filesystem.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include "
../
model/Move.hpp"
#include "model/Move.hpp"
#include <map>
#include <stack>
...
...
src/engine/UCIProc.hpp
View file @
5ef228c2
#ifndef UCIPROC_HPP
#define UCIPROC_HPP
#include "tools/log.hpp"
#include <boost/process.hpp>
#include <boost/filesystem.hpp>
#include <boost/asio.hpp>
#include "tools/Chrono.hpp"
#include "tools/log.hpp"
#include <boost/log/attributes.hpp>
#include <stack>
#include "log.hpp"
#include "utils/Chrono.hpp"
namespace
bp
=
boost
::
process
;
namespace
bfs
=
boost
::
filesystem
;
...
...
src/gui/MainFrame.cpp
View file @
5ef228c2
...
...
@@ -16,7 +16,7 @@ wxEND_EVENT_TABLE()
wxMenu
*
MainFrame
::
getPiecesMenu
()
{
wxMenu
*
themes
=
new
wxMenu
;
short
id
=
200
;
for
(
auto
&
theme
:
C
M
.
ListPiecesThemes
())
{
for
(
auto
&
theme
:
C
NF
.
ListPiecesThemes
())
{
themes
->
Append
(
id
,
theme
,
""
);
id
++
;
}
...
...
@@ -26,7 +26,7 @@ wxMenu* MainFrame::getPiecesMenu() {
wxMenu
*
MainFrame
::
getSquaresMenu
()
{
wxMenu
*
themes
=
new
wxMenu
;
short
id
=
300
;
for
(
auto
&
theme
:
C
M
.
ListBoardThemes
())
{
for
(
auto
&
theme
:
C
NF
.
ListBoardThemes
())
{
themes
->
Append
(
id
,
theme
,
""
);
id
++
;
}
...
...
@@ -36,7 +36,6 @@ wxMenu* MainFrame::getSquaresMenu() {
MainFrame
::
MainFrame
(
const
wxString
&
title
,
const
wxPoint
&
pos
,
const
wxSize
&
size
)
:
wxFrame
(
NULL
,
wxID_ANY
,
title
,
pos
,
size
)
{
CM
=
ochess
::
OchessInstance
::
GetConfigManager
();
wxMenu
*
menuFile
=
new
wxMenu
;
menuFile
->
Append
(
ID_Hello
,
"&Hello...
\t
Ctrl-H"
,
"Help string shown in status bar for this menu item"
);
...
...
src/gui/MainFrame.hpp
View file @
5ef228c2
...
...
@@ -7,7 +7,7 @@
#endif
#include "board/BoardView.hpp"
#include "engine/EngineView.hpp"
#include "
tools/OchessInstance
.hpp"
#include "
ochess
.hpp"
namespace
ochess
{
namespace
gui
{
...
...
@@ -35,7 +35,6 @@ private:
*/
BoardView
*
p
;
EngineView
*
e
;
ConfigManager
CM
;
vector
<
View
*>
OchessViews
;
void
OnHello
(
wxCommandEvent
&
event
);
...
...
src/gui/board/BoardPanel.cpp
View file @
5ef228c2
...
...
@@ -11,7 +11,7 @@ END_EVENT_TABLE()
BoardPanel
::
BoardPanel
(
wxFrame
*
parent
)
:
wxPanel
(
parent
),
Configurable
(
"BoardView"
),
C
(
this
)
{
UA
=
std
::
make_shared
<
UserActions
>
();
ochess
::
OchessInstance
::
GetConfigManager
()
.
AddModule
(
this
);
CNF
.
AddModule
(
this
);
UA
->
IsDraggingPiece
=
false
;
UA
->
DraggingPieceSquare
=
boost
::
none
;
UA
->
IsDrawingArrow
=
false
;
...
...
@@ -164,7 +164,7 @@ void BoardPanel::HandleMouse(wxMouseEvent &event) {
boost
::
optional
<
char
>
pieceName
=
C
.
GetPromotedPiece
(
promoted
.
i
,
promoted
.
j
,
square
.
i
,
square
.
j
,
c
);
if
(
pieceName
)
C
.
G
.
Promote
(
pieceName
.
value
());
C
.
G
.
Promote
(
(
char
)
pieceName
.
value
());
}
}
else
{
UA
->
DraggingPieceSquare
=
C
.
GetSquareAt
(
pos
.
x
,
pos
.
y
);
...
...
src/gui/board/BoardPanel.hpp
View file @
5ef228c2
...
...
@@ -11,10 +11,8 @@
#include <boost/format.hpp>
#include <sstream>
#include <boost/thread/mutex.hpp>
#include "model/commands/CMD_MovePiece.hpp"
#include "tools/config/Configurable.hpp"
#include "tools/OchessInstance.hpp"
#include "config/Configurable.hpp"
#include "ochess.hpp"
using
namespace
ochess
::
model
;
...
...
src/gui/board/controller/BoardController.hpp
View file @
5ef228c2
...
...
@@ -9,8 +9,8 @@
#include "engine/Engine.hpp"
#include <boost/filesystem.hpp>
#include "log.hpp"
#include "model/Move.hpp"
#include "tools/log.hpp"
namespace
bfs
=
boost
::
filesystem
;
using
namespace
ochess
;
...
...
src/gui/board/controller/Skin.cpp
View file @
5ef228c2
...
...
@@ -6,14 +6,13 @@ namespace gui {
Skin
::
Skin
()
{
wxInitAllImageHandlers
();
ConfigManager
CM
=
ochess
::
OchessInstance
::
GetConfigManager
();
for
(
auto
&
theme
:
CM
.
ListPiecesThemes
())
{
for
(
auto
&
theme
:
CNF
.
ListPiecesThemes
())
{
OC_LOG
(
trace
)
<<
"Loading default pieces skin: "
<<
theme
;
LoadPiecesSkin
(
theme
);
break
;
}
for
(
auto
&
theme
:
C
M
.
ListBoardThemes
())
{
for
(
auto
&
theme
:
C
NF
.
ListBoardThemes
())
{
OC_LOG
(
trace
)
<<
"Loading default board skin: "
<<
theme
;
LoadSquaresSkin
(
theme
);
...
...
src/gui/board/controller/Skin.hpp
View file @
5ef228c2
#ifndef SKIN_HPP
#define SKIN_HPP
#include "tools/OchessInstance.hpp"
#include "tools/log.hpp"
#include "ochess.hpp"
#include <wx/wxprec.h>
#include "log.hpp"
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
...
...
src/gui/engine/EngineView.hpp
View file @
5ef228c2
#ifndef ENGINEPANEL_HPP
#define ENGINEPANEL_HPP
#include "tools/log.hpp"
#include "gui/View.hpp"
#include "controller/EngineController.hpp"
#include "
tools/OchessInstance
.hpp"
#include "
ochess
.hpp"
#include "wx/sizer.h"
#include "wx/wx.h"
#include "../../log.hpp"
namespace
ochess
{
namespace
gui
{
...
...
src/gui/engine/controller/EngineController.hpp
View file @
5ef228c2
#ifndef ENGINECONTROLLER_HPP
#define ENGINECONTROLLER_HPP
#include "../../../log.hpp"
#include "engine/Engine.hpp"
#include "gui/Controller.hpp"
#include "gui/View.hpp"
#include "tools/log.hpp"
namespace
ochess
{
namespace
gui
{
...
...
src/
tools/
log.hpp
→
src/log.hpp
View file @
5ef228c2
...
...
@@ -2,7 +2,7 @@
#define OC_LOG_HPP
#include "boost/date_time/posix_time/posix_time.hpp"
#include "
tools/OchessInstance
.hpp"
#include "
ochess
.hpp"
#include <boost/filesystem.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
...
...
@@ -35,7 +35,7 @@ inline void OC_INIT_LOG() {
boost
::
log
::
trivial
::
debug
);
#endif
bfs
::
path
logPath
=
OchessInstance
::
GetConfigManager
()
.
GetLogPath
();
bfs
::
path
logPath
=
CNF
.
GetLogPath
();
// Convenience
typedef
sinks
::
synchronous_sink
<
sinks
::
text_ostream_backend
>
text_sink
;
...
...
src/model/Algorithm.cpp
View file @
5ef228c2
...
...
@@ -182,5 +182,26 @@ MoveType Algorithm::GetMoveType(Coord src, Coord dst) {
return
(
UNKNOWN
);
}
Coord
Algorithm
::
FindSrc
(
string
dst
,
char
col
){
Coord
src
;
auto
piecesCoord
=
GetPiecesOfColor
(
this
->
State
->
ActiveColor
);
std
::
vector
<
Coord
>
srcs
;
for
(
auto
c
:
piecesCoord
){
PPiece
piece
=
(
*
BRD
)[
c
];
if
(
piece
->
IsLegalMove
(
c
,
dst
))
srcs
.
push_back
(
c
);
}
if
(
srcs
.
size
()
==
1
)
src
=
srcs
.
front
();
else
if
(
srcs
.
size
()
>
1
){
for
(
auto
c
:
srcs
){
if
(
col
==
c
.
GetXY
()[
0
]){
return
(
c
);
}
}
}
return
(
src
);
}
}
// namespace model
}
// namespace ochess
src/model/Algorithm.hpp
View file @
5ef228c2
...
...
@@ -97,6 +97,7 @@ public:
* @return The coordinate of the next promoting pawn if exists.
*/
boost
::
optional
<
Coord
>
GetNextPromotingPawn
();
Coord
FindSrc
(
string
dst
,
char
col
);
};
}
// namespace model
...
...
src/model/Board.hpp
View file @
5ef228c2
#ifndef BOARD_HPP
#define BOARD_HPP
#include "../log.hpp"
#include "Coord.hpp"
#include "pieces/Piece.hpp"
#include "tools/log.hpp"
namespace
ochess
{
namespace
model
{
...
...
src/model/Fen.hpp
View file @
5ef228c2
...
...
@@ -10,11 +10,12 @@
#include "pieces/Queen.hpp"
#include "pieces/Rook.hpp"
#include <boost/algorithm/string.hpp> // Used in fen (split()...)
#include "tools/log.hpp"
#include <functional> // For lambda
#include <regex> // Used in fen
#include <string>
#include <vector>
#include "../log.hpp"
#define FEN_INITIAL "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
namespace
ochess
{
...
...
src/model/Game.cpp
View file @
5ef228c2
...
...
@@ -9,6 +9,7 @@ Game::Game(std::string fen) :
f
.
BuildBoard
(
&
BRD
);
State
=
f
.
GetState
();
}
Game
::
Game
()
:
Game
(
FEN_INITIAL
){}
boost
::
optional
<
PPiece
>
Game
::
GetPiece
(
Coord
c
)
{
if
(
!
BRD
.
isEmpty
(
c
))
...
...
@@ -71,6 +72,12 @@ bool Game::Move(Coord src, Coord dst) {
return
(
true
);
}
bool
Game
::
Move
(
ochess
::
model
::
Move
m
){
Coord
src
=
A
.
FindSrc
(
m
.
dst
,
m
.
col
);
std
::
cout
<<
"lkhjc: "
<<
src
.
GetXY
();
return
(
this
->
Move
(
src
.
GetXY
(),
m
.
dst
));
}
void
Game
::
Next
()
{
H
.
Next
(
&
BRD
,
&
State
);
}
...
...
@@ -169,7 +176,7 @@ bool Game::IsDrawByThreefold() {
// If we found a similar state
if
(
fen
.
ThreefoldCompare
(
currentFen
))
n
++
;
// If three sim
u
lar states is found
// If three sim
i
lar states is found
if
(
n
>=
3
)
{
H
.
RestoreState
();
return
(
true
);
...
...
src/model/Game.hpp
View file @
5ef228c2
...
...
@@ -13,10 +13,29 @@
#include "pieces/Knight.hpp"
#include "pieces/Queen.hpp"
#include <boost/optional.hpp>
#include <unordered_map>
#include "Move.hpp"
#include "Coord.hpp"
#include <iostream>
namespace
ochess
{
namespace
model
{
typedef
struct
GameInfos
{
bool
isDraw
;
bool
isWhiteWin
;
/// @brief Cf the "WhiteClock" PGN tag
short
WhiteClock
[
3
];
/// @brief Cf the "BlackClock" PGN tag
short
BlackClock
[
3
];
unordered_map
<
string
,
string
>
tags
;
}
GameInfos
;
/**
* @class Game
* @brief The only class that you should care of!
...
...
@@ -74,11 +93,14 @@ private:
}
;
public:
GameInfos
infos
;
/**
* @brief Create a new game with a initial starting position.
* @param fen Initial Position.
*/
Game
(
std
::
string
fen
);
Game
();
/**
* @brief Move the piece at src to dst
*
...
...
@@ -88,6 +110,7 @@ public:
* @return true if the move was legal and worked.
*/
bool
Move
(
Coord
src
,
Coord
dst
);
bool
Move
(
ochess
::
model
::
Move
m
);
/**
* @brief Check if a square is empty (usefull for the gui).
* @param c
...
...
src/model/History.cpp
View file @
5ef228c2
#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
->
IsLeaf
())
{
CurrentState
=
CurrentState
->
main
;
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
->
IsLeaf
())
{
CurrentState
=
CurrentState
->
main
;
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
->
parent
!=
nullptr
)
{
CurrentState
=
CurrentState
->
parent
;
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
->
parent
!=
nullptr
)
{
CurrentState
=
CurrentState
->
parent
;
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
)
{
Move
*
newState
=
new
Move
;
Fen
f
(
board
,
*
state
);
newState
->
FEN
=
f
.
GetFen
();
newState
->
parent
=
CurrentState
;
CurrentState
->
expand
(
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
)
{
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
::
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
::
SyncSavedState
(
Move
*
state
)
{
if
(
state
==
SavedState
||
state
->
main
==
SavedState
)
SavedState
=
NULL
;
for
(
auto
&
cur_state
:
state
->
variations
)
SyncSavedState
(
cur_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
src/model/Move.cpp
View file @
5ef228c2
...
...
@@ -56,6 +56,13 @@ namespace ochess
else
this
->
variations
.
push_back
(
m
);
}
bool
Move
::
operator
==
(
const
Move
&
m
){
return
(
this
->
Src
==
m
.
Src
&&
this
->
Dst
==
m
.
Dst
&&
this
->
FEN
==
m
.
FEN
);