This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
breakthroughpine64backup/Engine.cpp

101 lines
1.8 KiB
C++
Raw Normal View History

2015-10-25 16:43:27 -05:00
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include "Engine.h"
Engine::Engine(){
2015-10-25 16:53:32 -05:00
Board* brd = new Board();
b = brd;
2015-10-25 16:43:27 -05:00
}
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";
2015-10-26 15:22:59 -05:00
int choice = -1;
2015-10-25 16:43:27 -05:00
cin >> choice;
cout << "OK" << endl;
string move;
bool gameOver = false;
vector<Board> record;
2015-10-25 16:53:32 -05:00
b->snapshot(record, *b);
2015-10-25 16:43:27 -05:00
while (gameOver != true)
{
2015-10-25 16:53:32 -05:00
gameOver = b->isGameOver();
2015-10-25 16:43:27 -05:00
2015-10-25 16:53:32 -05:00
while(b->getTurn() == 'O' )
2015-10-25 16:43:27 -05:00
{
2015-10-25 16:53:32 -05:00
b->displayBoard();
2015-10-25 16:43:27 -05:00
cout<<"\nEnter command: ";
cin>>move;
2015-10-25 16:53:32 -05:00
b->interpret(move, *b);
2015-10-25 16:43:27 -05:00
}
2015-10-26 15:22:59 -05:00
while(b->getTurn() == 'X' )
2015-10-25 16:43:27 -05:00
{
2015-10-26 15:22:59 -05:00
AI();
2015-10-25 16:43:27 -05:00
}
2015-10-25 16:53:32 -05:00
gameOver = b->isGameOver();
2015-10-25 16:43:27 -05:00
2015-10-25 16:53:32 -05:00
b->snapshot(record, *b);
2015-10-25 16:43:27 -05:00
}
//for debugging purposes
cout<<"Record:"<<endl;
cout<<record.size();
for (int i = 0; i < record.size(); ++i)
{
record[i].displayBoard();
}
}
2015-10-25 16:53:32 -05:00
void Engine::easyAI()
2015-10-25 16:43:27 -05:00
{
//1) see all possible movements
2015-10-25 16:53:32 -05:00
vector<moves> listOfMoves = b->viewPossibleMoves();
2015-10-25 16:43:27 -05:00
//obvious moves
if (false){
2015-10-26 15:22:59 -05:00
b->changeTurns();
2015-10-25 16:43:27 -05:00
}
//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;
2015-10-26 15:22:59 -05:00
b->move(listOfMoves[randomChoice]);
2015-10-25 16:43:27 -05:00
}
}
2015-10-25 16:53:32 -05:00
void Engine::AI(){
2015-10-26 15:22:59 -05:00
vector<moves> listOfMoves = b->viewPossibleMoves();
cout << "rows: \n\n";
for (int i = 0; i < listOfMoves.size(); ++i){
cout << "i: " << listOfMoves[i].row << "\n";
}
cout << "columns: \n\n";
for (int i = 0; i < listOfMoves.size(); ++i){
cout << "i: " << listOfMoves[i].column << "\n";
}
2015-10-25 16:43:27 -05:00
}
2015-10-25 16:53:32 -05:00
void Engine::minMax(){
2015-10-25 16:43:27 -05:00
//do more things here
}