Change board from int[64] to vector<int, 64>

master
Tait Hoyem 5 years ago
parent dd3709eb1b
commit 5725803920

@ -1,3 +1,4 @@
#include <vector>
// Access with PieceType::ANY_FOLLOWING_OPTION
enum PieceType {
@ -31,7 +32,7 @@ enum Position{
// 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] = {
const std::vector<PieceType> DEFAULT_BOARD = {
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,
@ -42,6 +43,7 @@ const int DEFAULT_BOARD[64] = {
B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK
};
namespace Rank{
const int A[8] = {A1, A2, A3, A4, A5, A6, A7, A8};
const int B[8] = {B1, B2, B3, B4, B5, B6, B7, B8};

@ -3,11 +3,21 @@
// TODO implement functions.h functions.
// NOTE tests will NOT run unless you implement these functions.
pair<int, int> pos_to_pair(Position pn){
std::pair<int, int> pos_to_pair(Position pn){
// TODO replace with real code. Just implementing for running the tests.
return make_pair(-1, -1);
return std::make_pair(-1, -1);
}
Position pair_to_pos(pair<int, int> pr){
Position pair_to_pos(std::pair<int, int> pr){
return Position::A1;
}
std::vector<Position> get_possible_movers(Position pn, std::vector<PieceType> board){
std::vector<Position> pns = {Position::A1};
return pns;
}
std::vector<Position> get_possible_moves(Position pn, std::vector<PieceType> board){
std::vector<Position> pns = {Position::A1};
return pns;
}

@ -1,11 +1,19 @@
#include "constants.h"
#include <utility>
using namespace std;
#include <vector>
// 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);
Position pair_to_pos(std::pair<int, int> pr);
// Convert a Position number into a pair of x y coordiinates
pair<int, int> pos_to_pair(Position pn);
std::pair<int, int> pos_to_pair(Position pn);
// Get all positions of pieces which can move to this square
// This may require helper functions for each individual peice.
// TODO rename to something less stupid.
std::vector<Position> get_possible_movers(Position pn, std::vector<PieceType> pt);
// Get all possible moved for piece in Position pn.
// This may require helper functions for each individual piece.
std::vector<Position> get_possible_moves(Position pn, std::vector<PieceType> pt);

@ -1,24 +0,0 @@
#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