Merge branch 'beccadev' of https://github.tamu.edu/brj2013/Breakthrough into beccadev

This commit is contained in:
Alexander Huddleston 2015-10-20 11:22:32 -05:00
commit 1852432a73
5 changed files with 115 additions and 61 deletions

View file

@ -89,16 +89,16 @@ void Board::changeTurns()
void Board::displayBoard() void Board::displayBoard()
{ {
cout<<"\n\n"; 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) for (int i = 0; i < 8; ++i)
{ {
int mango = 8 - i; int mango = 8 - i;
cout<<mango<<" "; cout<<"; "<<mango<<" ";
for (int j = 0; j < 8; ++j) for (int j = 0; j < 8; ++j)
{ {
cout<<boardArray[i][j]<<" "; cout<<"|"<<boardArray[i][j];
} }
cout<<endl; cout<<"|\n";
} }
cout<<'\n'<<endl; cout<<'\n'<<endl;
cout<<"turn : "<<turn; cout<<"turn : "<<turn;
@ -123,7 +123,6 @@ int Board::charToIntColumn(char input) //converts column number to int
return kolumn; return kolumn;
} }
char Board::intToCharColumn(int input) //converts column number to int char Board::intToCharColumn(int input) //converts column number to int
{ {
char kolumn; char kolumn;
@ -255,8 +254,7 @@ void Board::move(string inputMove)
} }
void Board::move(moves jugada) void Board::move(moves jugada)
{ {
@ -408,9 +406,6 @@ bool Board::isThisMovePossible(int r, int c, string moveType)
} }
} }
vector<moves> Board::viewPossibleMoves() vector<moves> Board::viewPossibleMoves()
{ {
vector<moves> output; vector<moves> output;
@ -479,7 +474,70 @@ void Board::displayPossibleMoves(vector<moves> input)
cout<<"possible move: "<<input[i].row<<" "<<input[i].column<<" "<<input[i].moveType<<endl; 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
{
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() void Board::easyAI()
{ {

View file

@ -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();
@ -36,5 +38,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();
}; };

BIN
a.out

Binary file not shown.

View file

@ -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();
}
}

View file

@ -8,35 +8,69 @@ using namespace std;
int main() int main()
{ {
cout<<"Welcome to Breakthrough\n"<<endl; cout<<"WELCOME\n";
cout<<"playing with AI..."<<endl;
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; Board b;
string move; string move;
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();
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();
}
else
{
while(b.getTurn() == 'X' )
{
b.displayBoard();
cout<<"\nEnter command: ";
cin>>move;
b.interpret(move,b);
}
}
b.easyAI(); //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();
}
} }