Merge branch 'beccadev' of https://github.tamu.edu/brj2013/Breakthrough into beccadev
This commit is contained in:
commit
1852432a73
5 changed files with 115 additions and 61 deletions
76
Board.cpp
76
Board.cpp
|
@ -89,16 +89,16 @@ void Board::changeTurns()
|
|||
void Board::displayBoard()
|
||||
{
|
||||
cout<<"\n\n";
|
||||
cout<<" A B C D E F G H"<<endl;
|
||||
cout<<"; A B C D E F G H"<<endl;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
int mango = 8 - i;
|
||||
cout<<mango<<" ";
|
||||
cout<<"; "<<mango<<" ";
|
||||
for (int j = 0; j < 8; ++j)
|
||||
{
|
||||
cout<<boardArray[i][j]<<" ";
|
||||
cout<<"|"<<boardArray[i][j];
|
||||
}
|
||||
cout<<endl;
|
||||
cout<<"|\n";
|
||||
}
|
||||
cout<<'\n'<<endl;
|
||||
cout<<"turn : "<<turn;
|
||||
|
@ -123,7 +123,6 @@ int Board::charToIntColumn(char input) //converts column number to int
|
|||
return kolumn;
|
||||
}
|
||||
|
||||
|
||||
char Board::intToCharColumn(int input) //converts column number to int
|
||||
{
|
||||
char kolumn;
|
||||
|
@ -256,7 +255,6 @@ void Board::move(string inputMove)
|
|||
|
||||
}
|
||||
|
||||
|
||||
void Board::move(moves jugada)
|
||||
{
|
||||
|
||||
|
@ -408,9 +406,6 @@ bool Board::isThisMovePossible(int r, int c, string moveType)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
vector<moves> Board::viewPossibleMoves()
|
||||
{
|
||||
vector<moves> output;
|
||||
|
@ -480,6 +475,69 @@ 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
|
||||
{
|
||||
vector<Board> record;
|
||||
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);
|
||||
}
|
||||
|
||||
//move this to its own file
|
||||
void Board::easyAI()
|
||||
{
|
||||
|
||||
|
|
5
Board.h
5
Board.h
|
@ -23,6 +23,8 @@ class Board {
|
|||
|
||||
public:
|
||||
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);
|
||||
char getTurn() { return turn; }
|
||||
bool isGameOver();
|
||||
|
@ -36,5 +38,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();
|
||||
};
|
BIN
a.out
BIN
a.out
Binary file not shown.
43
main.cpp
43
main.cpp
|
@ -1,43 +0,0 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "GameEngine.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
cout<<"Welcome to Breakthrough\n"<<endl;
|
||||
cout<<"playing with AI..."<<endl;
|
||||
|
||||
Board b;
|
||||
|
||||
string move;
|
||||
|
||||
bool gameOver = false;
|
||||
|
||||
while (gameOver != true)
|
||||
{
|
||||
gameOver = b.isGameOver();
|
||||
|
||||
while(b.getTurn() == 'O')
|
||||
{
|
||||
b.displayBoard();
|
||||
cout<<"\nEnter move: ";
|
||||
cin>>move;
|
||||
b.move(move);
|
||||
}
|
||||
|
||||
|
||||
vector<moves> possibleMoves = b.viewPossibleMoves();
|
||||
//displayPossibleMoves(possibleMoves); for debugging purposes - AI
|
||||
|
||||
|
||||
b.easyAI();
|
||||
|
||||
gameOver = b.isGameOver();
|
||||
}
|
||||
|
||||
}
|
46
test.cpp
46
test.cpp
|
@ -8,14 +8,23 @@ using namespace std;
|
|||
|
||||
int main()
|
||||
{
|
||||
cout<<"Welcome to Breakthrough\n"<<endl;
|
||||
cout<<"playing with AI..."<<endl;
|
||||
cout<<"WELCOME\n";
|
||||
|
||||
cout<<"1. Play against AI?\n";
|
||||
cout<<"2. Play against a human?\n";
|
||||
cout<<"CHANGE THIS TO PARSE THINGS\n";
|
||||
cout<<"Enter choice: \n";
|
||||
|
||||
int choice;
|
||||
cin >> choice;
|
||||
cout << "OK" << endl;
|
||||
|
||||
Board b;
|
||||
|
||||
string move;
|
||||
|
||||
bool gameOver = false;
|
||||
vector<Board> record;
|
||||
b.snapshot(record,b);
|
||||
|
||||
while (gameOver != true)
|
||||
{
|
||||
|
@ -24,19 +33,44 @@ int main()
|
|||
while(b.getTurn() == 'O' )
|
||||
{
|
||||
b.displayBoard();
|
||||
cout<<"\nEnter move: ";
|
||||
cout<<"\nEnter command: ";
|
||||
cin>>move;
|
||||
b.move(move);
|
||||
b.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;
|
||||
b.interpret(move,b);
|
||||
}
|
||||
}
|
||||
|
||||
//b.snapshot();
|
||||
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