final restructure
This commit is contained in:
commit
cdd989bdcf
3 changed files with 109 additions and 7 deletions
61
Board.cpp
61
Board.cpp
|
@ -479,6 +479,67 @@ void Board::displayPossibleMoves(vector<moves> input)
|
|||
cout<<"possible move: "<<input[i].row<<" "<<input[i].column<<" "<<input[i].moveType<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
|
3
Board.h
3
Board.h
|
@ -36,5 +36,8 @@ public:
|
|||
vector<moves> viewPossibleMoves();
|
||||
string myToUpper(string 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();
|
||||
};
|
52
main.cpp
52
main.cpp
|
@ -2,15 +2,26 @@
|
|||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "GameEngine.h"
|
||||
#include "Board.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
cout<<"\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;
|
||||
|
||||
|
@ -18,26 +29,53 @@ int main()
|
|||
|
||||
bool gameOver = false;
|
||||
|
||||
snapshot(record,b);
|
||||
|
||||
while (gameOver != true)
|
||||
{
|
||||
gameOver = b.isGameOver();
|
||||
|
||||
while(b.getTurn() == 'O')
|
||||
while(b.getTurn() == 'O' )
|
||||
{
|
||||
b.displayBoard();
|
||||
cout<<"\nEnter move: ";
|
||||
cout<<"\nEnter command: ";
|
||||
cin>>move;
|
||||
b.move(move);
|
||||
interpret(move,b);
|
||||
}
|
||||
|
||||
|
||||
vector<moves> possibleMoves = b.viewPossibleMoves();
|
||||
//displayPossibleMoves(possibleMoves); for debugging purposes - AI
|
||||
|
||||
if (choice == 1)
|
||||
{
|
||||
b.easyAI();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
while(b.getTurn() == 'X' )
|
||||
{
|
||||
b.displayBoard();
|
||||
cout<<"\nEnter command: ";
|
||||
cin>>move;
|
||||
interpret(move,b);
|
||||
}
|
||||
}
|
||||
|
||||
b.easyAI();
|
||||
|
||||
//b.snapshot();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue