updating NOT STABLE
This commit is contained in:
parent
2dc2c70562
commit
67a2997b8c
3 changed files with 45 additions and 113 deletions
117
Board.cpp
117
Board.cpp
|
@ -143,113 +143,7 @@ char Board::intToCharColumn(int input) //converts column number to int
|
||||||
void Board::move(string inputMove)
|
void Board::move(string inputMove)
|
||||||
{
|
{
|
||||||
moves jugada = parse(inputMove);
|
moves jugada = parse(inputMove);
|
||||||
|
move(jugada);
|
||||||
int row = 8 - (jugada.row);
|
|
||||||
int kolumn = charToIntColumn(jugada.column);
|
|
||||||
int temp = boardArray[row][kolumn];
|
|
||||||
int reflector = 1;
|
|
||||||
|
|
||||||
if (row > 8 || row < 0 || kolumn > 8 || kolumn < 0)
|
|
||||||
{
|
|
||||||
cout<<"ERROR: index out of bound in move()!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (temp != turn)
|
|
||||||
{
|
|
||||||
cout<<"you can't move that piece at this turn!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (temp == '_')
|
|
||||||
{
|
|
||||||
cout<<"there's no piece in that spot!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (temp == 'X' || temp == 'O')
|
|
||||||
{
|
|
||||||
|
|
||||||
if (temp == 'O')
|
|
||||||
{
|
|
||||||
reflector *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (jugada.moveType == "FWD")
|
|
||||||
{
|
|
||||||
|
|
||||||
if(boardArray[row+reflector][kolumn] != '_')
|
|
||||||
{
|
|
||||||
cout<<"you can't move that piece forward"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boardArray[row][kolumn] = '_';
|
|
||||||
boardArray[row+reflector][kolumn] = temp;
|
|
||||||
|
|
||||||
changeTurns();
|
|
||||||
displayBoard();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (jugada.moveType == "LEFT")
|
|
||||||
{
|
|
||||||
if (kolumn == 0)
|
|
||||||
{
|
|
||||||
cout<<"Destination Spot out of range!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (boardArray[row+reflector][kolumn-1] == temp)
|
|
||||||
{
|
|
||||||
cout<<"you hate your own team or something? you can't do that!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boardArray[row][kolumn] = '_';
|
|
||||||
boardArray[row+reflector][kolumn-1] = temp;
|
|
||||||
|
|
||||||
changeTurns();
|
|
||||||
displayBoard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (jugada.moveType == "RIGHT")
|
|
||||||
{
|
|
||||||
if (kolumn == 7)
|
|
||||||
{
|
|
||||||
cout<<"Destination Spot out of range!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (boardArray[row+reflector][kolumn+1] == temp)
|
|
||||||
{
|
|
||||||
cout<<"you hate your own team or something? you can't do that!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boardArray[row][kolumn] = '_';
|
|
||||||
boardArray[row+reflector][kolumn+1] = temp;
|
|
||||||
|
|
||||||
changeTurns();
|
|
||||||
displayBoard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Unrecognized movetype!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Invalid piece!"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::move(moves jugada)
|
void Board::move(moves jugada)
|
||||||
|
@ -265,7 +159,8 @@ void Board::move(moves jugada)
|
||||||
int temp = boardArray[row][kolumn];
|
int temp = boardArray[row][kolumn];
|
||||||
if (temp != turn)
|
if (temp != turn)
|
||||||
{
|
{
|
||||||
cout<<"you can't move that piece at this turn!"<<endl;
|
//ssshhh
|
||||||
|
//cout<<"you can't move that piece at this turn!"<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (temp == '_')
|
else if (temp == '_')
|
||||||
|
@ -355,7 +250,7 @@ void Board::move(moves jugada)
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout<<"Invalid piece!"<<endl;
|
cout<<"Invalid piece2!"<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -363,9 +258,13 @@ void Board::move(moves jugada)
|
||||||
bool Board::isThisMovePossible(int r, int c, string moveType)
|
bool Board::isThisMovePossible(int r, int c, string moveType)
|
||||||
{
|
{
|
||||||
char pieceToMove = boardArray[r][c];
|
char pieceToMove = boardArray[r][c];
|
||||||
|
cout << "r: " << r << "\n";
|
||||||
|
cout << "c: " << c << "\n";
|
||||||
|
cout << "pieceToMove: " << pieceToMove << "\n";
|
||||||
|
|
||||||
if (pieceToMove != turn) //trying to move invalid piece
|
if (pieceToMove != turn) //trying to move invalid piece
|
||||||
{
|
{
|
||||||
|
//cout << "Error in Board::isThisMovePossible: trying to move a piece outside your turn.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
Engine.cpp
39
Engine.cpp
|
@ -83,10 +83,43 @@ void Engine::easyAI()
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::AI(){
|
void Engine::AI(){
|
||||||
|
cout << "----------------------BEGIN AI FUNCTION----------------------\n";
|
||||||
vector<moves> listOfMoves = b->viewPossibleMoves();
|
vector<moves> listOfMoves = b->viewPossibleMoves();
|
||||||
//
|
Board* temp = b;
|
||||||
|
if (temp->getTurn() != 'X'){
|
||||||
|
temp->changeTurns();
|
||||||
|
}
|
||||||
|
//temp->changeTurns();
|
||||||
|
//cout << "after: " << temp->getTurn() << "\n";
|
||||||
|
|
||||||
|
//only doing 1 branch right now because testing
|
||||||
|
/*for (int i = 0; i < listOfMoves.size(); ++i){
|
||||||
|
minMax(temp, listOfMoves[i]);
|
||||||
|
}*/
|
||||||
|
minMax(temp, listOfMoves[0]);
|
||||||
|
|
||||||
|
b->move(listOfMoves[0]);
|
||||||
|
cout << "----------------------END AI FUNCTION----------------------\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::minMax(){
|
void Engine::minMax(Board* temp, moves m){
|
||||||
//do more things here
|
if (temp->isGameOver() == true){
|
||||||
|
cout << "END OF PATH REACHED\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
cout << "m.row: " << m.row << "\n";
|
||||||
|
cout << "charToIntColumn(m.column): " << temp->charToIntColumn(m.column) << "\n";
|
||||||
|
cout << "m.moveType: " << m.moveType << "\n";
|
||||||
|
cout << "temp->isThisMovePossible(stuff): " << temp->isThisMovePossible(m.row, temp->charToIntColumn(m.column), m.moveType) << "\n\n\n";
|
||||||
|
|
||||||
|
vector<moves> listOfMoves = temp->viewPossibleMoves();
|
||||||
|
/*for (int i = 0; i < listOfMoves.size(); ++i){
|
||||||
|
minMax(temp, listOfMoves[i]);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
temp->displayBoard();
|
||||||
|
}
|
||||||
}
|
}
|
2
Engine.h
2
Engine.h
|
@ -12,5 +12,5 @@ public:
|
||||||
void startGame();
|
void startGame();
|
||||||
void easyAI();
|
void easyAI();
|
||||||
void AI();
|
void AI();
|
||||||
void minMax();
|
void minMax(Board* temp, moves m);
|
||||||
};
|
};
|
Reference in a new issue