Back to index

gcompris  8.2.2
Functions | Variables
awele_alphaBeta.c File Reference
#include "awele_utils.h"
#include <string.h>
#include <stdlib.h>
#include "gcompris/gcompris.h"

Go to the source code of this file.

Functions

gint eval (GNode *node)
 Fonction d'evaluation d'un plateau La fonction d'evaluation va evaluer la difference du nombre de graines capturees (Facteur preponderant),
la difference de la mobilite des deux joueurs, la difference des cases menacantes,
et la difference du nombre de graine active de chaque joueur.
gint eval_to_null (GNode *node)
gint eval_to_best_capture (GNode *node)
GNode * firstChild (GNode *node)
GNode * nextSibling (GNode *node)
gboolean free_awale (GNode *node, gpointer data)
short int think (AWALE *static_awale, short int level)
 Fonction de jeu de la machine Cette Fonction est appelee pour faire jouer l'ordinateur,
la racine de l'arbre est cree, puis passe en argument a la fonction AlphaBeta
La profondeur augmente au fur et mesure de la partie quand le nombre de graines diminue.

Variables

static gint maxprof

Function Documentation

gint eval ( GNode *  node)

Fonction d'evaluation d'un plateau La fonction d'evaluation va evaluer la difference du nombre de graines capturees (Facteur preponderant),
la difference de la mobilite des deux joueurs, la difference des cases menacantes,
et la difference du nombre de graine active de chaque joueur.


Parameters:
AWALE*aw Pointeur sur la structure AWALE a evaluer
Returns:
Une note d'evaluation du plateau.

Definition at line 31 of file awele_alphaBeta.c.

                       {
  AWALE *aw = node->data;

  if (aw->CapturedBeans[COMPUTER] > 24)
    return 25;

  if (aw->CapturedBeans[HUMAN] > 24)
    return -25;

  return (aw->CapturedBeans[COMPUTER] - aw->CapturedBeans[HUMAN]);
}

Here is the caller graph for this function:

gint eval_to_best_capture ( GNode *  node)

Definition at line 54 of file awele_alphaBeta.c.

                                       {
  AWALE *aw = node->data;

  return (aw->CapturedBeans[COMPUTER]);
}

Here is the caller graph for this function:

gint eval_to_null ( GNode *  node)

Definition at line 49 of file awele_alphaBeta.c.

                               {
  return 0;
}

Here is the caller graph for this function:

GNode* firstChild ( GNode *  node)

Definition at line 63 of file awele_alphaBeta.c.

{
  AWALE *aw = node->data;
  AWALE *tmpaw;
  GNode *tmpnode;
  gint eval_node = eval(node);
  gint rand_play;

  /* Case node is winning one */
  if ((eval_node == 25) || (eval_node == -25))
    return NULL;

  gint i;
  rand_play = RAND(1, 5);

  for (i = 0 ; i < 6; i++)
    {
      tmpaw = moveAwale((rand_play + i)%6 + ((aw->player == HUMAN )? 6 : 0), aw);
      if (tmpaw){
       tmpnode = g_node_new(tmpaw);
       g_node_insert (node, -1, tmpnode);
      }
    }
  
  return g_node_first_child(node);
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean free_awale ( GNode *  node,
gpointer  data 
)

Definition at line 97 of file awele_alphaBeta.c.

                                {
  g_free(data);
  return TRUE;
}

Here is the caller graph for this function:

GNode* nextSibling ( GNode *  node)

Definition at line 91 of file awele_alphaBeta.c.

{
  return g_node_next_sibling(node);
}

Here is the caller graph for this function:

short int think ( AWALE static_awale,
short int  level 
)

Fonction de jeu de la machine Cette Fonction est appelee pour faire jouer l'ordinateur,
la racine de l'arbre est cree, puis passe en argument a la fonction AlphaBeta
La profondeur augmente au fur et mesure de la partie quand le nombre de graines diminue.


Parameters:
awUn pointeur sur le plateau a partir duquel reflechir
Returns:
Le meilleur coup calcule par la machine le player est celui qui a joué le dernier coup.

Definition at line 114 of file awele_alphaBeta.c.

                                                       {

  AWALE *aw = g_malloc(sizeof(AWALE));
  memcpy (aw, static_awale, sizeof(AWALE));

  GNode *t = g_node_new(aw) ;

  int best = -1;
  int value = 0;
  EvalFunction use_eval = NULL;

  switch (level) {
  case 1:
    maxprof = 1;
    use_eval = (EvalFunction)&eval_to_null;
    g_warning("search depth 1, evaluation null");
    break;
  case 2:
    maxprof = 1;
    use_eval = (EvalFunction)&eval_to_best_capture;
    g_warning("search depth 1, evaluation best capture");
    break;
  case 3:
  case 4:
    maxprof = 2;
    use_eval = (EvalFunction)&eval;
    g_warning("search depth %d, evaluation best difference", maxprof);
    break;
  case 5:
  case 6:
    maxprof = 4;
    use_eval = (EvalFunction)&eval;
    g_warning("search depth %d, evaluation best difference", maxprof);
    break;
  case 7:
  case 8:
    maxprof = 6;
    use_eval = (EvalFunction)&eval;
    g_warning("search depth %d, evaluation best difference", maxprof);
    break;
  case 9:
    maxprof = 8;
    use_eval = (EvalFunction)&eval;
    g_warning("search depth %d, evaluation best difference", maxprof);
    break;
  default:
    maxprof = 8;
    use_eval = (EvalFunction)&eval;
    g_warning("search depth %d, evaluation best difference", maxprof);
    break;
  }

  value = gc_alphabeta( TRUE, 
                     t, 
                     use_eval, 
                     &best, 
                     (FirstChildGameFunction) firstChild, 
                     (NextSiblingGameFunction) nextSibling,
                     -INFINI , 
                     INFINI,
                     maxprof) ;
  
  if (best < 0){
    g_warning("Leaf node, game is over");
    return -1;
  }
  GNode *tmpNode = g_node_nth_child (t, best);
  
  AWALE *tmpaw = tmpNode->data;
  
  g_warning("THINK best : %d, play: %d", value, tmpaw->last_play);
  
  best = tmpaw->last_play;
  
  /* free awales*/
  g_node_traverse (t,
                 G_IN_ORDER,
                 G_TRAVERSE_ALL,
                 -1,
                 (GNodeTraverseFunc) free_awale,
                 NULL);

  /* free tree */
  g_node_destroy(t);

  return (best);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gint maxprof [static]

Definition at line 21 of file awele_alphaBeta.c.