Fix board type. Add pos_to_pair, pair_to_pos functions

master
Tait Hoyem 5 years ago
parent e3d2b4804d
commit 8cd46542ef

@ -1,23 +1,46 @@
#include "functions.h"
#include <stdexcept>
#include <cmath>
#include <iostream>
#include <stdio.h>
// TODO implement functions.h functions.
// NOTE tests will NOT run unless you implement these functions.
std::pair<int, int> pos_to_pair(Position pn){
// TODO replace with real code. Just implementing for running the tests.
return std::make_pair(-1, -1);
int x,y = 0;
for (x = pn; x >= 8; x = x-8){
++y;
}
return std::make_pair(x, std::abs(y-7));
}
// TODO find way to make function arbitary to board size as to allow wide game chess variants. Do much later. Not important now.
Position pair_to_pos(std::pair<int, int> pr){
return Position::A1;
if (pr.first > 7 || pr.first < 0
|| pr.second > 7 || pr.second < 0) {
throw std::invalid_argument("Cannot use any pairs with values > 7 or < 0.");
}
int int_val = std::abs(pr.second - 7)*8 + pr.first;
if (int_val > 0 && int_val < 64) {
return static_cast<Position>(int_val);
} else {
throw std::invalid_argument("Something went terribly wrong. x and y < 8 && x and y > 0 but abs(y-7)*8 + x < 0 or >= 64");
}
}
std::vector<Position> get_possible_movers(Position pn, std::vector<PieceType> board){
std::vector<Position> get_possible_movers(Position pn, std::array<PieceType, 64> board){
std::vector<Position> pns = {Position::A1};
return pns;
}
std::vector<Position> get_possible_moves(Position pn, std::vector<PieceType> board){
std::vector<Position> get_possible_moves(Position pn, std::array<PieceType, 64> board){
std::vector<Position> pns = {Position::A1};
return pns;
}
std::array<PieceType, 64> dumb_move(Position from, Position to, std::array<PieceType, 64> board){
PieceType piece = board[from];
board[to] = piece;
board[from] = PieceType::NONE;
return board;
}

@ -12,8 +12,12 @@ 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);
std::vector<Position> get_possible_movers(Position pn, std::array<PieceType, 64> 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);
std::vector<Position> get_possible_moves(Position pn, std::array<PieceType, 64> pt);
// Dumb function to do board moves.
// Does NOT check for valid moves. Only moves PieceType of Pos1 to Pos2, then replaces Pos1 with Piecetype::NONE
std::array<PieceType, 64> dumb_move(Position from, Position to, std::array<PieceType, 64> board);

Loading…
Cancel
Save