Back to index

gcompris  8.2.2
Classes | Defines | Functions
awele_utils.h File Reference
#include "gcompris/gcompris.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  AWALE
 Definition nouveaux types de variables. More...

Defines

#define FALSE   0
#define NBHOLE   12
#define NBTOTALBEAN   48
#define NBPLAYER   2
#define HUMAN   0
#define COMPUTER   1
#define START_HUMAN   0
#define START_COMPUTER   6
#define END_HUMAN   5
#define END_COMPUTER   11
#define NBBEANSPERHOLE   4
#define HALF_SIZE   6
#define DEF_DEPTH   3
#define INFINI   50
#define EMPTY_HOLE   51
#define HUNGRY   52
#define GAMEOVER   53
#define NOT_GAMEOVER   54
#define MSG_FAMINE   "declenche une famine"
#define MSG_AREA   "clic dans ton camp"
#define MSG_EMPTYHOLE   "Cette case est vide, selectionne une autre case"

Functions

gboolean diedOfHunger (AWALE *aw)
 Fonction de manipulation de l'awale.
AWALEmoveAwale (short int hole, AWALE *aw)
 Fonction de test si case non vide Test si la case choisie n'est pas vide.
short int think (AWALE *a, 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.
short int randplay (AWALE *a)
 Fonction coup Aleatoire Cette fonction permet de generer un coup aleatoire.
short int switch_player (short int player)
 Fonction de chgt de joueur Cette fonction permet de renvoyer la valeur de l'opposant.
short int threatenDelta (AWALE *aw)
short int moveDelta (AWALE *aw)
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.

Class Documentation

struct AWALE

Definition nouveaux types de variables.

Definition at line 52 of file awele_utils.h.

Class Members
short int board
short int CapturedBeans
short int last_play
short int player

Define Documentation

#define COMPUTER   1

Definition at line 26 of file awele_utils.h.

#define DEF_DEPTH   3

Definition at line 33 of file awele_utils.h.

#define EMPTY_HOLE   51

Definition at line 39 of file awele_utils.h.

#define END_COMPUTER   11

Definition at line 30 of file awele_utils.h.

#define END_HUMAN   5

Definition at line 29 of file awele_utils.h.

#define FALSE   0

Definition at line 19 of file awele_utils.h.

#define GAMEOVER   53

Definition at line 41 of file awele_utils.h.

#define HALF_SIZE   6

Definition at line 32 of file awele_utils.h.

#define HUMAN   0

Definition at line 25 of file awele_utils.h.

#define HUNGRY   52

Definition at line 40 of file awele_utils.h.

#define INFINI   50

Definition at line 34 of file awele_utils.h.

#define MSG_AREA   "clic dans ton camp"

Definition at line 45 of file awele_utils.h.

#define MSG_EMPTYHOLE   "Cette case est vide, selectionne une autre case"

Definition at line 46 of file awele_utils.h.

#define MSG_FAMINE   "declenche une famine"

Definition at line 44 of file awele_utils.h.

#define NBBEANSPERHOLE   4

Definition at line 31 of file awele_utils.h.

#define NBHOLE   12

Definition at line 22 of file awele_utils.h.

#define NBPLAYER   2

Definition at line 24 of file awele_utils.h.

#define NBTOTALBEAN   48

Definition at line 23 of file awele_utils.h.

#define NOT_GAMEOVER   54

Definition at line 42 of file awele_utils.h.

#define START_COMPUTER   6

Definition at line 28 of file awele_utils.h.

#define START_HUMAN   0

Definition at line 27 of file awele_utils.h.


Function Documentation

gboolean diedOfHunger ( AWALE aw)

Fonction de manipulation de l'awale.

Definition at line 150 of file awele_utils.c.

{
  gint begin = (aw->player == HUMAN) ? 6 : 0;
  gint k;

  if (isOpponentHungry(switch_player(aw->player), aw)){
    for (k=0; k <6; k++){
      if ( aw->board[begin+k] > 6 - k)
       return FALSE;
    }
    g_warning("%s is died of hunger", (aw->player == HUMAN) ? "HUMAN" : "COMPUTER");
    return TRUE;
  }
  else
    return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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:

AWALE* moveAwale ( short int  hole,
AWALE aw 
)

Fonction de test si case non vide Test si la case choisie n'est pas vide.

Parameters:
holeentier designant la case du plateau choisie
awpointeur sur la structure AWALE courante.

Definition at line 52 of file awele_utils.c.

{
  AWALE *tempAw, *tempAwGs;
  gboolean has_capture = FALSE;

  if (!aw->board[hole]){
    return NULL;
  }

  short int nbBeans, j, last;
  
  tempAw = g_malloc(sizeof(AWALE));
  
  memcpy(tempAw, aw, sizeof(AWALE));

  tempAw->last_play = hole;

  nbBeans = tempAw->board[hole];
  tempAw->board[hole] = 0;
  
  // DĂ©placement des graines
  for (j = 1, last = (hole+1)%12 ; j <= nbBeans; j++) {
    tempAw->board[last] += 1;
    last = (last + 1) % 12;
    if (last == hole)
      last = (last +1)% 12;
  }

  last = (last +11) %12;

  /* Grand Slam (play and no capture because this let other player hungry */
  tempAwGs = g_malloc(sizeof(AWALE));
  memcpy(tempAwGs, tempAw, sizeof(AWALE));

  // capture
  while ((last >= ((tempAw->player == HUMAN)? 0 : 6))
         && (last < ((tempAw->player == HUMAN)? 6 : 12))){
    if ((tempAw->board[last] == 2) || (tempAw->board[last] == 3)){
      has_capture = TRUE;
      tempAw->CapturedBeans[switch_player(tempAw->player)] += tempAw->board[last];
      tempAw->board[last] = 0;
      last = (last+11)%12;
      continue;
    }
    break;
  }

  if (isOpponentHungry(tempAw->player, tempAw)){
    if (has_capture){
      /* Grand Slam case */
      //g_warning("Grand Slam: no capture");
      g_free(tempAw);
      return tempAwGs;
    } else{
      /* No capture and  opponent hungry -> forbidden */
      //g_warning("isOpponentHungry %s TRUE",(tempAw->player == HUMAN)? "HUMAN" : "COMPUTER" );
      g_free(tempAw);
      g_free(tempAwGs);
      return NULL;
    }
  }    
  else {
    tempAw->player = switch_player(tempAw->player);
    return tempAw;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

short int moveDelta ( AWALE aw)
short int randplay ( AWALE a)

Fonction coup Aleatoire Cette fonction permet de generer un coup aleatoire.

Parameters:
apointeur sur la structure AWALE courante
Returns:
un entier representant le coup a jouer

Definition at line 136 of file awele_utils.c.

{
    short int i;
    AWALE *tmp = NULL;

    do {
       i = 6 + rand() % 6;
    } while (a->board[i] == 0 && !(tmp = moveAwale(i, a)));

    g_free(tmp);
    return (i);
}

Here is the call graph for this function:

short int switch_player ( short int  player)

Fonction de chgt de joueur Cette fonction permet de renvoyer la valeur de l'opposant.

Parameters:
playerun entier representant le joueur courant
Returns:
un entier representant l'opposant

Definition at line 125 of file awele_utils.c.

{
    return (player == HUMAN) ? COMPUTER : HUMAN;
}

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:

short int threatenDelta ( AWALE aw)