Updating branch.
This commit is contained in:
commit
8ece71023d
6 changed files with 638 additions and 711 deletions
40
Board.h
40
Board.h
|
@ -17,39 +17,9 @@ struct moves {
|
|||
}
|
||||
};
|
||||
|
||||
struct simpleBoard{
|
||||
|
||||
char boardStamp [8][8];
|
||||
|
||||
char elementAt(int r, int k)
|
||||
{
|
||||
return boardStamp[r][k];
|
||||
}
|
||||
|
||||
void modifyAt(int r, int k, char c)
|
||||
{
|
||||
boardStamp[r][k] = c;
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
for (int r = 0; r < 8; ++r)
|
||||
{
|
||||
cout<<'\n';
|
||||
|
||||
for (int k = 0; k < 8; ++k)
|
||||
{
|
||||
cout<<boardStamp[r][k]<<" ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Board {
|
||||
char boardArray [8][8];
|
||||
char turn = 'O';
|
||||
vector<simpleBoard> record;
|
||||
|
||||
public:
|
||||
Board();
|
||||
|
@ -67,11 +37,7 @@ public:
|
|||
bool isThisMovePossible(int r, int c, string moveType);
|
||||
vector<moves> viewPossibleMoves();
|
||||
string myToUpper(string input);
|
||||
void displayPossibleMoves(vector<moves> input);
|
||||
void undo();
|
||||
void undo(Board& tablero);
|
||||
void interpret(string input, Board& tablero);
|
||||
void snapshot();
|
||||
void easyAI();
|
||||
string boardToString();
|
||||
void displayRecord();
|
||||
};
|
||||
void snapshot(vector<Board>& inputVec, Board inputBoard);
|
||||
};
|
92
Engine.cpp
Executable file
92
Engine.cpp
Executable file
|
@ -0,0 +1,92 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "Engine.h"
|
||||
|
||||
|
||||
Engine::Engine(){
|
||||
Board* brd = new Board();
|
||||
b = brd;
|
||||
}
|
||||
|
||||
void Engine::startGame(){
|
||||
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 = -1;
|
||||
cin >> choice;
|
||||
cout << "OK" << endl;
|
||||
|
||||
string move;
|
||||
|
||||
bool gameOver = false;
|
||||
vector<Board> record;
|
||||
b->snapshot(record, *b);
|
||||
|
||||
while (gameOver != true)
|
||||
{
|
||||
gameOver = b->isGameOver();
|
||||
|
||||
while(b->getTurn() == 'O' )
|
||||
{
|
||||
b->displayBoard();
|
||||
cout<<"\nEnter command: ";
|
||||
cin>>move;
|
||||
b->interpret(move, *b);
|
||||
}
|
||||
|
||||
while(b->getTurn() == 'X' )
|
||||
{
|
||||
AI();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::easyAI()
|
||||
{
|
||||
//1) see all possible movements
|
||||
vector<moves> listOfMoves = b->viewPossibleMoves();
|
||||
|
||||
//obvious moves
|
||||
if (false){
|
||||
b->changeTurns();
|
||||
}
|
||||
|
||||
//random
|
||||
else {
|
||||
srand(time(NULL));
|
||||
int randomChoice = rand() % (listOfMoves.size()-1) - 0; // choose a move betwen listOfMoves[0] to last element
|
||||
|
||||
//3) execute movement
|
||||
int temp = randomChoice;
|
||||
b->move(listOfMoves[randomChoice]);
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::AI(){
|
||||
vector<moves> listOfMoves = b->viewPossibleMoves();
|
||||
//
|
||||
}
|
||||
|
||||
void Engine::minMax(){
|
||||
//do more things here
|
||||
}
|
16
Engine.h
Executable file
16
Engine.h
Executable file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "Board.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Engine {
|
||||
Board* b;
|
||||
|
||||
public:
|
||||
Engine();
|
||||
void startGame();
|
||||
void easyAI();
|
||||
void AI();
|
||||
void minMax();
|
||||
};
|
BIN
a.out
BIN
a.out
Binary file not shown.
73
test.cpp
73
test.cpp
|
@ -1,76 +1,9 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "Board.h"
|
||||
#include "Engine.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
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)
|
||||
{
|
||||
gameOver = b.isGameOver();
|
||||
|
||||
while(b.getTurn() == 'O' )
|
||||
{
|
||||
b.displayBoard();
|
||||
cout<<"\nEnter command: ";
|
||||
cin>>move;
|
||||
b.interpret(move,b);
|
||||
}
|
||||
|
||||
|
||||
vector<moves> possibleMoves = b.viewPossibleMoves();
|
||||
|
||||
if (choice == 1)
|
||||
{
|
||||
b.easyAI();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
while(b.getTurn() == 'X' )
|
||||
{
|
||||
b.displayBoard();
|
||||
cout<<"\nEnter command: ";
|
||||
cout<<"OK\n";
|
||||
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();
|
||||
}
|
||||
Engine e;
|
||||
e.startGame();
|
||||
}
|
||||
|
|
Reference in a new issue