Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
Games_For_AlphaGoZero
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WangChenxi
Games_For_AlphaGoZero
Commits
6b53aeed
Commit
6b53aeed
authored
May 13, 2021
by
WangChenxi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DeBug1
parent
ebbfb394
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
33 additions
and
30 deletions
+33
-30
Chess/chess/chess.h
+5
-5
Chess/chess/chess_comm.cc
+8
-8
Chess/chess/chess_comm.h
+5
-4
Chess/chess/chess_env.cc
+0
-0
Chess/chess/chess_env.h
+2
-2
ChineseChess/.DS_Store
+0
-0
ChineseChess/chinesechess/chinesechess.h
+4
-4
ChineseChess/chinesechess/chinesechess_comm.h
+6
-5
ChineseChess/chinesechess/chinesechess_env.cc
+0
-0
ChineseChess/chinesechess/chinesechess_env.h
+3
-2
No files found.
Chess/chess/chess.h
View file @
6b53aeed
...
...
@@ -8,14 +8,14 @@
*/
//EnCode for move(action)::
/*
from_id 64
to_id 64
stone 17
captured 10
promoted 8
stone 17
Attention: all this coding part should be >= 0
from_id 64
to_id 64
Attention: all this coding part should be >= 0 for a normal action
*/
//action =
from_id * 64^4 + to_id * 64^3 + captured * 64^2 + promoted * 64^1 + stone * 64^0
//action =
stone * 64^4 + captured * 64^3 + promoted * 64^2 + from_id * 64^1 + to_id * 64^0 //For many games, we use to_id as its action. To keep the same, to_id is the last bit.
#include <cstdlib>
#include <string>
...
...
Chess/chess/chess_comm.cc
View file @
6b53aeed
...
...
@@ -97,7 +97,7 @@ ChessCoordId StrToId(const std::string &str) {
return
CoordToId
(
x
,
y
);
}
void
ActionToId
(
const
int
&
action
,
const
Chess
CoordId
&
from_id
,
const
ChessCoordId
&
to_id
,
ChessStoneColor
&
captured_stone
,
ChessStoneColor
&
promoted_stone
,
ChessStoneColor
&
stone
){
void
ActionToId
(
const
int
&
action
,
const
Chess
Stone
&
stone
,
const
ChessStone
&
captured_stone
,
const
ChessStone
&
promoted_stone
,
const
ChessCoordId
&
from_id
,
const
ChessCoordId
&
to_id
){
int
code
[
5
];
int
i
;
if
(
action
==
COORD_RESIGN
){
...
...
@@ -114,15 +114,15 @@ void ActionToId(const int &action, const ChessCoordId &from_id, const ChessCoord
code
[
i
]
=
action
%
64
;
action
=
action
/
64
;
}
from_id
=
code
[
4
];
to_id
=
code
[
3
];
captur
ed_stone
=
code
[
2
];
promoted_stone
=
code
[
1
];
stone
=
code
[
0
];
stone
=
code
[
4
];
captured_stone
=
code
[
3
];
promot
ed_stone
=
code
[
2
];
from_id
=
code
[
1
];
to_id
=
code
[
0
];
}
}
void
IdToAction
(
const
Chess
CoordId
&
from_id
,
const
ChessCoordId
&
to_id
,
ChessStoneColor
&
captured_stone
,
ChessStoneColor
&
promoted_stone
,
ChessStoneColor
&
stone
,
const
int
&
action
){
void
IdToAction
(
const
Chess
Stone
&
stone
,
const
ChessStone
&
captured_stone
,
const
ChessStone
&
promoted_stone
,
const
ChessCoordId
&
from_id
,
const
ChessCoordId
&
to_id
,
const
int
&
action
){
int
code
[
5
];
int
i
,
j
;
for
(
i
=
0
;
i
<
5
;
i
++
){
...
...
@@ -138,7 +138,7 @@ void IdToAction(const ChessCoordId &from_id, const ChessCoordId &to_id, ChessSto
code
[
i
]
*=
64
;
}
}
action
=
from_id
*
code
[
4
]
+
to_id
*
code
[
3
]
+
captured_stone
*
code
[
2
]
+
promoted_stone
*
code
[
1
]
+
stone
*
code
[
0
];
action
=
stone
*
code
[
4
]
+
captured_stone
*
code
[
3
]
+
promoted_stone
*
code
[
2
]
+
from_id
*
code
[
1
]
+
to_id
*
code
[
0
];
}
}
...
...
Chess/chess/chess_comm.h
View file @
6b53aeed
...
...
@@ -18,7 +18,8 @@
// Return code of functions should be "int"
typedef
uint8_t
ChessStoneColor
;
// Stone color
typedef
int16_t
ChessCoordId
;
// Stone IDs or coordinates
typedef
int16_t
ChessSize
;
// Counts of visit times, used blocks, .. or other count
typedef
int32_t
ChessSize
;
// Counts of visit times, used blocks, .. or other count //For our action space, int16 may be not enough
//typedef int16_t ChessSize; // Counts of visit times, used blocks, .. or other count
namespace
ChessComm
{
...
...
@@ -45,7 +46,7 @@ const ChessStoneColor BLACK_ROOK = 13;
const
ChessStoneColor
BLACK_QUEEN
=
14
;
const
ChessStoneColor
BLACK_KING
=
15
;
const
ChessStoneColor
COLOR_UNKNOWN
=
-
1
;
const
char
*
const
COLOR_STRING
[]
=
{
"Empty"
,
"
Black"
,
"White
"
,
"Wall"
,
"White Pawn"
,
"White Knight"
,
"White Bishop"
,
"White Rook"
,
"White Queen"
,
"White King"
,
"Black Pawn"
,
"Black Knight"
,
"Black Bishop"
,
"Black Rook"
,
"Black Queen"
,
"Black King"
};
const
char
*
const
COLOR_STRING
[]
=
{
"Empty"
,
"
White"
,
"Black
"
,
"Wall"
,
"White Pawn"
,
"White Knight"
,
"White Bishop"
,
"White Rook"
,
"White Queen"
,
"White King"
,
"Black Pawn"
,
"Black Knight"
,
"Black Bishop"
,
"Black Rook"
,
"Black Queen"
,
"Black King"
};
const
ChessCoordId
N
=
-
8
;
const
ChessCoordId
S
=
8
;
...
...
@@ -106,9 +107,9 @@ extern std::string IdToStr(const ChessCoordId id);
extern
ChessCoordId
StrToId
(
const
std
::
string
&
str
);
extern
void
ActionToId
(
const
int
&
action
,
const
Chess
CoordId
&
from_id
,
const
ChessCoordId
&
to_id
,
ChessStone
&
captured_stone
,
ChessStone
&
promoted_stone
,
ChessStone
&
stone
);
extern
void
ActionToId
(
const
int
&
action
,
const
Chess
Stone
&
stone
,
const
ChessStone
&
captured_stone
,
const
ChessStone
&
promoted_stone
,
const
ChessCoordId
&
from_id
,
const
ChessCoordId
&
to_id
);
extern
void
IdToAction
(
const
Chess
CoordId
&
from_id
,
const
ChessCoordId
&
to_id
,
ChessStone
&
captured_stone
,
ChessStone
&
promoted_stone
,
ChessStone
&
stone
,
const
int
&
action
);
extern
void
IdToAction
(
const
Chess
Stone
&
stone
,
const
ChessStone
&
captured_stone
,
const
ChessStone
&
promoted_stone
,
const
ChessCoordId
&
from_id
,
const
ChessCoordId
&
to_id
,
const
int
&
action
);
extern
void
CreateGlobalVariables
();
...
...
Chess/chess/chess_env.cc
View file @
6b53aeed
This diff is collapsed.
Click to expand it.
Chess/chess/chess_env.h
View file @
6b53aeed
...
...
@@ -57,7 +57,7 @@ protected:
ChessStoneColor
GetWinner
()
const
;
inline
void
HandOff
()
{
current_player_
=
Opponent
();
}
inline
ChessStoneColor
Opponent
(
const
ChessStoneColor
color
=
ChessComm
::
COLOR_UNKNOWN
)
const
{
return
ChessComm
::
BLACK
+
ChessComm
::
WHITE
return
ChessComm
::
WHITE
+
ChessComm
::
BLACK
-
(
ChessComm
::
COLOR_UNKNOWN
!=
color
?
color
:
current_player_
);
}
inline
ChessStoneColor
Self
()
const
{
return
current_player_
;
}
...
...
@@ -67,7 +67,7 @@ protected:
void
GetSensibleMove
();
bool
IsSquareThreatened
(
ChessCoordId
&
id
)
const
;
bool
IsKingInCheck
()
const
bool
IsKingInCheck
()
const
;
void
Find_Legal_Moves
()
const
;
bool
IsMoveValid
(
int
&
action
)
const
;
...
...
ChineseChess/.DS_Store
View file @
6b53aeed
No preview for this file type
ChineseChess/chinesechess/chinesechess.h
View file @
6b53aeed
...
...
@@ -6,14 +6,14 @@
Experiment environment;
Environment in Agents' mind
*/
//EnCode for move(action)::
//EnCode for
chinesechess
move(action)::
/*
stone 19
from_id 90
to_id 90
stone 19
Attention: all this coding part should be >= 0
Attention: all this coding part should be >= 0 for a normal action
*/
//action = stone * 90^2 + from_id * 90^1 + to_id * 90^0
//action = stone * 90^2 + from_id * 90^1 + to_id * 90^0
//For many games, we use to_id as its action. To keep the same, to_id is the last bit.
#include <cstdlib>
#include <string>
...
...
ChineseChess/chinesechess/chinesechess_comm.h
View file @
6b53aeed
...
...
@@ -21,20 +21,21 @@
// Return code of functions should be "int"
typedef
uint8_t
ChineseChessStoneColor
;
// Stone color
typedef
int16_t
ChineseChessCoordId
;
// Stone IDs or coordinates
typedef
int16_t
ChineseChessSize
;
// Counts of visit times, used blocks, .. or other count
typedef
int32_t
ChineseChessSize
;
// Counts of visit times, used blocks, .. or other count //For our action space, int16 may be not enough
//typedef int16_t ChineseChessSize; // Counts of visit times, used blocks, .. or other count
namespace
ChineseChessComm
{
const
ChineseChessCoordId
BORDER_SIZE_LENGTH
=
9
;
// sxk_modify
const
ChineseChessCoordId
BORDER_SIZE_HEIGHT
=
10
;
const
ChineseChessCoordId
BORDER_SIZE_LENGTH
=
9
;
// sxk_modify
//y
const
ChineseChessCoordId
BORDER_SIZE_HEIGHT
=
10
;
//x
const
ChineseChessCoordId
CHINESECHESSBOARD_SIZE
=
BORDER_SIZE_LENGTH
*
BORDER_SIZE_HEIGHT
;
const
ChineseChessCoordId
COORD_UNSET
=
-
2
;
//const ChineseChessCoordId COORD_PASS = -1;
const
ChineseChessCoordId
COORD_RESIGN
=
-
3
;
const
ChineseChessStoneColor
EMPTY
=
0
;
const
ChineseChessStoneColor
RED
=
1
;
const
ChineseChessStoneColor
BLACK
=
2
;
const
ChineseChessStoneColor
RED
=
1
;
//First player
const
ChineseChessStoneColor
BLACK
=
2
;
//Second player
const
ChineseChessStoneColor
WALL
=
3
;
const
ChineseChessStoneColor
RED_PAWN
=
4
;
const
ChineseChessStoneColor
RED_CANNON
=
5
;
...
...
ChineseChess/chinesechess/chinesechess_env.cc
View file @
6b53aeed
This diff is collapsed.
Click to expand it.
ChineseChess/chinesechess/chinesechess_env.h
View file @
6b53aeed
...
...
@@ -64,8 +64,7 @@ protected:
//void ChineseChessEnv::TransformCoord(ChineseChessCoordId &x, ChineseChessCoordId &y, int mode, bool reverse = false)
void
GetSensibleMove
();
bool
IsSquareThreatened
(
ChineseChessCoordId
&
id
)
const
;
bool
IsKingInCheck
()
const
bool
IsKingInCheck
()
const
;
void
Find_Legal_Moves
()
const
;
bool
IsMoveValid
(
int
&
action
)
const
;
...
...
@@ -78,6 +77,8 @@ protected:
int
last_action_
;
bool
is_resign_
;
int
state_
;
bool
is_redking_incheck_
;
bool
is_blackking_incheck_
;
// hash board state
std
::
unordered_set
<
uint64_t
>
board_hash_states_
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment