Commit 6b53aeed by WangChenxi

DeBug1

parent ebbfb394
......@@ -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>
......
......@@ -97,7 +97,7 @@ ChessCoordId StrToId(const std::string &str) {
return CoordToId(x, y);
}
void ActionToId(const int &action, const ChessCoordId &from_id, const ChessCoordId &to_id, ChessStoneColor &captured_stone, ChessStoneColor &promoted_stone, ChessStoneColor &stone){
void ActionToId(const int &action, const ChessStone &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];
captured_stone = code[2];
promoted_stone = code[1];
stone = code[0];
stone = code[4];
captured_stone = code[3];
promoted_stone = code[2];
from_id = code[1];
to_id = code[0];
}
}
void IdToAction(const ChessCoordId &from_id, const ChessCoordId &to_id, ChessStoneColor &captured_stone, ChessStoneColor &promoted_stone, ChessStoneColor &stone, const int &action){
void IdToAction(const ChessStone &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];
}
}
......
......@@ -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 ChessCoordId &from_id, const ChessCoordId &to_id, ChessStone &captured_stone, ChessStone &promoted_stone, ChessStone &stone);
extern void ActionToId(const int &action, const ChessStone &stone, const ChessStone &captured_stone, const ChessStone &promoted_stone, const ChessCoordId &from_id, const ChessCoordId &to_id);
extern void IdToAction(const ChessCoordId &from_id, const ChessCoordId &to_id, ChessStone &captured_stone, ChessStone &promoted_stone, ChessStone &stone, const int &action);
extern void IdToAction(const ChessStone &stone, const ChessStone &captured_stone, const ChessStone &promoted_stone, const ChessCoordId &from_id, const ChessCoordId &to_id, const int &action);
extern void CreateGlobalVariables();
......
......@@ -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;
......
No preview for this file type
......@@ -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>
......
......@@ -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;
......
......@@ -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_;
......
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