diff options
author | zedarider <ymherklotz@gmail.com> | 2016-11-08 23:33:34 +0000 |
---|---|---|
committer | zedarider <ymherklotz@gmail.com> | 2016-11-08 23:33:34 +0000 |
commit | c57aed1a546f0dc0a6efcb06d10125e2dbd34d60 (patch) | |
tree | 1696095c58a30f185c64f53fdfe31e8a15c0750b | |
parent | 451678aa0ac08581d14442967432e4383e1db3f3 (diff) | |
download | ChessAI-c57aed1a546f0dc0a6efcb06d10125e2dbd34d60.tar.gz ChessAI-c57aed1a546f0dc0a6efcb06d10125e2dbd34d60.zip |
managed and going to merge
-rwxr-xr-x | bin/chess_ai | bin | 237648 -> 237744 bytes | |||
-rw-r--r-- | include/chess_ai.hpp | 11 | ||||
-rw-r--r-- | src/chess_board.cpp | 56 | ||||
-rw-r--r-- | src/chess_piece.cpp | 6 |
4 files changed, 36 insertions, 37 deletions
diff --git a/bin/chess_ai b/bin/chess_ai Binary files differindex 90f1c95..b938b9f 100755 --- a/bin/chess_ai +++ b/bin/chess_ai diff --git a/include/chess_ai.hpp b/include/chess_ai.hpp index 8c6eb50..efde215 100644 --- a/include/chess_ai.hpp +++ b/include/chess_ai.hpp @@ -102,15 +102,12 @@ iterator vector_iterator; // move a piece from coordinates void move_piece(unsigned x, unsigned y); + void move_piece(unsigned orig_x, unsigned orig_y, unsigned dest_x, + unsigned dest_y); + void move_piece(chess_piece piece, unsigned x, unsigned y); - // find a piece on the board using coordinates - void find_piece(unsigned x, unsigned y); - - // iterate through the list with point - void iterate_board(chess_piece piece, square_iterator& it); - // iterate through the list and return the pointer to change - void iterate_board(unsigned x, unsigned y, square_iterator& it); + square_iterator& iterate_board(square_iterator& it, unsigned x, unsigned y); diff --git a/src/chess_board.cpp b/src/chess_board.cpp index c700ecb..b46a284 100644 --- a/src/chess_board.cpp +++ b/src/chess_board.cpp @@ -106,48 +106,42 @@ void chess_ai::chess_board::print_board() { } void chess_ai::chess_board::set_piece(chess_piece piece) { - unsigned vec_index, sqr_index; - for(vector_iterator it_vec = grid.begin(); it_vec != grid.end(); ++it_vec) { - for(square_iterator it_sqr = (*it_vec).begin(); - it_sqr != (*it_vec).end(); ++it_sqr) { - vec_index = it_vec - grid.begin(); - sqr_index = it_sqr - (*it_vec).begin(); - - if(vec_index == piece.y && sqr_index == piece.x) { - *it_sqr = piece; - } - } - } + square_iterator it_sqr; + *iterate_board(it_sqr, piece.x, piece.y) = piece; } void chess_ai::chess_board::remove_piece(chess_piece piece) { - square_iterator it_sqr; - iterate_board(piece.x, piece.y, it_sqr); - *it_sqr = piece; + remove_piece(piece.x, piece.y); } void chess_ai::chess_board::remove_piece(unsigned x, unsigned y) { - unsigned vec_index, sqr_index; - for(vector_iterator it_vec = grid.begin(); it_vec != grid.end(); ++it_vec) { - for(square_iterator it_sqr = (*it_vec).begin(); - it_sqr != (*it_vec).end(); ++it_sqr) { - vec_index = it_vec - grid.begin(); - sqr_index = it_sqr - (*it_vec).begin(); - - if(vec_index == y && sqr_index == x) { - chess_piece empty_piece; - *it_sqr = empty_piece; - } - } - } + square_iterator it_sqr; + *iterate_board(it_sqr, x, y) = chess_piece(); } void chess_ai::chess_board::move_piece(chess_piece piece) { + move_piece(piece.x, piece.y); +} + +void chess_ai::chess_board::move_piece(unsigned x, unsigned y) { + square_iterator it; + iterate_board(it, x, y); + + ++(*it); +} + +void chess_ai::chess_board::move_piece(chess_ai::chess_piece piece, + unsigned x, unsigned y) { + move_piece(piece.x, piece.y, x, y); +} + +void chess_ai::chess_board::move_piece(unsigned orig_x, unsigned orig_y, + unsigned dest_x, unsigned dest_y) { } -void chess_ai::chess_board::iterate_board(unsigned x, unsigned y, - square_iterator& it) { +chess_ai::square_iterator& chess_ai::chess_board::iterate_board( + square_iterator& it, unsigned x, unsigned y) { unsigned vec_index, sqr_index; for(vector_iterator it_vec = grid.begin(); it_vec != grid.end(); ++it_vec) { for(square_iterator it_sqr = (*it_vec).begin(); @@ -157,7 +151,9 @@ void chess_ai::chess_board::iterate_board(unsigned x, unsigned y, if(vec_index == y && sqr_index == x) { it = it_sqr; + return it; } } } + return it; } diff --git a/src/chess_piece.cpp b/src/chess_piece.cpp index bab3612..44dfaa5 100644 --- a/src/chess_piece.cpp +++ b/src/chess_piece.cpp @@ -55,6 +55,12 @@ chess_ai::chess_piece& chess_ai::chess_piece::operator==(const chess_piece& } chess_ai::chess_piece& chess_ai::chess_piece::operator++() { + if(type == pawn) { + if(colour == white) + --y; + else + ++y; + } return *this; } |