working on AI
This commit is contained in:
parent
67c3b463db
commit
c9ab7c2622
4 changed files with 16 additions and 25 deletions
32
Board.cpp
32
Board.cpp
|
@ -88,7 +88,6 @@ void Board::changeTurns()
|
||||||
|
|
||||||
void Board::displayBoard()
|
void Board::displayBoard()
|
||||||
{
|
{
|
||||||
cout<<"\n\n";
|
|
||||||
cout<<"; A B C D E F G H"<<endl;
|
cout<<"; A B C D E F G H"<<endl;
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
|
@ -466,15 +465,6 @@ string Board::myToUpper(string input)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::displayPossibleMoves(vector<moves> input)
|
|
||||||
{
|
|
||||||
cout<<"\n\nList of possible Moves:"<<endl;
|
|
||||||
for (int i = 0; i < input.size(); ++i)
|
|
||||||
{
|
|
||||||
cout<<"possible move: "<<input[i].row<<" "<<input[i].column<<" "<<input[i].moveType<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Board::undo(Board& tablero)
|
void Board::undo(Board& tablero)
|
||||||
{
|
{
|
||||||
vector<Board> record;
|
vector<Board> record;
|
||||||
|
@ -545,17 +535,19 @@ void Board::easyAI()
|
||||||
|
|
||||||
vector<moves> listOfMoves = viewPossibleMoves();
|
vector<moves> listOfMoves = viewPossibleMoves();
|
||||||
|
|
||||||
//2) pick a movement
|
//obvious moves
|
||||||
|
if (){
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
srand(time(NULL));
|
//random
|
||||||
int randomChoice = rand() % (listOfMoves.size()-1) - 0; // choose a move betwen listOfMoves[0] to last element
|
else {
|
||||||
|
srand(time(NULL));
|
||||||
|
int randomChoice = rand() % (listOfMoves.size()-1) - 0; // choose a move betwen listOfMoves[0] to last element
|
||||||
|
|
||||||
//3) execute movement
|
//3) execute movement
|
||||||
|
int temp = randomChoice;
|
||||||
int temp = randomChoice;
|
|
||||||
|
|
||||||
move(listOfMoves[randomChoice]);
|
|
||||||
|
|
||||||
//cout<<"\n\nMove executed by AI: "<<listOfMoves[temp].column<<" "<<listOfMoves[temp].row<<" "<<listOfMoves[temp].moveType<<endl; uncomment for debugging purposes
|
|
||||||
|
|
||||||
|
move(listOfMoves[randomChoice]);
|
||||||
|
}
|
||||||
}
|
}
|
1
Board.h
1
Board.h
|
@ -37,7 +37,6 @@ public:
|
||||||
bool isThisMovePossible(int r, int c, string moveType);
|
bool isThisMovePossible(int r, int c, string moveType);
|
||||||
vector<moves> viewPossibleMoves();
|
vector<moves> viewPossibleMoves();
|
||||||
string myToUpper(string input);
|
string myToUpper(string input);
|
||||||
void displayPossibleMoves(vector<moves> input);
|
|
||||||
void undo(Board& tablero);
|
void undo(Board& tablero);
|
||||||
void interpret(string input, Board& tablero);
|
void interpret(string input, Board& tablero);
|
||||||
void snapshot(vector<Board>& inputVec, Board inputBoard);
|
void snapshot(vector<Board>& inputVec, Board inputBoard);
|
||||||
|
|
BIN
a.out
BIN
a.out
Binary file not shown.
2
test.cpp
2
test.cpp
|
@ -40,7 +40,6 @@ int main()
|
||||||
|
|
||||||
|
|
||||||
vector<moves> possibleMoves = b.viewPossibleMoves();
|
vector<moves> possibleMoves = b.viewPossibleMoves();
|
||||||
//displayPossibleMoves(possibleMoves); for debugging purposes - AI
|
|
||||||
|
|
||||||
if (choice == 1)
|
if (choice == 1)
|
||||||
{
|
{
|
||||||
|
@ -53,6 +52,7 @@ int main()
|
||||||
{
|
{
|
||||||
b.displayBoard();
|
b.displayBoard();
|
||||||
cout<<"\nEnter command: ";
|
cout<<"\nEnter command: ";
|
||||||
|
cout<<"OK\n";
|
||||||
cin>>move;
|
cin>>move;
|
||||||
b.interpret(move,b);
|
b.interpret(move,b);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue