Redo tracking system. Add tests

master
Tait Hoyem 5 years ago
parent ca1e134755
commit 7e03a7c085

@ -1,13 +0,0 @@
class Bishop
{
public:
double points = 3;
bool status;
bool white = true;
static std::string piece() { return "B"; }
std::string player()
{
if (white == true) { return "w"; }
else { return "b"; }
}
};

@ -1,14 +0,0 @@
class King
{
public:
double points = 0;
bool status;
bool white = true;
static std::string piece() { return "K"; }
std::string player()
{
if (white == true) { return "w"; }
else { return "b"; }
}
};

@ -1,14 +0,0 @@
class Knight
{
public:
double points = 3;
bool status;
bool white = true;
static std::string piece() { return "K"; }
std::string player()
{
if (white == true) { return "w"; }
else { return "b"; }
}
};

@ -1,14 +0,0 @@
class Pawn
{
public:
double points = 1;
bool status;
bool white = true;
static std::string piece() { return "P"; }
std::string player()
{
if (white == true) { return "w"; }
else { return "b"; }
}
};

@ -1,14 +0,0 @@
class Queen
{
public:
double points = 9;
bool status;
bool white = true;
static std::string piece() { return "Q"; }
std::string player()
{
if (white == true) { return "w"; }
else { return "b"; }
}
};

@ -1,14 +0,0 @@
class Rook
{
public:
double points = 5;
bool status;
bool white = true;
static std::string piece() { return "R"; }
std::string player()
{
if (white == true) { return "w"; }
else { return "b"; }
}
};

@ -0,0 +1,44 @@
// Access with PieceType::ANY_FOLLOWING_OPTION
enum PieceType {
NONE,
W_PAWN,
W_KNIGHT,
W_BISHOP,
W_ROOK,
W_QUEEN,
W_KING,
B_PAWN,
B_KNIGHT,
B_BISHOP,
B_ROOK,
B_QUEEN,
B_KING
};
// Access with CHESS_CHARS[PieceType] to get the character for the piece.
const char CHESS_CHARS[13] = {
' ',
'p', 'n', 'b', 'r', 'q', 'k',
'P', 'N', 'B', 'R', 'Q', 'K'
};
// This allows reference to DEFAULT_BOARD (or more likely, a copy of it.
enum Position{
A1, B1, C1, D1, E1, F1, G1, H1, A2, B2, C2, D2, E2, F2, G2, H2, A3, B3, C3, D3, E3, F3, G3, H3, A4, B4, C4, D4, E4, F4, G4, H4, A5, B5, C5, D5, E5, F5, G5, H5, A6, B6, C6, D6, E6, F6, G6, H6, A7, B7, C7, D7, E7, F7, G7, H7, A8, B8, C8, D8, E8, F8, G8, H8
};
// Access with normal ways of accessing an array.
// OR lie so DEFAULT_BOARD[Position::G1] would equal PieceType::W_KNIGHT
// TODO make function to convert x and y to board num, and vis versa.
const int DEFAULT_BOARD[64] = {
W_ROOK, W_KNIGHT, W_BISHOP, W_QUEEN, W_KING, W_BISHOP, W_KNIGHT, W_ROOK,
W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN,
B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK
};

@ -0,0 +1,13 @@
#include "functions.h"
// TODO implement functions.h functions.
// NOTE tests will NOT run unless you implement these functions.
pair<int, int> pos_to_pair(Position pn){
// TODO replace with real code. Just implementing for running the tests.
return make_pair(-1, -1);
}
Position pair_to_pos(pair<int, int> pr){
return Position::A1;
}

@ -0,0 +1,11 @@
#include "constants.h"
#include <utility>
using namespace std;
// Convert pair of x y coordinates to Position enum member.
// If pr contains values above 7, or below 0 it will fail with an InvalidArgument exception.
Position pair_to_pos(pair<int, int> pr);
// Convert a Position number into a pair of x y coordiinates
pair<int, int> pos_to_pair(Position pn);

