Skip to content

Commit

Permalink
Commit gates functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
alexobviously committed Oct 19, 2020
1 parent 9a2a363 commit c10eaa6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,
ss >> std::noskipws;

Square sq = SQ_A1 + max_rank() * NORTH;
int commitFile = 0;
int rank = 0;

// 1. Piece placement
while ((ss >> token) && !isspace(token))
Expand All @@ -271,15 +273,23 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,

else if (token == '/')
{
++rank;
commitFile = 0;
sq += 2 * SOUTH + (FILE_MAX - max_file()) * EAST;
if (!is_ok(sq))
break;
}

else if(token == '*') ++commitFile;

else if ((idx = piece_to_char().find(token)) != string::npos || (idx = piece_to_char_synonyms().find(token)) != string::npos)
{
if (ss.peek() == '~')
ss >> token;
if(v->commitGates && (rank == 0 || rank == FILE_NB+1){
commit_piece(Piece(idx), commitFile);
++commitFile;
}
put_piece(Piece(idx), sq, token == '~');
++sq;
}
Expand Down
21 changes: 21 additions & 0 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class Position {
const Variant* var;
bool chess960;
int pieceCountInHand[COLOR_NB][PIECE_TYPE_NB];
int committedGates[COLOR_NB][FILE_NB];
Bitboard promotedPieces;
void add_to_hand(Piece pc);
void remove_from_hand(Piece pc);
Expand Down Expand Up @@ -1191,6 +1192,26 @@ inline void Position::remove_from_hand(Piece pc) {
psq -= PSQT::psq[pc][SQ_NONE];
}

inline void Position::commit_piece(Piece pc, File fl){
committedGates[color_of(pc)][fl] = type_of(pc);
}

inline void Position::uncommit_piece(Color cl, File fl){
committedGates[cl][fl] = NO_PIECE;
}

inline bool Position::has_committed_piece(Color cl, File fl){
return committedGates[cl][fl] > NO_PIECE;
}

inline void Position::drop_committed_piece(Color cl, File fl){
if(has_committed_piece(cl, fl)){
Square dropSquare = (cl == WHITE)?fl:SQUARE_NB-8+fl;
put_piece(committedGates[cl][fl], dropSquare, false, NO_PIECE);
uncommit_piece(cl, fl);
}
}

inline void Position::drop_piece(Piece pc_hand, Piece pc_drop, Square s) {
assert(pieceCountInHand[color_of(pc_hand)][type_of(pc_hand)]);
put_piece(pc_drop, s, pc_drop != pc_hand, pc_drop != pc_hand ? pc_hand : NO_PIECE);
Expand Down
6 changes: 3 additions & 3 deletions src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ namespace {
v->add_piece(ARCHBISHOP, 'a');
v->add_piece(CHANCELLOR, 'o');
v->add_piece(AMAZON, 'd'); // called Dragon in Musketeer
v->add_piece(LEOPARD, 'l'); // UNFINISHED
v->add_piece(LEOPARD, 'l');
v->add_piece(HAWK, 'h');
v->add_piece(UNICORN, 'u');
v->add_piece(SPIDER, 's'); // UNFINISHED
v->add_piece(FORTRESS, 'f'); // UNFINISHED
v->add_piece(SPIDER, 's');
v->add_piece(FORTRESS, 'f');
v->add_piece(MUSKETEER_ELEPHANT, 'e');
v->add_piece(MUSKETEER_CANNON, 'c');
v->startFen = "ao******/rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR/AO****** w KQkq - 0 1";
Expand Down

0 comments on commit c10eaa6

Please sign in to comment.