this will work with functioning mechanics
This commit is contained in:
parent
b9b1ba0764
commit
f10c4e7c18
3 changed files with 22 additions and 15 deletions
30
Board.cpp
30
Board.cpp
|
@ -201,13 +201,13 @@ char Board::intToCharColumn(int input){
|
|||
}
|
||||
|
||||
void Board::move(string inputMove){
|
||||
moves jugada = parse(inputMove);
|
||||
move(jugada);
|
||||
moves m = parse(inputMove);
|
||||
move(m);
|
||||
}
|
||||
|
||||
void Board::move(moves jugada){
|
||||
int row = 8 - (jugada.row);
|
||||
int column = charToIntColumn(jugada.column);
|
||||
void Board::move(moves m){
|
||||
int row = 8 - (m.row);
|
||||
int column = charToIntColumn(m.column);
|
||||
|
||||
if (row > 8 || row < 0 || column > 8 || column < 0) {
|
||||
cout<<"ERROR: index out of bound."<<endl;
|
||||
|
@ -227,16 +227,22 @@ void Board::move(moves jugada){
|
|||
}
|
||||
|
||||
else {
|
||||
if (jugada.moveType == "FWD") {
|
||||
if (!(isThisMovePossible(row, column, m.moveType))){
|
||||
cout << "Unable to move: impossible move.\n";
|
||||
//add a try again
|
||||
return;
|
||||
}
|
||||
|
||||
if (m.moveType == "FWD") {
|
||||
piece->moveFwd();
|
||||
}
|
||||
|
||||
else if (jugada.moveType == "LEFT") {
|
||||
else if (m.moveType == "LEFT") {
|
||||
//add error checking
|
||||
piece->moveLeft();
|
||||
}
|
||||
|
||||
else if (jugada.moveType == "RIGHT") {
|
||||
else if (m.moveType == "RIGHT") {
|
||||
//add error checking
|
||||
piece->moveRight();
|
||||
}
|
||||
|
@ -262,21 +268,21 @@ bool Board::isThisMovePossible(int r, int c, string moveType){
|
|||
reflector *= -1;
|
||||
|
||||
if (moveType == "FWD"){
|
||||
if (isPiece(r+reflector, c))
|
||||
if (!isPiece(r + reflector, c))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
else if (moveType == "RIGHT"){
|
||||
if (isPiece(r+reflector, c+1) && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 <= 7))
|
||||
if (!isPiece(r+reflector, c+1) && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 <= 7))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
else if (moveType == "LEFT"){
|
||||
if (isPiece(r+reflector, c+1) && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 >= 0))
|
||||
if (!isPiece(r+reflector, c+1) && (r+reflector >= 0) && (r+reflector <= 7) && (c+1 >= 0))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
@ -314,7 +320,7 @@ vector<moves> Board::viewPossibleMoves(){
|
|||
}
|
||||
}
|
||||
|
||||
else {
|
||||
else if (turn == 'X') {
|
||||
for (int i = 0; i < opieces.size(); ++i){
|
||||
r = opieces[i]->getX();
|
||||
c = opieces[i]->getY();
|
||||
|
|
|
@ -60,6 +60,7 @@ void Engine::easyAI()
|
|||
int randomChoice = rand() % (listOfMoves.size()-1) - 0;
|
||||
|
||||
int temp = randomChoice;
|
||||
cout << "easy AI move: " << listOfMoves[randomChoice].row << listOfMoves[randomChoice].column << listOfMoves[randomChoice].moveType << "\n";
|
||||
b->move(listOfMoves[randomChoice]);
|
||||
b->changeTurns();
|
||||
}
|
||||
|
@ -93,7 +94,7 @@ void Engine::AI(){
|
|||
}
|
||||
|
||||
moves Engine::minMax(Board* temp, moves m, int c){
|
||||
//testing purposes only
|
||||
//testing purposes only, c = finite depth
|
||||
if (c > 5){
|
||||
return m;
|
||||
}
|
||||
|
|
4
test.cpp
4
test.cpp
|
@ -6,8 +6,8 @@ using namespace std;
|
|||
int main()
|
||||
{
|
||||
//board testing
|
||||
//Board b;
|
||||
|
||||
Board b;
|
||||
|
||||
//engine testing
|
||||
Engine e;
|
||||
e.startGame();
|
||||
|
|
Reference in a new issue