Working on bug...TBC

master
Tait Hoyem 5 years ago
parent f2cff7440b
commit 70129a3219

@ -16,11 +16,8 @@ void print_board(array<PieceType, 120> const& board){
int ix = (i*10) + j;
int piece = board[ix];
string piece_string = FANCY_CHESS_CHARS[piece];
if (is_white(piece)){
cout << color::rize(piece_string, "White", "Default");
} else {
cout << color::rize(piece_string, "Black", "Default");
}
string color = is_white(piece)?"White":"Black";
cout << color::rize(piece_string, color, "Default");
cout << " ";
}
cout << endl;
@ -30,7 +27,61 @@ void print_board(array<PieceType, 120> const& board){
}
// TODO: allow algebraic notation.
int main(){
print_board(DEFAULT_BOARD);
Color whos_turn = Color::WHITE;
array<PieceType, 120> my_board;
copy(DEFAULT_BOARD.begin(), DEFAULT_BOARD.end(),
my_board.begin());
vector<int> all_moves = {};
vector<string> all_moves_notation = {};
while (true){
all_moves = {};
all_moves_notation = {};
// Gets all moves for color who's turn it is.
if (whos_turn == Color::WHITE){
get_all_white_moves(&my_board, &all_moves);
} else {
get_all_black_moves(&my_board, &all_moves);
}
print_board(my_board);
// Gets a string from cin called input
string input;
getline(cin, input);
// Quits
if (input == "q"){
break;
}
// Gets all moves and stores them in a notation list
// TODO make into own function
bool move_exec = false;
int move_to_exec = 0;
for (int move : all_moves){
string move_notation = to_notation(move, &my_board);
all_moves_notation.push_back(move_notation);
if (move_notation == input){
move_exec = true;
move_to_exec = move;
break;
}
}
// If the input did not match any legal move.
if (!move_exec){
cout << "These are the only valid moves: ";
for (string notation : all_moves_notation){
cout << notation << " ";
}
cout << endl;
// If the input did match a legal move.
} else {
my_board = dumb_move(move_to_exec, my_board);
whos_turn = rev_color(whos_turn);
}
}
return 0;
}

@ -375,3 +375,18 @@ std::string to_notation(int move, std::array<PieceType, 120> *board){
}
return ss.str();
}
void get_all_white_moves(std::array<PieceType, 120> *board, std::vector<int> *moves){
for (PieceType pt : Pieces::WHITE){
for (int pos_of : get_poss_of(pt, board)){
get_all_moves_as_if(pos_of, pt, board, moves);
}
}
}
void get_all_black_moves(std::array<PieceType, 120> *board, std::vector<int> *moves){
for (PieceType pt : Pieces::BLACK){
for (int pos_of : get_poss_of(pt, board)){
get_all_moves_as_if(pos_of, pt, board, moves);
}
}
}

@ -62,3 +62,7 @@ bool is_checked(int pos, std::array<PieceType, 120> board);
// Convert move (and board becuase notation needs more info than the move itself)
// ...into algbraic notation.
std::string to_notation(int move, std::array<PieceType, 120> *board);
// These functions are just for printing (for now) so they are not included in the tests.
void get_all_white_moves(std::array<PieceType, 120> *board, std::vector<int> *moves);
void get_all_black_moves(std::array<PieceType, 120> *board, std::vector<int> *moves);

@ -262,3 +262,12 @@ TEST_CASE("Test for disambiguating moves, and checkmate mark (#)", "[to_notation
CHECK(get_notations(check_rook_moves, CHECKMATE_ROOK_BOARD) == CHECKMATE_ROOK_NOTATION);
}
TEST_CASE("Do extra (random board tests) on notation and move generation", "[to_notation][get_all_moves]"){
auto knight_moves = get_all_moves(KNIGHT_EXTRA1_POS, EXTRA1_BOARD);
auto knight_moves2 = get_all_moves(KNIGHT_EXTRA2_POS, EXTRA2_BOARD);
CHECK(get_notations(knight_moves, EXTRA1_BOARD) == KNIGHT_EXTRA1_NOTATION);
CHECK(get_notations(knight_moves2, EXTRA2_BOARD) == KNIGHT_EXTRA2_NOTATION);
CHECK(get_to_squares(knight_moves2) == KNIGHT_EXTRA2_MOVES);
}

@ -718,3 +718,60 @@ const std::vector<std::string> CHECKMATE_ROOK_NOTATION = {
"Rd7", "Rd6", "Rd5", "Rd4", "Rd3", "Rdd2", "Rd1#"
};
// Extra checks on valid moves
const int KNIGHT_EXTRA1_POS = G5;
const std::array<PieceType, 120> EXTRA1_BOARD = {
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV,
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV,
INV, B_ROOK, NONE, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK, INV,
INV, NONE, B_PAWN, B_PAWN, B_PAWN, NONE, NONE, B_PAWN, B_PAWN, INV,
INV, NONE, NONE, W_KNIGHT, NONE, NONE, B_PAWN, NONE, NONE, INV,
INV, B_PAWN, NONE, NONE, NONE, B_PAWN, W_PAWN, W_KNIGHT, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, NONE, W_PAWN, W_PAWN, INV,
INV, W_ROOK, W_KNIGHT, W_BISHOP, W_QUEEN, W_KING, W_BISHOP, NONE, W_ROOK, INV,
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV,
INV, INV, INV, INV, INV, INV, INV, INV, INV, INV
};
const std::vector<std::string> KNIGHT_EXTRA1_NOTATION = {
"Nh3", "Nf3", "Ne4", "Ne6", "Nf7", "Nxh7"
};
const int KNIGHT_EXTRA2_POS = D4;
const std::array<PieceType, 120> EXTRA2_BOARD = {
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,
INV, B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK, INV,
INV, B_PAWN, B_PAWN, B_PAWN, B_PAWN, NONE, B_PAWN, B_PAWN, B_PAWN, INV,
INV, NONE, NONE, NONE, NONE, B_PAWN, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, W_KNIGHT, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, INV,
INV, W_ROOK, W_KNIGHT, W_BISHOP, W_QUEEN, W_KING, W_BISHOP, W_KNIGHT, W_ROOK, INV,
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV
};
const std::vector<int> KNIGHT_EXTRA2_MOVES = {
B3, F3, F5, E6, C6, B5
};
const std::vector<std::string> KNIGHT_EXTRA2_NOTATION = {
};
const std::array<PieceType, 120> EXTRA3_BOARD = {
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,
INV, B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK, INV,
INV, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, W_KNIGHT, NONE, NONE, NONE, NONE, INV,
INV, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, INV,
INV, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, INV,
INV, W_ROOK, W_KNIGHT, W_BISHOP, W_QUEEN, W_KING, W_BISHOP, W_KNIGHT, W_ROOK, INV,
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,
INV,INV,INV,INV,INV,INV,INV,INV,INV,INV
};

Loading…
Cancel
Save