@ -1,141 +1,18 @@
#include <iostream>
#include <stdio.h>
#include <string>
#include "chessPieces/rook.cpp"
#include "chessPieces/knight.cpp"
#include "chessPieces/bishop.cpp"
#include "chessPieces/queen.cpp"
#include "chessPieces/king.cpp"
#include "chessPieces/pawn.cpp"
#include "constants.h"
using namespace std;
class Chess
{
int board[64] = {0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0};
public:
string square(int x, string piece, string player)
{
if (board[x] == 1)
{
return "B-"+ player + piece +" ";
}
else
{
return "W-"+ player + piece +" ";
}
}
};
int main()
{
Chess chs;
Rook rb1, rb2;
rb1.white = false;
rb2.white = false;
Knight kb1, kb2;
kb1.white = false;
kb2.white = false;
Bishop bb1, bb2;
bb1.white = false;
bb2.white = false;
Queen Qb;
Qb.white = false;
King Kb;
Kb.white = false;
Pawn pb1,pb2,pb3,pb4,pb5,pb6,pb7,pb8;
pb1.white = false;
pb2.white = false;
pb3.white = false;
pb4.white = false;
pb5.white = false;
pb6.white = false;
pb7.white = false;
pb8.white = false;
// See constants.h for CHESS_CHARS, and DEFAULT_BOARD
Rook rw1, rw2;
rw1.white = true;
rw2.white = true;
Knight kw1, kw2;
kw1.white = true;
kw2.white = true;
Bishop bw1, bw2;
bw1.white = true;
bw2.white = true;
Queen Qw;
Qw.white = true;
King Kw;
Kw.white = true;
Pawn pw1,pw2,pw3,pw4,pw5,pw6,pw7,pw8;
pw1.white = true;
pw2.white = true;
pw3.white = true;
pw4.white = true;
pw5.white = true;
pw6.white = true;
pw7.white = true;
pw8.white = true;
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
int sqNum = (8 * i) + j;
if (sqNum == 0) { cout << chs.square(sqNum, rb1.player(), rb1.piece()); }
else if (sqNum == 1) { cout << chs.square(sqNum, kb1.player(), kb1.piece()); }
else if (sqNum == 2) { cout << chs.square(sqNum, bb1.player(), bb1.piece()); }
else if (sqNum == 3) { cout << chs.square(sqNum, Qb.player() , Qb.piece()); }
else if (sqNum == 4) { cout << chs.square(sqNum, Kb.player() , Kb.piece()); }
else if (sqNum == 5) { cout << chs.square(sqNum, bb2.player(), bb2.piece()); }
else if (sqNum == 6) { cout << chs.square(sqNum, kb2.player(), kb2.piece()); }
else if (sqNum == 7) { cout << chs.square(sqNum, rb2.player(), rb2.piece()); }
else if (sqNum == 8) { cout << chs.square(sqNum, pb1.player(), pb1.piece()); }
else if (sqNum == 9) { cout << chs.square(sqNum, pb2.player(), pb2.piece()); }
else if (sqNum == 10) { cout << chs.square(sqNum, pb3.player(), pb3.piece()); }
else if (sqNum == 11) { cout << chs.square(sqNum, pb4.player(), pb4.piece()); }
else if (sqNum == 12) { cout << chs.square(sqNum, pb5.player(), pb5.piece()); }
else if (sqNum == 13) { cout << chs.square(sqNum, pb6.player(), pb6.piece()); }
else if (sqNum == 14) { cout << chs.square(sqNum, pb7.player(), pb7.piece()); }
else if (sqNum == 15) { cout << chs.square(sqNum, pb8.player(), pb8.piece()); }
else if (sqNum == 63) { cout << chs.square(sqNum, rw1.player(), rw1.piece()); }
else if (sqNum == 62) { cout << chs.square(sqNum, kw1.player(), kw1.piece()); }
else if (sqNum == 61) { cout << chs.square(sqNum, bw1.player(), bw1.piece()); }
else if (sqNum == 59) { cout << chs.square(sqNum, Qw.player() , Qw.piece()); }
else if (sqNum == 60) { cout << chs.square(sqNum, Kw.player() , Kw.piece()); }
else if (sqNum == 58) { cout << chs.square(sqNum, bw2.player(), bw2.piece()); }
else if (sqNum == 57) { cout << chs.square(sqNum, kw2.player(), kw2.piece()); }
else if (sqNum == 56) { cout << chs.square(sqNum, rw2.player(), rw2.piece()); }
else if (sqNum == 55) { cout << chs.square(sqNum, pw1.player(), pw1.piece()); }
else if (sqNum == 54) { cout << chs.square(sqNum, pw2.player(), pw2.piece()); }
else if (sqNum == 53) { cout << chs.square(sqNum, pw3.player(), pw3.piece()); }
else if (sqNum == 52) { cout << chs.square(sqNum, pw4.player(), pw4.piece()); }
else if (sqNum == 51) { cout << chs.square(sqNum, pw5.player(), pw5.piece()); }
else if (sqNum == 50) { cout << chs.square(sqNum, pw6.player(), pw6.piece()); }
else if (sqNum == 49) { cout << chs.square(sqNum, pw7.player(), pw7.piece()); }
else if (sqNum == 48) { cout << chs.square(sqNum, pw8.player(), pw8.piece()); }
else { cout << chs.square(sqNum, " ", " "); }
}
cout << endl;
}
using namespace std;
return 0;
int main(){
for (int i = 0; i < 8; ++i){
for (int j = 0; j < 8; ++j){
int ix = (i*8) + j;
cout << CHESS_CHARS[DEFAULT_BOARD[ix]];
}
cout << endl;
}
}

@ -0,0 +1,4 @@
defualt: build
build:
g++ -I../src/ -o tests.out ../src/functions.cpp tests_main.cpp

File diff suppressed because it is too large Load Diff

@ -0,0 +1,24 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <string>
#include <sstream>
#include <tuple>
#include <functions.h>
// For some retarted reason, I need to implement the printing of pairs, otherwise in the test outputs they show up as {?}
// TODO implement that functionality.
TEST_CASE("Test convert method to go from X and Y to board position", "[pair_to_pos]"){
CHECK(pair_to_pos(make_pair(3, 5)) == Position::C3);
CHECK(pair_to_pos(make_pair(7, 0)) == Position::H8);
CHECK(pair_to_pos(make_pair(0, 0)) == Position::A8);
CHECK(pair_to_pos(make_pair(7, 7)) == Position::H1);
CHECK_THROWS(pair_to_pos(make_pair(8, 2)));
CHECK_THROWS(pair_to_pos(make_pair(-1, 1)));
}
TEST_CASE("Test convert method to go from a board position to an x and y", "[pos_to_pair]"){
CHECK(pos_to_pair(Position::A3) == make_pair(0, 5));
CHECK(pos_to_pair(Position::B2) == make_pair(1, 1));
CHECK(pos_to_pair(Position::H8) == make_pair(0, 7));
}
Loading…
Cancel
Save