aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzedarider <ymherklotz@gmail.com>2017-01-17 15:42:18 +0000
committerzedarider <ymherklotz@gmail.com>2017-01-17 15:42:18 +0000
commitf0799aef3ff8c4a8e8ffea79c963b8f128c462b9 (patch)
treeef496e7326148dd29d555eb017155fcb7af234f8
parent088b948122cbf24dd9dc1dfedf4be2724bab2157 (diff)
downloadChessAI-f0799aef3ff8c4a8e8ffea79c963b8f128c462b9.tar.gz
ChessAI-f0799aef3ff8c4a8e8ffea79c963b8f128c462b9.zip
fixed the chess board and added empty pieces to fill holes, also added forward declarations
-rw-r--r--include/board_state_parser.hpp2
-rw-r--r--include/chess_board.hpp1
-rw-r--r--include/chess_piece.hpp20
-rw-r--r--include/chess_tester.hpp105
-rw-r--r--src/chess_board.cpp7
-rw-r--r--src/chess_piece.cpp9
-rw-r--r--src/test_bench.cpp4
7 files changed, 95 insertions, 53 deletions
diff --git a/include/board_state_parser.hpp b/include/board_state_parser.hpp
index 39286d4..d4940db 100644
--- a/include/board_state_parser.hpp
+++ b/include/board_state_parser.hpp
@@ -20,6 +20,8 @@
#include <fstream>
namespace ymhChessAI {
+class BoardStateParser;
+
typedef std::vector<std::string> boardStateData;
class BoardStateParser {
diff --git a/include/chess_board.hpp b/include/chess_board.hpp
index d3516fc..c277618 100644
--- a/include/chess_board.hpp
+++ b/include/chess_board.hpp
@@ -28,6 +28,7 @@ class ChessBoard {
public:
ChessBoard();
+ void populateBoard();
void printBoard();
protected:
private:
diff --git a/include/chess_piece.hpp b/include/chess_piece.hpp
index 5febc99..e7f2f79 100644
--- a/include/chess_piece.hpp
+++ b/include/chess_piece.hpp
@@ -20,6 +20,16 @@
// names
namespace ymhChessAI {
+enum class Colour;
+class ChessPiece;
+class King;
+class Queen;
+class Rook;
+class Bishop;
+class Knight;
+class Pawn;
+class EmptyPiece;
+
// Colour enum class so that we can have the colours in the Chess Piece and not
// using normal enums because of undefined errors
@@ -127,6 +137,16 @@ public:
protected:
private:
};
+
+class EmptyPiece : public ChessPiece {
+public:
+ EmptyPiece();
+ EmptyPiece(const int& x, const int& y, const Colour& colour);
+
+ virtual void move(const int& x, const int& y);
+protected:
+private:
+};
}
#endif
diff --git a/include/chess_tester.hpp b/include/chess_tester.hpp
index d2994ad..f121ec8 100644
--- a/include/chess_tester.hpp
+++ b/include/chess_tester.hpp
@@ -11,79 +11,78 @@
#include <algorithm>
#include <iostream>
+namespace ymhChessAI {
struct tested_pieces {
- std::string piece_name;
- int num_passed;
- int num_failed;
-
- friend bool operator==(const tested_pieces& tp1, const tested_pieces& tp2) {
- if(tp1.piece_name == tp2.piece_name) {
- return true;
- }
- return false;
- }
-
- friend bool operator<(const tested_pieces& tp1, const tested_pieces& tp2) {
- if(tp1.piece_name < tp2.piece_name) {
- return true;
- }
- return false;
- }
+ std::string piece_name;
+ int num_passed;
+ int num_failed;
+
+ friend bool operator==(const tested_pieces& tp1, const tested_pieces& tp2) {
+ if(tp1.piece_name == tp2.piece_name)
+ return true;
+ return false;
+ }
+
+ friend bool operator<(const tested_pieces& tp1, const tested_pieces& tp2) {
+ if(tp1.piece_name < tp2.piece_name)
+ return true;
+ return false;
+ }
};
class chess_tester {
-
public:
- // sets all the initial values for the tester
- chess_tester();
+ // sets all the initial values for the tester
+ chess_tester();
- // begins the test suite so that this class can record the results and
- // analyse them
- void chess_begin_test_suite();
+ // begins the test suite so that this class can record the results and
+ // analyse them
+ void chess_begin_test_suite();
- // begins the test
- int chess_begin_test(std::string test_name);
+ // begins the test
+ int chess_begin_test(std::string test_name);
- // records the result of the test
- void chess_end_test(int test_id, bool passed);
+ // records the result of the test
+ void chess_end_test(int test_id, bool passed);
- // analyses the results and prints them out
- void chess_end_test_suite();
+ // analyses the results and prints them out
+ void chess_end_test_suite();
- // see if the test is acceptable
- bool is_in_arr(const std::string& test_piece) const;
+ // see if the test is acceptable
+ bool is_in_arr(const std::string& test_piece) const;
- // see if test is in vector
- bool is_in_vec(const tested_pieces& piece) const;
+ // see if test is in vector
+ bool is_in_vec(const tested_pieces& piece) const;
private:
- // checks if the test suite is running
- bool ts_begin;
+ // checks if the test suite is running
+ bool ts_begin;
- // list of pieces to test
- const std::string chess_test_pieces[CHESS_TEST_SIZE] = {
- "<INTERNAL>",
- "PAWN",
- "ROOK",
- "KNIGHT",
- "BISHOP",
- "QUEEN",
- "KING"
- };
+ // list of pieces to test
+ const std::string chess_test_pieces[CHESS_TEST_SIZE] = {
+ "<INTERNAL>",
+ "PAWN",
+ "ROOK",
+ "KNIGHT",
+ "BISHOP",
+ "QUEEN",
+ "KING"
+ };
- // vector that contains the tested pieces
- std::vector<tested_pieces> test_piece;
+ // vector that contains the tested pieces
+ std::vector<tested_pieces> test_piece;
- // the test_id of the current instruction
- int test_id;
+ // the test_id of the current instruction
+ int test_id;
- // the test id of the test that has been started
- int test_id_test;
+ // the test id of the test that has been started
+ int test_id_test;
- // the current test that is being tested
- std::string current_test;
+ // the current test that is being tested
+ std::string current_test;
};
+}
#endif
diff --git a/src/chess_board.cpp b/src/chess_board.cpp
index 1eaa7d4..3432b52 100644
--- a/src/chess_board.cpp
+++ b/src/chess_board.cpp
@@ -18,6 +18,13 @@ using namespace ymhChessAI;
ChessBoard::ChessBoard() {
+ for(unsigned i = 0; i < BOARD_SIZE; ++i)
+ board.emplace_back(new EmptyPiece);
+}
+
+void ChessBoard::populateBoard() {
+ for(auto&& piece : board)
+ piece = chessPiecePtr(new Knight);
}
void ChessBoard::printBoard() {
diff --git a/src/chess_piece.cpp b/src/chess_piece.cpp
index 626377e..d4d14e6 100644
--- a/src/chess_piece.cpp
+++ b/src/chess_piece.cpp
@@ -21,3 +21,12 @@ ChessPiece::ChessPiece() : m_x(0), m_y(0), m_colour(Colour::White) {
ChessPiece::ChessPiece(const int& x, const int& y, const Colour& colour) : m_x(x), m_y(y), m_colour(colour) {
}
+
+EmptyPiece::EmptyPiece() : ChessPiece() {
+}
+
+EmptyPiece::EmptyPiece(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) {
+}
+
+void EmptyPiece::move(const int& x, const int& y) {
+}
diff --git a/src/test_bench.cpp b/src/test_bench.cpp
index a68b60c..b1fe4ba 100644
--- a/src/test_bench.cpp
+++ b/src/test_bench.cpp
@@ -25,6 +25,10 @@ int main(int argc, char **argv) {
cout << "Program name: " << argv[0] << endl;
cout << "Arguments: " << argc - 1 << endl;
+ ChessBoard cb;
+ cb.populateBoard();
+ cb.printBoard();
+
cout << endl << "====== Executed Successfully ======" << endl;
return 0;