working on AI
This commit is contained in:
parent
67c3b463db
commit
c9ab7c2622
4 changed files with 16 additions and 25 deletions
38
Board.cpp
38
Board.cpp
|
@ -87,8 +87,7 @@ void Board::changeTurns()
|
|||
}
|
||||
|
||||
void Board::displayBoard()
|
||||
{
|
||||
cout<<"\n\n";
|
||||
{
|
||||
cout<<"; A B C D E F G H"<<endl;
|
||||
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)
|
||||
{
|
||||
vector<Board> record;
|
||||
|
@ -545,17 +535,19 @@ void Board::easyAI()
|
|||
|
||||
vector<moves> listOfMoves = viewPossibleMoves();
|
||||
|
||||
//2) pick a movement
|
||||
|
||||
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;
|
||||
|
||||
move(listOfMoves[randomChoice]);
|
||||
|
||||
//cout<<"\n\nMove executed by AI: "<<listOfMoves[temp].column<<" "<<listOfMoves[temp].row<<" "<<listOfMoves[temp].moveType<<endl; uncomment for debugging purposes
|
||||
//obvious moves
|
||||
if (){
|
||||
//
|
||||
}
|
||||
|
||||
//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;
|
||||
|
||||
move(listOfMoves[randomChoice]);
|
||||
}
|
||||
}
|
1
Board.h
1
Board.h
|
@ -37,7 +37,6 @@ public:
|
|||
bool isThisMovePossible(int r, int c, string moveType);
|
||||
vector<moves> viewPossibleMoves();
|
||||
string myToUpper(string input);
|
||||
void displayPossibleMoves(vector<moves> input);
|
||||
void undo(Board& tablero);
|
||||
void interpret(string input, Board& tablero);
|
||||
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();
|
||||
//displayPossibleMoves(possibleMoves); for debugging purposes - AI
|
||||
|
||||
if (choice == 1)
|
||||
{
|
||||
|
@ -53,6 +52,7 @@ int main()
|
|||
{
|
||||
b.displayBoard();
|
||||
cout<<"\nEnter command: ";
|
||||
cout<<"OK\n";
|
||||
cin>>move;
|
||||
b.interpret(move,b);
|
||||
}
|
||||
|
|
Reference in a new issue