merge and restructure
This commit is contained in:
parent
d3ed28a608
commit
16d014edc0
5 changed files with 56 additions and 12 deletions
|
@ -504,6 +504,7 @@ void Board::undo(Board& tablero)
|
||||||
|
|
||||||
void Board::interpret(string input, Board& tablero) //determines what kind of command its input is
|
void Board::interpret(string input, Board& tablero) //determines what kind of command its input is
|
||||||
{
|
{
|
||||||
|
vector<Board> record;
|
||||||
input = myToUpper(input);
|
input = myToUpper(input);
|
||||||
|
|
||||||
if (input == "UNDO")
|
if (input == "UNDO")
|
||||||
|
|
2
Board.h
2
Board.h
|
@ -23,6 +23,8 @@ class Board {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Board();
|
Board();
|
||||||
|
char elementAt(int r, int k) { return boardArray[r][k]; }
|
||||||
|
void modifyAt(int r, int k, char input) { boardArray[r][k] = input; }
|
||||||
moves parse(string input);
|
moves parse(string input);
|
||||||
char getTurn() { return turn; }
|
char getTurn() { return turn; }
|
||||||
bool isGameOver();
|
bool isGameOver();
|
||||||
|
|
BIN
a.out
BIN
a.out
Binary file not shown.
11
main.cpp
11
main.cpp
|
@ -8,7 +8,6 @@ using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
cout<<"\n----------------------------"<<endl;
|
cout<<"\n----------------------------"<<endl;
|
||||||
cout<<"Welcome to Breakthrough\n"<<endl;
|
cout<<"Welcome to Breakthrough\n"<<endl;
|
||||||
cout<<"-----------------------------\n\n"<<endl;
|
cout<<"-----------------------------\n\n"<<endl;
|
||||||
|
@ -29,7 +28,9 @@ int main()
|
||||||
|
|
||||||
bool gameOver = false;
|
bool gameOver = false;
|
||||||
|
|
||||||
snapshot(record,b);
|
vector<Board> record;
|
||||||
|
|
||||||
|
b.snapshot(record,b);
|
||||||
|
|
||||||
while (gameOver != true)
|
while (gameOver != true)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +41,7 @@ int main()
|
||||||
b.displayBoard();
|
b.displayBoard();
|
||||||
cout<<"\nEnter command: ";
|
cout<<"\nEnter command: ";
|
||||||
cin>>move;
|
cin>>move;
|
||||||
interpret(move,b);
|
b.interpret(move,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,14 +60,14 @@ int main()
|
||||||
b.displayBoard();
|
b.displayBoard();
|
||||||
cout<<"\nEnter command: ";
|
cout<<"\nEnter command: ";
|
||||||
cin>>move;
|
cin>>move;
|
||||||
interpret(move,b);
|
b.interpret(move,b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//b.snapshot();
|
//b.snapshot();
|
||||||
gameOver = b.isGameOver();
|
gameOver = b.isGameOver();
|
||||||
|
|
||||||
snapshot(record,b);
|
b.snapshot(record,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
//for debugging purposes
|
//for debugging purposes
|
||||||
|
|
48
test.cpp
48
test.cpp
|
@ -8,8 +8,19 @@ 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;
|
||||||
|
|
||||||
|
@ -17,6 +28,10 @@ int main()
|
||||||
|
|
||||||
bool gameOver = false;
|
bool gameOver = false;
|
||||||
|
|
||||||
|
vector<Board> record;
|
||||||
|
|
||||||
|
b.snapshot(record,b);
|
||||||
|
|
||||||
while (gameOver != true)
|
while (gameOver != true)
|
||||||
{
|
{
|
||||||
gameOver = b.isGameOver();
|
gameOver = b.isGameOver();
|
||||||
|
@ -24,19 +39,44 @@ int main()
|
||||||
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);
|
b.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;
|
||||||
|
b.interpret(move,b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//b.snapshot();
|
||||||
gameOver = b.isGameOver();
|
gameOver = b.isGameOver();
|
||||||
|
|
||||||
|
b.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