final restructure

This commit is contained in:
Rebecca Schofield 2015-10-19 16:37:20 -05:00
commit cdd989bdcf
3 changed files with 109 additions and 7 deletions

View file

@ -480,6 +480,67 @@ void Board::displayPossibleMoves(vector<moves> input)
} }
} }
void Board::undo(Board& tablero)
{
vector<Board> record;
if (record.size() < 2)
{
cout<<"nothing to undo"<<endl;
}
else
{
for (int r = 0; r < 8; ++r)
{
for (int k = 0; k < 8; ++k)
{
tablero.modifyAt(r,k,(record[record.size()-2]).elementAt(r,k));
}
}
record.pop_back();
}
}
void Board::interpret(string input, Board& tablero) //determines what kind of command its input is
{
input = myToUpper(input);
if (input == "UNDO")
{
undo(tablero);
}
else if (input == "DISPLAYRECORD") //for debugging purposes
{
cout<<"record: "<<endl;
cout<<record.size();
for (int i = 0; i < record.size(); ++i)
{
record[i].displayBoard();
}
cout<<"---------------------------------------------------END DISPLAY RECORD------------------------"<<endl;
}
else tablero.move(input);
}
void Board::snapshot(vector<Board>& inputVec, Board inputBoard)
{
if (inputVec.size() == 10)
{
inputVec.erase(inputVec.begin());
}
else if (inputVec.size() > 10)
{
cout<<"QUEUE OVERFLOW!"<<endl;
}
inputVec.push_back(inputBoard);
}
void Board::easyAI() void Board::easyAI()
{ {

View file

@ -36,5 +36,8 @@ public:
vector<moves> viewPossibleMoves(); vector<moves> viewPossibleMoves();
string myToUpper(string input); string myToUpper(string input);
void displayPossibleMoves(vector<moves> input); void displayPossibleMoves(vector<moves> input);
void undo(Board& tablero);
void interpret(string input, Board& tablero);
void snapshot(vector<Board>& inputVec, Board inputBoard);
void easyAI(); void easyAI();
}; };

View file

@ -2,15 +2,26 @@
#include <vector> #include <vector>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "GameEngine.h" #include "Board.h"
using namespace std; using namespace std;
int main() int main()
{ {
cout<<"\n----------------------------"<<endl;
cout<<"Welcome to Breakthrough\n"<<endl; cout<<"Welcome to Breakthrough\n"<<endl;
cout<<"playing with AI..."<<endl; cout<<"-----------------------------\n\n"<<endl;
cout<<"1. Play agains AI?"<<endl;
cout<<"2. Play against a human?"<<endl;
cout<<"Enter choice: "<<endl;
int choice;
cin>>choice;
if (choice == 1) cout<<"playing with AI..."<<endl;
else cout<<"playing with human..."<<endl;
Board b; Board b;
@ -18,26 +29,53 @@ int main()
bool gameOver = false; bool gameOver = false;
snapshot(record,b);
while (gameOver != true) while (gameOver != true)
{ {
gameOver = b.isGameOver(); gameOver = b.isGameOver();
while(b.getTurn() == 'O') while(b.getTurn() == 'O' )
{ {
b.displayBoard(); b.displayBoard();
cout<<"\nEnter move: "; cout<<"\nEnter command: ";
cin>>move; cin>>move;
b.move(move); interpret(move,b);
} }
vector<moves> possibleMoves = b.viewPossibleMoves(); vector<moves> possibleMoves = b.viewPossibleMoves();
//displayPossibleMoves(possibleMoves); for debugging purposes - AI //displayPossibleMoves(possibleMoves); for debugging purposes - AI
if (choice == 1)
{
b.easyAI();
}
b.easyAI(); else
{
while(b.getTurn() == 'X' )
{
b.displayBoard();
cout<<"\nEnter command: ";
cin>>move;
interpret(move,b);
}
}
//b.snapshot();
gameOver = b.isGameOver(); gameOver = b.isGameOver();
snapshot(record,b);
} }
//for debugging purposes
cout<<"Record:"<<endl;
cout<<record.size();
for (int i = 0; i < record.size(); ++i)
{
record[i].displayBoard();
}
} }