void testDoubling() {
  printf("\n\nTEST ACCETTAZIONE DOUBLE...\n");
  int b[2][25] = 
  {
    {2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//ALL BEARED OFF 
    {0, 3, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0},//ALL BEARED OFF
    //{2, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    //{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0}
  };

  ms.anScore[0] = 0;
  ms.anScore[1] = 0;
  ms.nMatchTo = 7;


  ms.fMove = 0;
  ms.fTurn = 1;
  ms.fCubeOwner = -1;
  setBoard((ConstTanBoard)b);
  printBoard(msBoard());
  printf("ACCETTAZIONE: %s\n\n", acceptDouble()?"OK":"NO");

  ms.fMove = 1;
  ms.fTurn = 0;
  ms.fCubeOwner = -1;
  SwapSides(ms.anBoard);
  printBoard(msBoard());
  printf("ACCETTAZIONE: %s\n", acceptDouble()?"OK":"NO");
}
Exemple #2
0
static void
MoveListMove(GtkWidget * pw, hintdata * phd)
{
    move m;
    move *pm;
    char szMove[40];
    GList *plSelList = MoveListGetSelectionList(phd);
    if (!plSelList)
        return;

    ShowMove(phd, TRUE);
    pm = MoveListGetMove(phd, plSelList);
    MoveListFreeSelectionList(plSelList);

    memcpy(&m, pm, sizeof(move));

    if (phd->fDestroyOnMove)
        /* Destroy widget on exit */
        gtk_widget_destroy(gtk_widget_get_toplevel(pw));

    FormatMove(szMove, msBoard(), m.anMove);
    UserCommand(szMove);

#if USE_BOARD3D
    RestrictiveRedraw();
#endif
}
Exemple #3
0
extern void
ShowMove(hintdata * phd, const int f)
{
    char *sz;
    TanBoard anBoard;
    if (f) {
        move *pm;
        GList *plSelList = MoveListGetSelectionList(phd);
        if (!plSelList)
            return;

        /* the button is toggled */
        pm = MoveListGetMove(phd, plSelList);

        MoveListFreeSelectionList(plSelList);

        memcpy(anBoard, msBoard(), sizeof(TanBoard));
        ApplyMove(anBoard, pm->anMove, FALSE);

        UpdateMove((BOARD(pwBoard))->board_data, anBoard);
    } else {

        sz = g_strdup("show board");
        UserCommand(sz);
        g_free(sz);

    }
#if USE_BOARD3D
    RestrictiveRedraw();
#endif
}
//NOT USED!
extern int TryBearoff(ConstTanBoard b, int dice0, int dice1) {

  movelist ml;
  unsigned int i, iMove, cMoves;

  if (ClassifyPosition(msBoard(), VARIATION_STANDARD) > CLASS_RACE) {
    /* It's a contact position; don't automatically bear off */
    printf("> CLASS_RACE!\n");
    return -2;
  }

  GenerateMoves(&ml, b, dice0, dice1, FALSE);
  cMoves = (dice0 == dice1) ? 4 : 2;

  for (i = 0; i < ml.cMoves; i++)
    for (iMove = 0; iMove < cMoves; iMove++) {
      if ((ml.amMoves[i].anMove[iMove << 1] < 0) || (ml.amMoves[i].anMove[(iMove << 1) + 1] != -1)) {
        break;
      } else if (iMove == cMoves - 1) {
        printf("OK\n");
        printMove(ml.amMoves[i].anMove);
        return 0;
      }
    }

  printf("KO\n");
  return -1;
}
void testResignation() {
  int b[2][25] = 
  {
    {2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15}
  };
  setBoard((ConstTanBoard)b);
  ms.fMove = 1;
  ms.fTurn = 0;
  ms.nCube = -1;
  ms.fCubeOwner = 1;
  ms.anScore[0] = 0;
  ms.anScore[1] = 0;
  ms.nMatchTo = 7;

  printf("\n\nTEST ACCETTAZIONE RESIGN...\n");
  printBoard(msBoard());
  printf("RESIGN 1: %s\n", acceptResign(1)?"OK":"NO");
  printf("RESIGN 2: %s\n", acceptResign(2)?"OK":"NO");
  printf("RESIGN 3: %s\n", acceptResign(3)?"OK":"NO");
  printf("AIlevel: %d\n\n", currentAILevel);
}
Exemple #6
0
/*
 * Call UpdateMostList to update the movelist in the GTK hint window.
 * For example, after new evaluations, rollouts or toggle of MWC/Equity.
 *
 */
extern void MoveListUpdate ( const hintdata *phd )
{
  unsigned int i, j, colNum;
  char sz[ 32 ];
  cubeinfo ci;
  movelist *pml = phd->pml;
  int col = phd->fDetails ? 8 : 2;
  int showWLTree = showMoveListDetail && !phd->fDetails;

  int offset = (phd->fDetails) ? 0 : MIN_COLUMN_COUNT - DETAIL_COLUMN_COUNT;
  GtkTreeIter iter;
  GtkListStore *store;
  store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(phd->pwMoves)));
  gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);

  if (!psHighlight)
  { /* Get highlight style first time in */
    GtkStyle *psTemp;
    GtkStyle *psMoves = gtk_widget_get_style(phd->pwMoves);
    GetStyleFromRCFile(&psHighlight, "move-done", psMoves);
    /* Use correct background colour when selected */
    memcpy(&psHighlight->bg[GTK_STATE_SELECTED], &psMoves->bg[GTK_STATE_SELECTED], sizeof(GdkColor));

    /* Also get colour to use for w/l stats in detail view */
    GetStyleFromRCFile(&psTemp, "move-winlossfg", psMoves);
    memcpy(&wlCol, &psTemp->fg[GTK_STATE_NORMAL], sizeof(GdkColor));
    g_object_unref(psTemp);
  }

  /* This function should only be called when the game state matches
     the move list. */
  g_assert( ms.fMove == 0 || ms.fMove == 1 );

  GetMatchStateCubeInfo( &ci, &ms );
  rBest = pml->amMoves[ 0 ].rScore;

  if (!showWLTree)
    gtk_tree_view_column_set_title(gtk_tree_view_get_column(GTK_TREE_VIEW(phd->pwMoves), col),
        (fOutputMWC && ms.nMatchTo) ? _("MWC") : _("Equity"));

  for( i = 0; i < pml->cMoves; i++ )
  {
    float *ar = pml->amMoves[ i ].arEvalMove;
    int rankKnown;
    char *highlight_sz;

    if (showWLTree)
      gtk_list_store_set(store, &iter, 0, pml->amMoves + i, -1);
    else
      gtk_list_store_set(store, &iter, ML_COL_DATA + offset, pml->amMoves + i, -1);

    rankKnown = 1;
    if( i && i == pml->cMoves - 1 && phd->piHighlight && i == *phd->piHighlight )
      /* The move made is the last on the list.  Some moves might
         have been deleted to fit this one in */
    {
      /* Lets count how many moves are possible to see if this is the last move */
      movelist ml;
      int dice[2];
      memcpy(dice, ms.anDice, sizeof(dice));
      if (!dice[0])
      { /* If the dice have got lost, try to find them */
        moverecord* pmr = (moverecord*)plLastMove->plNext->p;
        if (pmr)
        {
          dice[0] = pmr->anDice[0];
          dice[1] = pmr->anDice[1];
        }
      }
      GenerateMoves(&ml, msBoard(), dice[0], dice[1], FALSE);
      if (i < ml.cMoves - 1)
        rankKnown = 0;
    }

    highlight_sz = (phd->piHighlight && *phd->piHighlight == i) ? "*" : "";

    if (rankKnown)
      sprintf( sz, "%s%s%d", pml->amMoves[i].cmark ? "+" : "", highlight_sz, i + 1 );
    else
      sprintf( sz, "%s%s??", pml->amMoves[i].cmark ? "+" : "", highlight_sz );

    if (showWLTree)
    {
      gtk_list_store_set(store, &iter, 1, rankKnown ? (int)i + 1 : -1, -1);
      goto skipoldcode;
    }
    else
      gtk_list_store_set(store, &iter, ML_COL_RANK, sz, -1);
    FormatEval( sz, &pml->amMoves[ i ].esMove );
    gtk_list_store_set(store, &iter, ML_COL_TYPE, sz, -1);

    /* gwc */
    if ( phd->fDetails )
    {
      colNum = ML_COL_WIN;
      for( j = 0; j < 5; j++ ) 
      {
        if (j == 3)
        {
          gtk_list_store_set(store, &iter, colNum, OutputPercent(1.0f - ar[ OUTPUT_WIN ] ), -1);
          colNum++;
        }
        gtk_list_store_set(store, &iter, colNum, OutputPercent(ar[j]), -1);
        colNum++;
      }
    }

    /* cubeless equity */
    gtk_list_store_set(store, &iter, ML_COL_EQUITY + offset,
        OutputEquity( pml->amMoves[ i ].rScore, &ci, TRUE ), -1);
    if (i != 0)
    {
      gtk_list_store_set(store, &iter, ML_COL_DIFF + offset,
          OutputEquityDiff( pml->amMoves[ i ].rScore, 
            rBest, &ci ), -1);
    }

    gtk_list_store_set(store, &iter, ML_COL_MOVE + offset,
        FormatMove( sz, msBoard(),
          pml->amMoves[ i ].anMove ), -1);

    /* highlight row */
    if (phd->piHighlight && *phd->piHighlight == i)
    {
      char buf[20];
      sprintf(buf, "#%02x%02x%02x", psHighlight->fg[GTK_STATE_SELECTED].red / 256, psHighlight->fg[GTK_STATE_SELECTED].green / 256, psHighlight->fg[GTK_STATE_SELECTED].blue / 256);
      gtk_list_store_set(store, &iter, ML_COL_FGCOL + offset, buf, -1);
    }
    else
      gtk_list_store_set(store, &iter, ML_COL_FGCOL + offset, NULL, -1);
skipoldcode:  /* Messy as 3 copies of code at moment... */
    gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
  }

}
Exemple #7
0
static void
MoveListRolloutClicked(GtkWidget * pw, hintdata * phd)
{
    cubeinfo ci;
    int i, c, res;
    move *m;
    int *ai;
    void *p;
    GList *pl, *plSelList = MoveListGetSelectionList(phd);
    if (!plSelList)
        return;

    GetMatchStateCubeInfo(&ci, &ms);

    c = g_list_length(plSelList);

    /* setup rollout dialog */
    {
        move **ppm = (move **) malloc(c * sizeof(move *));
        cubeinfo **ppci = (cubeinfo **) malloc(c * sizeof(cubeinfo *));
        char (*asz)[40] = (char (*)[40]) malloc(40 * c);

        for (i = 0, pl = plSelList; i < c; pl = pl->next, i++) {
            m = ppm[i] = MoveListGetMove(phd, pl);
            ppci[i] = &ci;
            FormatMove(asz[i], msBoard(), m->anMove);
        }
        MoveListFreeSelectionList(plSelList);

        GTKSetCurrentParent(pw);
        RolloutProgressStart(&ci, c, NULL, &rcRollout, asz, FALSE, &p);

        res = ScoreMoveRollout(ppm, (const cubeinfo **) ppci, c, RolloutProgress, p);

        RolloutProgressEnd(&p, FALSE);

        free(asz);
        free(ppm);
        free(ppci);

        if (res < 0)
            return;

        /* If the source widget parent has been destroyed do not attempt
         * to update the hint window */
        if (!GDK_IS_WINDOW(gtk_widget_get_parent_window(pw)))
            return;

        /* Calling RefreshMoveList here requires some extra work, as
         * it may reorder moves */
        MoveListUpdate(phd);
    }

    MoveListClearSelection(0, 0, phd);

    ai = (int *) malloc(phd->pml->cMoves * sizeof(int));
    RefreshMoveList(phd->pml, ai);

    if (phd->piHighlight && phd->pml->cMoves)
        *phd->piHighlight = ai[*phd->piHighlight];

    free(ai);

    find_skills(phd->pmr, &ms, -1, -1);
    MoveListUpdate(phd);
    if (phd->hist) {
        SetAnnotation(pmrCurAnn);
        ChangeGame(NULL);
    }
}