Merge branch 'beccadev'
This commit is contained in:
commit
290c8aee2d
6 changed files with 27 additions and 31 deletions
25
Board.cpp
25
Board.cpp
|
@ -219,8 +219,8 @@ string Board::boardToString(){
|
||||||
Board Board::move(moves m){
|
Board Board::move(moves m){
|
||||||
int row = m.row;
|
int row = m.row;
|
||||||
int column = m.column;
|
int column = m.column;
|
||||||
|
|
||||||
Piece* piece;
|
Piece* piece;
|
||||||
|
|
||||||
if (isPiece(row, column))
|
if (isPiece(row, column))
|
||||||
piece = getPiece(row, column);
|
piece = getPiece(row, column);
|
||||||
|
|
||||||
|
@ -231,11 +231,13 @@ Board Board::move(moves m){
|
||||||
|
|
||||||
if (piece->getType() != turn) {
|
if (piece->getType() != turn) {
|
||||||
cout<<"ERROR: attempting to move the wrong side's piece.\n";
|
cout<<"ERROR: attempting to move the wrong side's piece.\n";
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
if(isThisMovePossible(row, column, m.moveType))
|
if(isThisMovePossible(row, column, m.moveType))
|
||||||
{
|
{
|
||||||
|
record.push_back(*this);
|
||||||
if (m.moveType == "FWD") {
|
if (m.moveType == "FWD") {
|
||||||
piece->moveFwd();
|
piece->moveFwd();
|
||||||
}
|
}
|
||||||
|
@ -282,6 +284,7 @@ Board Board::move(moves m){
|
||||||
}
|
}
|
||||||
setValidTrue();
|
setValidTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "Invalid move.\n\n";
|
cout << "Invalid move.\n\n";
|
||||||
|
@ -435,22 +438,18 @@ string Board::myToUpper(string input){
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::undo(Board& tablero){
|
Board* Board::undo(){
|
||||||
vector<Board> record;
|
//assuming this will only be called by a player, against an AI
|
||||||
|
if (record.size() == 0){
|
||||||
if (record.size() < 2){
|
cout<< "ERROR: there is nothing to undo";
|
||||||
cout<<"nothing to undo"<<endl;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
for (int r = 0; r < 8; ++r){
|
Board* temp = new Board(record[record.size()-2]);
|
||||||
for (int k = 0; k < 8; ++k){
|
return temp;
|
||||||
//tablero.modifyAt(r,k,(record[record.size()-2]).elementAt(r,k));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
record.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::snapshot(vector<Board>& inputVec, Board inputBoard){
|
void Board::snapshot(vector<Board>& inputVec, Board inputBoard){
|
||||||
|
|
4
Board.h
4
Board.h
|
@ -28,12 +28,14 @@ class Board {
|
||||||
vector<Piece*> xpieces;
|
vector<Piece*> xpieces;
|
||||||
vector<Piece*> opieces;
|
vector<Piece*> opieces;
|
||||||
vector<Piece*> pieces;
|
vector<Piece*> pieces;
|
||||||
|
vector<Board> record;
|
||||||
bool valid, xtaken, otaken;
|
bool valid, xtaken, otaken;
|
||||||
char turn = 'O';
|
char turn = 'O';
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Board();
|
Board();
|
||||||
Board(const Board& b);
|
Board(const Board& b);
|
||||||
|
vector<Board> getRecord() const{ return record; }
|
||||||
void setValidFalse(){ valid = false; }
|
void setValidFalse(){ valid = false; }
|
||||||
void setValidTrue(){ valid = true; }
|
void setValidTrue(){ valid = true; }
|
||||||
bool isValid(){ return valid; }
|
bool isValid(){ return valid; }
|
||||||
|
@ -54,7 +56,7 @@ public:
|
||||||
bool isThisMovePossible(int r, int c, string moveType);
|
bool isThisMovePossible(int r, int c, string moveType);
|
||||||
vector<moves> viewPossibleMoves();
|
vector<moves> viewPossibleMoves();
|
||||||
string myToUpper(string input);
|
string myToUpper(string input);
|
||||||
void undo(Board& tablero);
|
Board* undo();
|
||||||
void snapshot(vector<Board>& inputVec, Board inputBoard);
|
void snapshot(vector<Board>& inputVec, Board inputBoard);
|
||||||
int evaluate(char max, char min);
|
int evaluate(char max, char min);
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,9 +13,11 @@ Engine::Engine(){
|
||||||
b = brd;
|
b = brd;
|
||||||
alpha = INT_MIN;
|
alpha = INT_MIN;
|
||||||
beta = INT_MAX;
|
beta = INT_MAX;
|
||||||
|
undo_cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::startGame(){
|
void Engine::startGame(){
|
||||||
|
undo_cnt = 0;
|
||||||
cout<<"WELCOME\n";
|
cout<<"WELCOME\n";
|
||||||
|
|
||||||
cout<<"1. Play against AI?\n";
|
cout<<"1. Play against AI?\n";
|
||||||
|
|
2
Engine.h
2
Engine.h
|
@ -8,7 +8,7 @@ using namespace std;
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
Board* b;
|
Board* b;
|
||||||
int alpha, beta;
|
int alpha, beta, undo_cnt;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Engine();
|
Engine();
|
||||||
|
|
19
Parser.cpp
19
Parser.cpp
|
@ -29,19 +29,18 @@ string myToUpper(string input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseAndMove(vector<string> tokens, Board& board) {
|
void parseAndMove(vector<string> tokens, Board& board) {
|
||||||
//Debugging
|
|
||||||
int col;
|
int col;
|
||||||
int row;
|
int row;
|
||||||
|
|
||||||
if(tokens[0].size() == 2) {
|
if(tokens[0].size() == 2) {
|
||||||
if(tokens[1].size() >= 3 && tokens[1].size() <= 5) {
|
if(tokens[1].size() >= 3 && tokens[1].size() <= 5) {
|
||||||
if(tokens[0][0] - 'A' < 0 || tokens[0][0] - 'A' > 7) {
|
if(tokens[0][0] - 'A' < 0 || tokens[0][0] - 'A' > 7) {
|
||||||
//cout << "Error. Invalid move location. (1st coord.)\n\n";
|
cout << "Error. Invalid move location. (1st coord.)\n\n";
|
||||||
cout << tokens[0][0] << " " << (tokens[0][0] - 'A') << "\n\n";
|
cout << tokens[0][0] << " " << (tokens[0][0] - 'A') << "\n\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(tokens[0][1] - '0' < 0 || tokens[0][1] - '0' > 7) {
|
else if(tokens[0][1] - '0' < 0 || tokens[0][1] - '0' > 7) {
|
||||||
//cout << "Error. Invalid move location. (1st coord.)\n\n";
|
cout << "Error. Invalid move location. (1st coord.)\n\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -64,29 +63,23 @@ void parseAndMove(vector<string> tokens, Board& board) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//cout << "Error. Invalid move location. (size)\n\n";
|
cout << "Error. Invalid move location. (size)\n\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseCmd(vector<string> tokens, Board& board) {
|
void parseCmd(vector<string> tokens, Board& board) {
|
||||||
if(tokens[0] == "UNDO") {
|
if(tokens[0] == "UNDO") {
|
||||||
//Debugging
|
board = *(board.undo());
|
||||||
//cout << "Testing UNDO.\n\n";
|
|
||||||
//Change when you fix undo.
|
|
||||||
board.undo(board);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(tokens[0] == "DISPLAYRECORD") {
|
else if(tokens[0] == "DISPLAYRECORD") {
|
||||||
//Debugging
|
cout << "record size: " << board.getRecord().size();
|
||||||
//cout << "Testing DISPLAYRECORD.\n\n";
|
vector<Board> record = board.getRecord();
|
||||||
/*Fix record, uncomment this.
|
|
||||||
cout << "recordsize: " << board->getRecord.size();
|
|
||||||
|
|
||||||
for(int i = 0; i < record.size(); ++i) {
|
for(int i = 0; i < record.size(); ++i) {
|
||||||
record[i].displayBoard();
|
record[i].displayBoard();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
BIN
a.out
Executable file
BIN
a.out
Executable file
Binary file not shown.
Reference in a new issue