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){
|
void Board::move(string inputMove){
|
||||||
moves jugada = parse(inputMove);
|
moves m = parse(inputMove);
|
||||||
move(jugada);
|
move(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::move(moves jugada){
|
void Board::move(moves m){
|
||||||
int row = 8 - (jugada.row);
|
int row = 8 - (m.row);
|
||||||
int column = charToIntColumn(jugada.column);
|
int column = charToIntColumn(m.column);
|
||||||
|
|
||||||
if (row > 8 || row < 0 || column > 8 || column < 0) {
|
if (row > 8 || row < 0 || column > 8 || column < 0) {
|
||||||
cout<<"ERROR: index out of bound."<<endl;
|
cout<<"ERROR: index out of bound."<<endl;
|
||||||
|
@ -227,16 +227,22 @@ void Board::move(moves jugada){
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
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();
|
piece->moveFwd();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (jugada.moveType == "LEFT") {
|
else if (m.moveType == "LEFT") {
|
||||||
//add error checking
|
//add error checking
|
||||||
piece->moveLeft();
|
piece->moveLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (jugada.moveType == "RIGHT") {
|
else if (m.moveType == "RIGHT") {
|
||||||
//add error checking
|
//add error checking
|
||||||
piece->moveRight();
|
piece->moveRight();
|
||||||
}
|
}
|
||||||
|
@ -262,21 +268,21 @@ bool Board::isThisMovePossible(int r, int c, string moveType){
|
||||||
reflector *= -1;
|
reflector *= -1;
|
||||||
|
|
||||||
if (moveType == "FWD"){
|
if (moveType == "FWD"){
|
||||||
if (isPiece(r+reflector, c))
|
if (!isPiece(r + reflector, c))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (moveType == "RIGHT"){
|
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;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (moveType == "LEFT"){
|
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;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -314,7 +320,7 @@ vector<moves> Board::viewPossibleMoves(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else if (turn == 'X') {
|
||||||
for (int i = 0; i < opieces.size(); ++i){
|
for (int i = 0; i < opieces.size(); ++i){
|
||||||
r = opieces[i]->getX();
|
r = opieces[i]->getX();
|
||||||
c = opieces[i]->getY();
|
c = opieces[i]->getY();
|
||||||
|
|
|
@ -60,6 +60,7 @@ void Engine::easyAI()
|
||||||
int randomChoice = rand() % (listOfMoves.size()-1) - 0;
|
int randomChoice = rand() % (listOfMoves.size()-1) - 0;
|
||||||
|
|
||||||
int temp = randomChoice;
|
int temp = randomChoice;
|
||||||
|
cout << "easy AI move: " << listOfMoves[randomChoice].row << listOfMoves[randomChoice].column << listOfMoves[randomChoice].moveType << "\n";
|
||||||
b->move(listOfMoves[randomChoice]);
|
b->move(listOfMoves[randomChoice]);
|
||||||
b->changeTurns();
|
b->changeTurns();
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ void Engine::AI(){
|
||||||
}
|
}
|
||||||
|
|
||||||
moves Engine::minMax(Board* temp, moves m, int c){
|
moves Engine::minMax(Board* temp, moves m, int c){
|
||||||
//testing purposes only
|
//testing purposes only, c = finite depth
|
||||||
if (c > 5){
|
if (c > 5){
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
4
test.cpp
4
test.cpp
|
@ -6,8 +6,8 @@ using namespace std;
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//board testing
|
//board testing
|
||||||
//Board b;
|
Board b;
|
||||||
|
|
||||||
//engine testing
|
//engine testing
|
||||||
Engine e;
|
Engine e;
|
||||||
e.startGame();
|
e.startGame();
|
||||||
|
|
Reference in a new issue