Esempio n. 1
0
static char *
ExtEvaluation(scancontext * pec)
{
    ProcessedFIBSBoard processedBoard;
    float arOutput[NUM_ROLLOUT_OUTPUTS];
    cubeinfo ci;
    int anScore[2];
    char *szResponse;
    float r;
    evalcontext ec;

    if (ProcessFIBSBoardInfo(&pec->bi, &processedBoard)) {
        szResponse = g_strdup_printf("Error: badly formed board\n");
    } else {

        anScore[0] = processedBoard.nScoreOpp;
        anScore[1] = processedBoard.nScore;
        /* If the session isn't using Crawford rule, set crawford flag to false */
        processedBoard.fCrawford = pec->fCrawfordRule ? processedBoard.fCrawford : FALSE;
        /* Set the Jacoby flag appropriately from the external interface settings */
        processedBoard.fJacoby = pec->fJacobyRule;

        /* printf ("Jacoby Setting: %d\n", fJacoby); */
        /* printf ("Crawford Setting: %d\n", fCrawford); */

        SetCubeInfo(&ci, processedBoard.nCube, processedBoard.fCubeOwner, 1, processedBoard.nMatchTo,
                    anScore, processedBoard.fCrawford, processedBoard.fJacoby, nBeavers, bgvDefault);

        ec.fCubeful = pec->fCubeful;
        ec.nPlies = pec->nPlies;
        ec.fUsePrune = pec->fUsePrune;
        ec.fDeterministic = pec->fDeterministic;
        ec.rNoise = pec->rNoise;

        if (GeneralEvaluationE(arOutput, (ConstTanBoard) processedBoard.anBoard, &ci, &ec))
            return NULL;

        if (processedBoard.nMatchTo) {
            if (ec.fCubeful)
                r = arOutput[OUTPUT_CUBEFUL_EQUITY];
            else
                r = eq2mwc(arOutput[OUTPUT_EQUITY], &ci);
        } else
            r = ec.fCubeful ? arOutput[6] : arOutput[5];

        szResponse = g_strdup_printf("%f %f %f %f %f %f\n",
                                     arOutput[0], arOutput[1], arOutput[2], arOutput[3], arOutput[4], r);
    }

    return szResponse;

}
extern void EvaluateRoll(float ar[NUM_ROLLOUT_OUTPUTS], int nDie1, int nDie2, const TanBoard anBoard,
             const cubeinfo * pci, const evalcontext * pec)
{
    TanBoard anBoardTemp;
    cubeinfo ciOpp;

    memcpy(&ciOpp, pci, sizeof(cubeinfo));
    ciOpp.fMove = !pci->fMove;

    memcpy(&anBoardTemp[0][0], &anBoard[0][0], 2 * 25 * sizeof(int));

    if (FindBestMove(NULL, nDie1, nDie2, anBoardTemp, pci, NULL, defaultFilters) < 0)
        g_assert_not_reached();

    SwapSides(anBoardTemp);

    GeneralEvaluationE(ar, (ConstTanBoard) anBoardTemp, &ciOpp, pec);

    return;
}
Esempio n. 3
0
static void
add_level(GtkTreeStore * model, GtkTreeIter * iter,
          const int n, const TanBoard anBoard,
          evalcontext * pec, cubeinfo * pci, const gboolean fInvert, float arOutput[NUM_ROLLOUT_OUTPUTS])
{

    int n0, n1;
    GtkTreeIter child_iter;
    cubeinfo ci;
    TanBoard an;
    float ar[NUM_ROLLOUT_OUTPUTS];
    int anMove[8];
    int i;

    char szRoll[3], szMove[100], *szEquity;

    /* cubeinfo for opponent on roll */

    memcpy(&ci, pci, sizeof(cubeinfo));
    ci.fMove = !pci->fMove;

    for (i = 0; i < NUM_ROLLOUT_OUTPUTS; ++i)
        arOutput[i] = 0.0f;

    for (n0 = 0; n0 < 6; ++n0) {
        for (n1 = 0; n1 <= n0; ++n1) {

            memcpy(an, anBoard, sizeof(an));

            if (FindBestMove(anMove, n0 + 1, n1 + 1, an, pci, pec, defaultFilters) < 0)
                return;

            SwapSides(an);

            gtk_tree_store_append(model, &child_iter, iter);

            if (n) {

                add_level(model, &child_iter, n - 1, (ConstTanBoard) an, pec, &ci, !fInvert, ar);
                if (fInterrupt)
                    return;

            } else {

                /* evaluate resulting position */

                ProgressValueAdd(1);

                if (GeneralEvaluationE(ar, (ConstTanBoard) an, &ci, pec) < 0)
                    return;

            }

            if (fInvert)
                InvertEvaluationR(ar, &ci);

            sprintf(szRoll, "%d%d", n0 + 1, n1 + 1);
            FormatMove(szMove, anBoard, anMove);

            szEquity = OutputMWC(ar[OUTPUT_CUBEFUL_EQUITY], fInvert ? pci : &ci, TRUE);

            gtk_tree_store_set(model, &child_iter, 0, szRoll, 1, szMove, 2, szEquity, -1);

            for (i = 0; i < NUM_ROLLOUT_OUTPUTS; ++i)
                arOutput[i] += (n0 == n1) ? ar[i] : 2.0f * ar[i];

        }

    }

    for (i = 0; i < NUM_ROLLOUT_OUTPUTS; ++i)
        arOutput[i] /= 36.0f;

    /* add average equity */

    szEquity = OutputMWC(arOutput[OUTPUT_CUBEFUL_EQUITY], fInvert ? pci : &ci, TRUE);

    gtk_tree_store_append(model, &child_iter, iter);

    gtk_tree_store_set(model, &child_iter, 0, _("Average equity"), 1, "", 2, szEquity, -1);

    if (!fInvert)
        InvertEvaluationR(arOutput, pci);

}
Esempio n. 4
0
static char *
ExtEvaluation( extcmd *pec ) {

  char szName[ MAX_NAME_LEN ], szOpp[ MAX_NAME_LEN ];
  int nMatchTo, anScore[ 2 ],
    anDice[ 2 ], nCube, fCubeOwner, fDoubled, fCrawford, fJacoby;
  TanBoard anBoard;
  float arOutput[ NUM_ROLLOUT_OUTPUTS ];
  cubeinfo ci;
  int nScore, nScoreOpponent;
  char *szResponse;
  float r;
  evalcontext ec;

  if( ParseFIBSBoard( pec->szFIBSBoard, anBoard, szName, szOpp, &nMatchTo,
                      &nScore, &nScoreOpponent, anDice, &nCube,
                      &fCubeOwner, &fDoubled, &fCrawford ) ) {
    outputl( _("Warning: badly formed board from external controller.") );
    szResponse = 
      g_strdup_printf( "Error: badly formed board ('%s')\n", pec->szFIBSBoard );
  }
  else {
    
    anScore[ 0 ] = nScoreOpponent;
    anScore[ 1 ] = nScore;
	/* If the session isn't using Crawford rule, set crawford flag to false */
	fCrawford = pec->fCrawfordRule ? fCrawford : FALSE;
	/* Set the Jacoby flag appropriately from the external interface settings */
	fJacoby   = pec->fJacobyRule;

	/* printf ("Jacoby Setting: %d\n", fJacoby);*/
	/* printf ("Crawford Setting: %d\n", fCrawford); */
    
    SetCubeInfo ( &ci, nCube, fCubeOwner, 1, nMatchTo, anScore,
                  fCrawford, fJacoby, nBeavers, bgvDefault ); 

    ec.fCubeful = pec->fCubeful;
    ec.nPlies = pec->nPlies;
    ec.fUsePrune = pec->fUsePrune;
    ec.fDeterministic = pec->fDeterministic;
    ec.rNoise = pec->rNoise;

    if ( GeneralEvaluationE( arOutput, (ConstTanBoard)anBoard, &ci, &ec ) )
      return NULL;

    if ( nMatchTo ) {
      if ( ec.fCubeful )
        r = arOutput[ OUTPUT_CUBEFUL_EQUITY ];
      else
        r = eq2mwc( arOutput[ OUTPUT_EQUITY ], &ci );
    }
    else
      r = ec.fCubeful ? arOutput[ 6 ] : arOutput[ 5 ];
    
    szResponse = g_strdup_printf( "%f %f %f %f %f %f\n",
                                  arOutput[ 0 ],
                                  arOutput[ 1 ],
                                  arOutput[ 2 ],
                                  arOutput[ 3 ],
                                  arOutput[ 4 ],
                                  r );
  }

  return szResponse;

}