Bonjour à tous, je dois appliquer l'algorithme Minmax en C à un Morpion (ou Tic Tac Toe)... Le problème est que je ne sais pas du tout comment faire...
voici une partie de mon programme :
#include "tictactoe.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
// Ask for the user to enter its move using the keyboard
void HumanPlayer(TicTacToe *Game);
// Random selection of the move
void RandomPlayer(TicTacToe *Game);
void AIPlayer(TicTacToe *Game);
int MinMax(TicTacToe *Game,char Mark, int *ptBest_Move);
int main(int argc, char *argv[])
{
TicTacToe *Game=new TicTacToe; // Create a po inter on a TicTacToe object
srand ( time(NULL) ); // Initialyze pseudo random generaor using current time
// ::: Game core :::
Game->DrawGame(); // Show the game
while (Game->GameOver()==0) { // Play until the game is over
if (Game->CurrentPlayer()==CROSS) { // Current player is player one
cout << "\n ::: Player 1 (Crosses) :::\n";
HumanPlayer(Game); // Player 1 is the human player
Game->DrawGame(); // Draw the game after the move
}
else {
cout << "\n::: Player 2 (Circles) :::\n";
RandomPlayer(Game); // Player 2 is a random player
Game->DrawGame(); // Draw the game after the move
}
}
// ::: End of the game :::
std::cout << "\n ::: Game Over ::: \n\n";
Game->DrawGame();
switch (Game->GameOver()) { // Print the result of the game
case CROSS : cout << "\nPlayer 1 wins (CROSSES)\n"; break; // Player 1 is winning
case CIRCLE : cout << "\nPlayer 2 wins (CIRCLES)\n"; break; // Player 2 is winning
case DRAW : cout << "\nDraw !\n"; // Draw game
}
}
// ::: Play randomly a move :::
void RandomPlayer(TicTacToe *Game)
{
int Cell=random()%9+1; // Randomly select a move
while (Game->Play(Cell)==0) // while the move is not possible...
Cell=random()%9+1; // ... select a new one
}
// ::: Human player :::
void HumanPlayer(TicTacToe *Game)
{
int Cell;
do
{
cout << "Dans quelle case jouez-vous : "; // Print a message for the user
cin >> Cell; // Read the move to the keyboard
}
while (Game->Play(Cell)==0); // Until the move is possible
}
void AIPlayer(TicTacToe *Game)
{
int Move;
MinMax(Game,Game->CurrentPlayer(),&Move);
Game->Play(Move);
}
int MinMax(TicTacToe *Game,char Mark, int *ptBest_Move)
{
//je dois compléter mais par quoi????
}
Merci d'avance pour votre aide...
Partager