I think this looks very promising, keep up your work :-)
Btw your current code caused a segfault here after the 5th round...

Bye,
Michael Prager


[EMAIL PROTECTED] wrote:

Hello all,
I promised you last sunday a beginning of AI player
implementation ; sorry for the delay. Here is my proposal.

The AI might be composed by two classes. The first class (I
named it "Strategie" since all the classes names are in
french) concerns the computation of the optimal AI strategy.
It is a pure virtual class, since it can be implemeted by
much different ways. We can imagine, for example, that the
user can choose his AI algorithm in the team menu. I proposed that an AI strategy relies on a few elements :

- The worm who plays
- The weapon choosen
- The shoot position
- The shoot direction
- The shoot angle
- The shoot force
- The end-of-turn position (after the shoot)

The second element of the AI player should be an "artificial
player", that I named "Ordinateur". Its role is to play the
choosen strategy like a "human" player. For each game turn,
each AI player starts its turn computing the otimal
strategy. Then, there is no more calculations, the turn is
played sequencially. For example, the worms are switched,
then, the worm moves. Then, the weapon is changed. Then, the
angle is changed, etc. It is possible for example to manage
"pauses" in the action, as if the worm is thinking. The only public function of Ordinateur is Ordinateur::Joue.
This function must be called just instead of
"souris.Gestion(); clavier.Gestion();".

I tried to induce minimal changes on the existing code, so
my implementation attempt might be not the best one. I
propose to add a pointer to an Ordinateur class in the class
Equipe. This pointer is set to NULL in the Equipe
constructor. Is the Equipe is controlled by a human player,
it will always be NULL, and nothing happens. On the
contrary, if the Equipe is an AI player, an Ordinateur class
is created (and deleted at the end of the turn).

Here is a patch illustrating this (note that all the teams
will be controlled by the computer):

Index: bcl_jeu.cpp
===================================================================
RCS file: /cvs/wormux/wormux/src/bcl_jeu.cpp,v
retrieving revision 1.14
diff -u -r1.14 bcl_jeu.cpp
--- bcl_jeu.cpp 4 Jul 2004 21:26:14 -0000       1.14
+++ bcl_jeu.cpp 7 Jul 2004 17:17:54 -0000
@@ -44,6 +44,8 @@
#include "interface.h"
#include "vent.h"
#include <sstream>
+
+#include "ordinateur.h"
using namespace Wormux;
//-----------------------------------------------------------------------------
@@ -157,8 +159,15 @@
        || (etat == jeuVER_A_JOUE)
        || ((etat == jeuPAUSE_FIN_TOUR))))
    {
-      souris.Gestion();
-      clavier.Gestion();
+      if (EquipeActive().Ordi() != NULL)
+      {
+        (EquipeActive().Ordi())->Joue();
+      }
+         else
+      {
+        souris.Gestion();
+        clavier.Gestion();
+      }
    }

    // Gestion des vers

Index: equipe.cpp
===================================================================
RCS file: /cvs/wormux/wormux/src/equipe.cpp,v
retrieving revision 1.18
diff -u -r1.18 equipe.cpp
--- equipe.cpp  4 Jul 2004 21:26:14 -0000       1.18
+++ equipe.cpp  7 Jul 2004 17:17:56 -0000
@@ -43,6 +43,7 @@
Equipe::Equipe()
{
  vers_fin = vers.end();
+  ordinateur = NULL;
}

//-----------------------------------------------------------------------------@@
-227,6 +228,7 @@
// Prepare le tour d'une equipe
void Equipe::PrepareTour()
{
+  ordinateur = new Ordinateur();
  // Choisi un ver vivant si possible
  if (VerActif().EstMort())
  {
@@ -252,6 +254,8 @@
  // D&#65533;sactive notre arme
  (*arme_active).Desactive();
  camera_est_sauve = true;
+  if (ordinateur != NULL)
+    delete ordinateur;
  sauve_camera = CL_Point(camera.LitX(), camera.LitY());
}



Index: equipe.h
===================================================================
RCS file: /cvs/wormux/wormux/src/equipe.h,v
retrieving revision 1.11
diff -u -r1.11 equipe.h
--- equipe.h    4 Jul 2004 21:26:14 -0000       1.11
+++ equipe.h    7 Jul 2004 17:17:57 -0000
@@ -32,6 +32,8 @@
#include <ClanLib/display.h>
#include <string>
#include <list>
+
+#include "ordinateur.h"
//-----------------------------------------------------------------------------
class Equipe
@@ -63,6 +65,7 @@
  EnergieEquipe energie;

private:
+  Ordinateur * ordinateur;
  std::string m_nom;
  std::string m_nomfich;
  std::string m_profile_son;
@@ -126,6 +129,8 @@
  // (renvoie MUNITION_ILLIMITEES si les munitions sont
illimit&#65533;es)
  int& AccesNbrMunition();
  int LitNbrMunition() const;
+
+  Ordinateur * Ordi() {return ordinateur;}

protected:
  void PasseVerSuivant();


For the moment, my AI player is very simple: the worm is
randomly chosen, and it does not move. It just shoot against
the nearest ennemy with the gun (in fact, it is still very
bad). Please, do not consider it as a definitive
implementation, but rather as an example. The code is still
very dirty. The files "ordinateur.h", "ordinateur.cpp",
"strategie.h" and "strategy.cpp" are joined to the message.

I just want to know what do you think about that. It should
be nice, for example, if it was possible to discuss the
inclusion of the path into the CVS tree, except for the line
"ordinateur = new Ordinateur();", which can be commented.
In this case, nobody will be able to see any difference of
behaviour with the older version, but people who want to
work on the AI improvement just have to uncomment this line
to get a completely functionnal artificial player.

Arnaud.

////////////////////////////////////////////////////////////
// Webmail Oreka : http://www.oreka.com
////////////////////////////////////////////////////////////

Répondre à