aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bishop.cpp26
-rw-r--r--src/board_state_parser.cpp61
-rw-r--r--src/chess_board.cpp263
-rw-r--r--src/chess_piece.cpp69
-rw-r--r--src/chess_tester.cpp186
-rw-r--r--src/king.cpp28
-rw-r--r--src/knight.cpp28
-rw-r--r--src/main.cpp.bck23
-rw-r--r--src/pawn.cpp44
-rw-r--r--src/queen.cpp26
-rw-r--r--src/rook.cpp26
-rw-r--r--src/test_bench.cpp44
12 files changed, 396 insertions, 428 deletions
diff --git a/src/bishop.cpp b/src/bishop.cpp
new file mode 100644
index 0000000..849db19
--- /dev/null
+++ b/src/bishop.cpp
@@ -0,0 +1,26 @@
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Bishop class implementation
+ *
+ */
+
+#include "chess_piece.hpp"
+
+using namespace ymhChessAI;
+
+
+Bishop::Bishop() : ChessPiece() {
+}
+
+Bishop::Bishop(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) {
+}
+
+void Bishop::move(const int& x, const int& y) {
+}
diff --git a/src/board_state_parser.cpp b/src/board_state_parser.cpp
new file mode 100644
index 0000000..288a491
--- /dev/null
+++ b/src/board_state_parser.cpp
@@ -0,0 +1,61 @@
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 15/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Implementation of the Board state class
+ *
+ */
+
+#include "board_state_parser.hpp"
+#include "chess_constats.hpp"
+
+using namespace ymhChessAI;
+
+
+BoardStateParser::BoardStateParser() : boardFile("res/default.board", std::ifstream::in) {
+}
+
+BoardStateParser::BoardStateParser(const std::string& boardFileName) : boardFile(boardFileName.c_str()) {
+}
+
+BoardStateParser::~BoardStateParser() {
+ boardFile.close();
+}
+
+void BoardStateParser::populateBoardState() {
+ std::string currentLine;
+
+ boardStateVector.reserve(ChessConstants::BOARD_SIZE);
+
+ if(!boardFile.is_open())
+ throw "Error: Can't open file";
+
+ while(getline(boardFile, currentLine))
+ boardStateVector[stringToInt(currentLine)] = getStateFromLine(currentLine);
+}
+
+unsigned BoardStateParser::stringToInt(const std::string& str) {
+ unsigned finalInt = 0;
+ bool foundWhiteSpace = false;
+
+ for(char character : str)
+ if(character == ' ')
+ foundWhiteSpace = true;
+ else if(!foundWhiteSpace && character >= '0' && character <= '9')
+ finalInt = finalInt * 10 + character - '0';
+
+ return finalInt;
+}
+
+std::string BoardStateParser::getStateFromLine(const std::string& str) {
+ std::string state;
+
+ state = str.substr(2, str.length() - 2);
+
+ return state;
+}
diff --git a/src/chess_board.cpp b/src/chess_board.cpp
index de21015..e0967ad 100644
--- a/src/chess_board.cpp
+++ b/src/chess_board.cpp
@@ -1,244 +1,43 @@
-#include "chess_ai.hpp"
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 14/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Chess Board class implementation
+ *
+ */
-chess_ai::chess_board::chess_board() : SIZE(CHESS_BOARD_SIZE) {
- init_board_vector();
-}
-
-chess_ai::chess_board::chess_board(board_state state) : SIZE(CHESS_BOARD_SIZE) {
- unsigned vec_index, sqr_index;
-
- init_board_vector();
-
- if(state == initial) {
-
- 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) {
- chess_piece piece;
-
- piece_colour colour;
+#include "chess_board.hpp"
+#include "chess_constants.hpp"
- if(vec_index < 3) {
- colour = black;
- } else {
- colour = white;
- }
+#include <iostream>
- vec_index = it_vec - grid.begin();
- sqr_index = it_sqr - (*it_vec).begin();
+using namespace ymhChessAI;
- if(vec_index == 1 || vec_index == 6) {
- piece.set_type(pawn);
- } else if(vec_index == 0 || vec_index == 7) {
- if(sqr_index == 0 || sqr_index == 7)
- piece.set_type(rook);
- else if(sqr_index == 1 || sqr_index == 6)
- piece.set_type(knight);
- else if(sqr_index == 2 || sqr_index == 5)
- piece.set_type(bishop);
- else if(sqr_index == 3)
- piece.set_type(queen);
- else if(sqr_index == 4)
- piece.set_type(king);
- }
-
- piece.set_colour(colour);
- piece.set_x(sqr_index);
- piece.set_y(vec_index);
-
- *it_sqr = piece;
- }
- }
- } else {
- for(auto& row : grid) {
- for(auto& square : row) {
- chess_piece piece;
- square = piece;
- }
- }
- }
-}
-
-chess_ai::chess_board::~chess_board() {}
-
-void chess_ai::chess_board::init_board_vector() {
- for(unsigned i = 0; i < SIZE; ++i) {
- std::vector<chess_ai::chess_piece> tmp_vec;
- for(unsigned j = 0; j < SIZE; ++j) {
- chess_piece piece;
- tmp_vec.push_back(piece);
- }
- grid.push_back(tmp_vec);
- }
+ChessBoard::ChessBoard() {
+ for(unsigned i = 0; i < ChessConstants::BOARD_SIZE; ++i)
+ board.emplace_back(new EmptyPiece);
}
-void chess_ai::chess_board::print_board() {
- std::cout << " |";
- for(unsigned i = 0; i < SIZE; ++i) {
- std::cout << "---|";
- }
- std::cout << std::endl << "8 |";
-
- for(unsigned y = 0; y < SIZE; ++y) {
- for(unsigned x = 0; x < SIZE; ++x) {
- std::cout << " " << grid[y][x].str() << " |";
- }
-
- std::cout << std::endl << " |";
-
-
- if(y == SIZE-1) {
- std::cout << "---+";
- for(unsigned i = 0; i < SIZE-2; ++i) {
- std::cout << "---+";
- }
- std::cout << "---|" << std::endl;
- } else {
- for(unsigned i = 0; i < SIZE-1; ++i) {
- std::cout << "---+";
- }
- std::cout << "---|" << std::endl;
- std::cout << 7-y << " |";
- }
- }
- std::cout << " a b c d e f g h" << std::endl;
-}
-
-chess_ai::chess_piece chess_ai::chess_board::at(unsigned x,
- unsigned y) {
-
- square_iterator it_sqr;
- chess_piece tmp_piece;
-
- tmp_piece = *iterate_board(it_sqr, x, y);
- return tmp_piece;
-}
-
-void chess_ai::chess_board::set_piece(chess_piece piece) {
- square_iterator it_sqr;
- *iterate_board(it_sqr, piece.x, piece.y) = piece;
-}
-
-void chess_ai::chess_board::set_piece(piece_type type, piece_colour colour,
- unsigned x, unsigned y) {
-
- chess_piece piece(type, colour, x, y);
- set_piece(piece);
-}
-
-void chess_ai::chess_board::remove_piece(chess_piece piece) {
- remove_piece(piece.x, piece.y);
-}
-
-void chess_ai::chess_board::remove_piece(unsigned x, unsigned y) {
- square_iterator it_sqr;
- *iterate_board(it_sqr, x, y) = chess_piece();
-}
-
-chess_ai::move_error chess_ai::chess_board::move_piece(chess_piece piece) {
- return move_piece(piece.x, piece.y);
-}
-
-chess_ai::move_error chess_ai::chess_board::move_piece(unsigned x, unsigned y) {
- square_iterator it;
- iterate_board(it, x, y);
-
- if(it->y < 7 && it->y > 0) {
- if(it->colour == white)
- return move_piece(x, y, x, y-1);
- return move_piece(x, y, x, y+1);
- }
- return move_error_IllegalMove;
-}
-
-chess_ai::move_error chess_ai::chess_board::move_piece
-(chess_ai::chess_piece piece, unsigned x, unsigned y) {
-
- return move_piece(piece.x, piece.y, x, y);
-}
-
-chess_ai::move_error chess_ai::chess_board::move_piece
-(unsigned orig_x, unsigned orig_y, unsigned dest_x, unsigned dest_y) {
-
- chess_piece taken;
- return move_piece(orig_x, orig_y, dest_x, dest_y, taken);
-}
-
-chess_ai::move_error chess_ai::chess_board::move_piece
-(unsigned orig_x, unsigned orig_y, unsigned dest_x, unsigned dest_y,
- chess_piece& taken_piece) {
-
- square_iterator it;
- square_iterator new_it;
-
- iterate_board(it, orig_x, orig_y);
- iterate_board(new_it, dest_x, dest_y);
-
- switch(it->type) {
- case pawn:
- return move_pawn(it, new_it, taken_piece);
- case rook:
- case knight:
- case bishop:
- case queen:
- case king:
- default:
- return move_error_IllegalMove;
- }
-}
-
-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();
- 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) {
- it = it_sqr;
- return it;
- }
- }
- }
- return it;
+bool ChessBoard::populateBoard() {
+ for(auto && piece : board)
+ piece = chessPiecePtr(new Knight);
+ return true;
}
-chess_ai::move_error chess_ai::chess_board::move_pawn
-(square_iterator it, square_iterator new_it, chess_piece& taken_piece) {
+bool ChessBoard::printBoard() {
+ int i = 0;
- chess_piece piece(it->type, it->colour, new_it->x, new_it->y);
+ for(auto && piece : board) {
+ std::cout << i << " ";
+ piece->move(1, 2);
+ ++i;
+ }
- if((new_it->y - it->y == 2 && it->y == 1) ||
- ((int)new_it->y - (int)it->y == -2 && it->y == 6) ||
- (new_it->y - it->y == 1 && piece.colour == black && it->y < 7) ||
- ((int)new_it->y - (int)it->y == -1 && piece.colour == white &&
- it->y > 0)) {
- if(new_it->x == it->x) {
- if(new_it->type == empty) {
- remove_piece(it->x, it->y);
- set_piece(piece);
- return move_Success;
- } else if(new_it->colour == it->colour) {
- return move_error_FriendlyPieceOnDestination;
- }
- return move_error_EnemyPieceOnDestination;
- } else if(new_it->x - it->x == 1 || (int)new_it->x - (int)it->x == -1) {
- if(new_it->colour != it->colour && new_it->colour != none) {
- taken_piece.set(new_it->type, new_it->colour, new_it->x,
- new_it->y);
- remove_piece(it->x, it->y);
- set_piece(piece);
- return move_Success;
- } else if(new_it->colour == it->colour) {
- return move_error_FriendlyPieceOnDestination;
- }
- }
- }
- return move_error_IllegalMove;
+ return true;
}
diff --git a/src/chess_piece.cpp b/src/chess_piece.cpp
index f73d4c1..33ce34f 100644
--- a/src/chess_piece.cpp
+++ b/src/chess_piece.cpp
@@ -1,63 +1,32 @@
-#include "chess_ai.hpp"
-
-chess_ai::chess_piece::chess_piece(piece_type type, piece_colour colour) :
- type(type), colour(colour) {
-
- if(colour == black) {
- y = 0;
- } else {
- y = 7;
- }
-
- if(type == king) {
- x = 4;
- } else {
- x = 3;
- }
-}
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Chess Piece class implementation
+ *
+ */
-chess_ai::chess_piece::chess_piece(piece_type type, piece_colour colour,
- unsigned x, unsigned y) :
- type(type), colour(colour), x(x), y(y) {}
+#include "chess_piece.hpp"
-chess_ai::chess_piece::~chess_piece() {}
+using namespace ymhChessAI;
-void chess_ai::chess_piece::set_type(piece_type type) {
- this->type = type;
-}
-void chess_ai::chess_piece::set_colour(piece_colour colour) {
- this->colour = colour;
+ChessPiece::ChessPiece() : m_x(0), m_y(0), m_colour(Colour::White) {
}
-void chess_ai::chess_piece::set_x(unsigned x) {
- this->x = x;
+ChessPiece::ChessPiece(const int& x, const int& y, const Colour& colour) : m_x(x), m_y(y), m_colour(colour) {
}
-void chess_ai::chess_piece::set_y(unsigned y) {
- this->y = y;
+EmptyPiece::EmptyPiece() : ChessPiece() {
}
-void chess_ai::chess_piece::set(piece_type type, piece_colour colour,
- unsigned x, unsigned y) {
- set_type(type);
- set_colour(colour);
- set_x(x);
- set_y(y);
+EmptyPiece::EmptyPiece(const int& x, const int& y) : ChessPiece(x, y, Colour::None) {
}
-std::string chess_ai::chess_piece::str() {
- if(type == empty)
- return " ";
- else if(type == pawn)
- return "p";
- else if(type == rook)
- return "r";
- else if(type == knight)
- return "n";
- else if(type == bishop)
- return "b";
- else if(type == queen)
- return "q";
- return "k";
+void EmptyPiece::move(const int& x, const int& y) {
}
diff --git a/src/chess_tester.cpp b/src/chess_tester.cpp
index 6f3745c..a8ec0b5 100644
--- a/src/chess_tester.cpp
+++ b/src/chess_tester.cpp
@@ -1,125 +1,119 @@
#include "chess_tester.hpp"
-chess_tester::chess_tester() : ts_begin(false) {
- srand(time(NULL));
+using namespace ymhChessAI;
- test_id = rand() % 0xffffffff;
- test_id_test = test_id;
+chess_tester::chess_tester() : ts_begin(false) {
+ srand(time(NULL));
+ test_id = rand() % 0xffffffff;
+ test_id_test = test_id;
}
void chess_tester::chess_begin_test_suite() {
- if(ts_begin) {
- fprintf(stderr, "Error: already started test suite\n");
- exit(1);
- }
+ if(ts_begin)
+ fprintf(stderr, "Error: already started test suite\n");
+ exit(1);
- ts_begin = true;
+ ts_begin = true;
}
int chess_tester::chess_begin_test(std::string test_name) {
- if(!ts_begin) {
- fprintf(stderr, "Error: the test suite hasn't been started yet\n");
- exit(1);
- }
+ if(!ts_begin) {
+ fprintf(stderr, "Error: the test suite hasn't been started yet\n");
+ exit(1);
+ }
- if(!is_in_arr(test_name)) {
- fprintf(stderr, "Error: the test name does not exist\n");
- exit(1);
- }
+ if(!is_in_arr(test_name)) {
+ fprintf(stderr, "Error: the test name does not exist\n");
+ exit(1);
+ }
- current_test = test_name;
+ current_test = test_name;
- test_id = rand() % 0xffffffff;
- test_id_test = test_id;
+ test_id = rand() % 0xffffffff;
+ test_id_test = test_id;
- return test_id;
+ return test_id;
}
void chess_tester::chess_end_test(int test_id, bool passed) {
- if(test_id != test_id_test) {
- fprintf(stderr , "Error: the test from before has not been ended\n");
- exit(1);
- }
-
- tested_pieces tmp;
- tmp.piece_name = current_test;
-
- if(passed) {
- tmp.num_passed = 1;
- tmp.num_failed = 0;
- } else {
- tmp.num_passed = 0;
- tmp.num_failed = 1;
- }
-
- if(test_piece.empty() || !is_in_vec(tmp)) {
- test_piece.push_back(tmp);
- } else {
- for(unsigned i = 0; i < test_piece.size(); ++i) {
- if(test_piece[i] == tmp) {
- if(passed) {
- test_piece[i].num_passed++;
- } else {
- test_piece[i].num_failed++;
- }
- }
- }
- }
+ if(test_id != test_id_test) {
+ fprintf(stderr, "Error: the test from before has not been ended\n");
+ exit(1);
+ }
+
+ tested_pieces tmp;
+ tmp.piece_name = current_test;
+
+ if(passed) {
+ tmp.num_passed = 1;
+ tmp.num_failed = 0;
+ } else {
+ tmp.num_passed = 0;
+ tmp.num_failed = 1;
+ }
+
+ if(test_piece.empty() || !is_in_vec(tmp)) {
+ test_piece.push_back(tmp);
+ } else {
+ for(unsigned i = 0; i < test_piece.size(); ++i) {
+ if(test_piece[i] == tmp) {
+ if(passed)
+ test_piece[i].num_passed++;
+ else
+ test_piece[i].num_failed++;
+ }
+ }
+ }
}
void chess_tester::chess_end_test_suite() {
- std::sort(test_piece.begin(), test_piece.end());
-
- int pieces_passed = 0;
- int pieces_partial = 0;
- int pieces_fail = 0;
-
- fprintf(stderr, "+-%10s-+-%5s-+-%6s-+-%8s-+\n", "----------", "-----",
- "------", "--------");
- fprintf(stderr, "| %10s | %5s | %6s | %8s |\n", "Piece ", "Total", "Passed",
- "Passed %");
- fprintf(stderr, "+-%10s-+-%5s-+-%6s-+-%8s-+\n", "----------", "-----",
- "------", "--------");
- for(unsigned i = 0; i < test_piece.size(); ++i) {
- fprintf(stderr, "| %10s | %5d | %6d | %7.3f%% |\n",
- test_piece[i].piece_name.c_str(), test_piece[i].num_passed +
- test_piece[i].num_failed, test_piece[i].num_passed,
- 100.0*(double)test_piece[i].num_passed /
- (double)(test_piece[i].num_passed + test_piece[i].num_failed));
-
- if(test_piece[i].num_passed == 0) {
- pieces_fail++;
- } else if(test_piece[i].num_failed == 0) {
- pieces_passed++;
- } else {
- pieces_partial++;
- }
- }
- fprintf(stderr, "+-%10s-+-%5s-+-%6s-+-%8s-+\n", "----------", "-----",
- "------", "--------");
-
- fprintf(stderr, "\nTotal pieces tested: %lu\n", test_piece.size());
- fprintf(stderr, "Passed: %d\n", pieces_passed);
- fprintf(stderr, "Partially working: %d\n", pieces_partial);
- fprintf(stderr, "Failed: %d\n", pieces_fail);
+ std::sort(test_piece.begin(), test_piece.end());
+
+ int pieces_passed = 0;
+ int pieces_partial = 0;
+ int pieces_fail = 0;
+
+ fprintf(stderr, "+-%10s-+-%5s-+-%6s-+-%8s-+\n", "----------", "-----",
+ "------", "--------");
+ fprintf(stderr, "| %10s | %5s | %6s | %8s |\n", "Piece ", "Total", "Passed",
+ "Passed %");
+ fprintf(stderr, "+-%10s-+-%5s-+-%6s-+-%8s-+\n", "----------", "-----",
+ "------", "--------");
+ for(unsigned i = 0; i < test_piece.size(); ++i) {
+ fprintf(stderr, "| %10s | %5d | %6d | %7.3f%% |\n",
+ test_piece[i].piece_name.c_str(), test_piece[i].num_passed +
+ test_piece[i].num_failed, test_piece[i].num_passed,
+ 100.0 * (double)test_piece[i].num_passed /
+ (double)(test_piece[i].num_passed + test_piece[i].num_failed));
+
+ if(test_piece[i].num_passed == 0)
+ pieces_fail++;
+ else if(test_piece[i].num_failed == 0)
+ pieces_passed++;
+ else
+ pieces_partial++;
+ }
+ fprintf(stderr, "+-%10s-+-%5s-+-%6s-+-%8s-+\n", "----------", "-----",
+ "------", "--------");
+
+ fprintf(stderr, "\nTotal pieces tested: %lu\n", test_piece.size());
+ fprintf(stderr, "Passed: %d\n", pieces_passed);
+ fprintf(stderr, "Partially working: %d\n", pieces_partial);
+ fprintf(stderr, "Failed: %d\n", pieces_fail);
}
bool chess_tester::is_in_arr(const std::string& test_piece) const {
- for(unsigned i = 0; i < CHESS_TEST_SIZE; ++i) {
- if(chess_test_pieces[i] == test_piece) {
- return true;
- }
- }
+ for(unsigned i = 0; i < CHESS_TEST_SIZE; ++i)
+ if(chess_test_pieces[i] == test_piece)
+ return true;
- return false;
+ return false;
}
bool chess_tester::is_in_vec(const tested_pieces& piece) const {
- for(unsigned i = 0; i < test_piece.size(); ++i) {
- if(test_piece[i] == piece) {
- return true;
- }
- }
- return false;
+ for(unsigned i = 0; i < test_piece.size(); ++i)
+ if(test_piece[i] == piece)
+ return true;
+ return false;
}
diff --git a/src/king.cpp b/src/king.cpp
new file mode 100644
index 0000000..1d297d3
--- /dev/null
+++ b/src/king.cpp
@@ -0,0 +1,28 @@
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * King class implementation
+ *
+ */
+
+#include "chess_piece.hpp"
+#include <iostream>
+
+using namespace ymhChessAI;
+
+
+King::King() : ChessPiece() {
+}
+
+King::King(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) {
+}
+
+void King::move(const int& x, const int& y) {
+ std::cout << "This is the king" << std::endl;
+}
diff --git a/src/knight.cpp b/src/knight.cpp
new file mode 100644
index 0000000..25e5ab9
--- /dev/null
+++ b/src/knight.cpp
@@ -0,0 +1,28 @@
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Knight class implementation
+ *
+ */
+
+#include "chess_piece.hpp"
+#include <iostream>
+
+using namespace ymhChessAI;
+
+
+Knight::Knight() : ChessPiece() {
+}
+
+Knight::Knight(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) {
+}
+
+void Knight::move(const int& x, const int& y) {
+ std::cout << "This is a Knight" << std::endl;
+}
diff --git a/src/main.cpp.bck b/src/main.cpp.bck
deleted file mode 100644
index 2fd9be2..0000000
--- a/src/main.cpp.bck
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
-
- description: This is the main file for the chess_ai
-
- author: Yann Herklotz <ymherklotz@gmail.com>
- date created: DD-MM-YYYY
-
- */
-
-#include "chess_ai.hpp"
-#include "chess_tester.hpp"
-
-#include <iostream>
-
-using namespace std;
-using namespace chess_ai;
-
-int main(int argc, char** argv) {
- (void)argc;
- (void)argv;
-
- return 0;
-}
diff --git a/src/pawn.cpp b/src/pawn.cpp
new file mode 100644
index 0000000..5c5f1f6
--- /dev/null
+++ b/src/pawn.cpp
@@ -0,0 +1,44 @@
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Pawn class implementation, checking if there is a piece in the way of the
+ * one that is currently moving will be the chess boards concern
+ *
+ * Update: Checking if a piece is in the way will be the concern of this class
+ * because the move function has to perform the whole move.
+ *
+ */
+
+#include "chess_piece.hpp"
+#include "chess_constants.hpp"
+
+#include <cmath>
+
+using namespace ymhChessAI;
+
+
+Pawn::Pawn() : ChessPiece() {
+}
+
+Pawn::Pawn(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) {
+}
+
+void Pawn::move(const int& x, const int& y) {
+ int move_length = y - (int)m_y;
+
+ // First check what colour the pawn is
+ if(m_colour == Colour::White) {
+ // if this condition is met the pawn can move
+ if(move_length == -2 && m_y == ChessConstants::WHITE_PAWN_ROW) {
+ // we now have to check if there is a piece in between the pawn and
+ // it's desination
+ }
+ } else {
+ }
+}
diff --git a/src/queen.cpp b/src/queen.cpp
new file mode 100644
index 0000000..897237a
--- /dev/null
+++ b/src/queen.cpp
@@ -0,0 +1,26 @@
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Queen class implementation
+ *
+ */
+
+#include "chess_piece.hpp"
+
+using namespace ymhChessAI;
+
+
+Queen::Queen() : ChessPiece() {
+}
+
+Queen::Queen(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) {
+}
+
+void Queen::move(const int& x, const int& y) {
+}
diff --git a/src/rook.cpp b/src/rook.cpp
new file mode 100644
index 0000000..cd72029
--- /dev/null
+++ b/src/rook.cpp
@@ -0,0 +1,26 @@
+/*
+ *
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Rook class implementation
+ *
+ */
+
+#include "chess_piece.hpp"
+
+using namespace ymhChessAI;
+
+
+Rook::Rook() : ChessPiece() {
+}
+
+Rook::Rook(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) {
+}
+
+void Rook::move(const int& x, const int& y) {
+}
diff --git a/src/test_bench.cpp b/src/test_bench.cpp
index 8c79568..b1fe4ba 100644
--- a/src/test_bench.cpp
+++ b/src/test_bench.cpp
@@ -1,45 +1,35 @@
/*
*
- * description: This is the test_bench file for the chess_ai
+ * author: Yann Herklotz
+ * username: ymherklotz
+ * email: ymherklotz@gmail.com
+ * date created: 13/01/17
*
- * author: Yann Herklotz <ymherklotz@gmail.com>
- * date created: DD-MM-YYYY
+ * -----------------------------------------------------------------------------
+ *
+ * Main file that tests the chess ai
*
*/
-#include "chess_ai.hpp"
#include "chess_tester.hpp"
+#include "chess_piece.hpp"
+#include "chess_board.hpp"
+#include "board_state_parser.hpp"
#include <iostream>
using namespace std;
-using namespace chess_ai;
+using namespace ymhChessAI;
int main(int argc, char **argv) {
- int test_id;
- bool passed;
-
- chess_tester test_bench;
-
- chess_board empty_board(clear);
- chess_board initial_board(initial);
-
- test_bench.chess_begin_test_suite();
+ cout << "Program name: " << argv[0] << endl;
+ cout << "Arguments: " << argc - 1 << endl;
- test_id = test_bench.chess_begin_test("PAWN");
- chess_piece piece(pawn, white, 1, 6);
- empty_board.set_piece(piece);
- empty_board.print_board();
- cout << empty_board.move_piece(1, 6, 1, 4) << endl;
- piece.set(pawn, white, 1, 4);
- if(empty_board.at(1, 4) == piece)
- passed = true;
- else
- passed = false;
- empty_board.print_board();
- test_bench.chess_end_test(test_id, passed);
+ ChessBoard cb;
+ cb.populateBoard();
+ cb.printBoard();
- test_bench.chess_end_test_suite();
+ cout << endl << "====== Executed Successfully ======" << endl;
return 0;
}