Esempio n. 1
0
static char *
ExtFIBSBoard(scancontext * pec)
{
    ProcessedFIBSBoard processedBoard;
    TanBoard anBoardOrig;
    int anScore[2], anMove[8], fTurn;
    float arDouble[NUM_CUBEFUL_OUTPUTS], aarOutput[2][NUM_ROLLOUT_OUTPUTS], aarStdDev[2][NUM_ROLLOUT_OUTPUTS];
    rolloutstat aarsStatistics[2][2];
    cubeinfo ci;
    char *szResponse;

    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 ("Crawford Setting: %d\n", fCrawford); */
        /* printf ("Jacoby Setting: %d\n", fJacoby); */

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

        memcpy(anBoardOrig, processedBoard.anBoard, sizeof(processedBoard.anBoard));

        if (processedBoard.fDoubled) {

            /* take decision */
            if (GeneralCubeDecision(aarOutput, aarStdDev,
                                    aarsStatistics, (ConstTanBoard) processedBoard.anBoard, &ci, GetEvalCube(), NULL,
                                    NULL) < 0)
                return NULL;

            switch (FindCubeDecision(arDouble, aarOutput, &ci)) {
            case DOUBLE_PASS:
            case TOOGOOD_PASS:
            case REDOUBLE_PASS:
            case TOOGOODRE_PASS:
                szResponse = g_strdup("drop\n");
                break;

            case NODOUBLE_BEAVER:
            case DOUBLE_BEAVER:
            case NO_REDOUBLE_BEAVER:
                szResponse = g_strdup("beaver\n");
                break;

            default:
                szResponse = g_strdup("take\n");
            }

        } else if (pec->nResignation) {

            /* if opp wants to resign (extension to FIBS board) */

            float arOutput[NUM_ROLLOUT_OUTPUTS];
            float rEqBefore, rEqAfter;
            const float epsilon = 1.0e-6f;

            getResignation(arOutput, processedBoard.anBoard, &ci, &esEvalCube);

            getResignEquities(arOutput, &ci, pec->nResignation, &rEqBefore, &rEqAfter);

            /* if opponent gives up equity by resigning */
            if ((rEqAfter - epsilon) < rEqBefore)
                szResponse = g_strdup("accept\n");
            else
                szResponse = g_strdup("reject\n");

        } else if (processedBoard.anDice[0]) {
            /* move */
            char szMove[64];
            if (FindBestMove(anMove, processedBoard.anDice[0], processedBoard.anDice[1],
                             processedBoard.anBoard, &ci, &GetEvalChequer()->ec, *GetEvalMoveFilter()) < 0)
                return NULL;

            FormatMovePlain(szMove, anBoardOrig, anMove);
            szResponse = g_strconcat(szMove, "\n", NULL);
        } else {
            /* double decision */
            if (GeneralCubeDecision(aarOutput, aarStdDev,
                                    aarsStatistics, (ConstTanBoard) processedBoard.anBoard, &ci, GetEvalCube(),
                                    NULL, NULL) < 0)
                return NULL;

            switch (FindCubeDecision(arDouble, aarOutput, &ci)) {
            case DOUBLE_TAKE:
            case DOUBLE_PASS:
            case DOUBLE_BEAVER:
            case REDOUBLE_TAKE:
            case REDOUBLE_PASS:
                szResponse = g_strdup("double\n");
                break;

            default:
                szResponse = g_strdup("roll\n");
            }
        }

    }

    return szResponse;

}
Esempio n. 2
0
static char *
ExtFIBSBoard( extcmd *pec ) {

  char szName[ MAX_NAME_LEN ], szOpp[ MAX_NAME_LEN ];
  int nMatchTo, anScore[ 2 ],
    anDice[ 2 ], nCube, fCubeOwner, fDoubled, fCrawford, fJacoby,
    anMove[ 8 ], fTurn;
  TanBoard anBoard, anBoardOrig;
  float arDouble[ NUM_CUBEFUL_OUTPUTS ],
    aarOutput[ 2 ][ NUM_ROLLOUT_OUTPUTS ],
    aarStdDev[ 2 ][ NUM_ROLLOUT_OUTPUTS ];
  rolloutstat aarsStatistics[ 2 ][ 2 ];
  cubeinfo ci;
  int nScore, nScoreOpponent;
  char *szResponse;
 
  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 ("Crawford Setting: %d\n", fCrawford); */
	/* printf ("Jacoby Setting: %d\n", fJacoby); */
    
    fTurn = 1;
    SetCubeInfo ( &ci, nCube, fCubeOwner, fTurn, nMatchTo, anScore,
                  fCrawford, fJacoby, nBeavers, bgvDefault ); 
    
#if 0 
    {
      char *asz[ 7 ] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
      char szBoard[ 10000 ];
      outputl( DrawBoard( szBoard, anBoard, 1, asz,
                          "no matchid", 15 ) );

      printf( "score %d-%d to %d ", anScore[ 0 ], anScore[ 1 ],
              nMatchTo );
      printf( "dice %d %d ", anDice[ 0 ], anDice[ 1 ] );
      printf( "cubeowner %d cube %d turn %d crawford %d doubled %d\n",
              fCubeOwner, nCube, fTurn, fCrawford, fDoubled );
    }
#endif

    memcpy( anBoardOrig, anBoard, sizeof( anBoard ) );

    if ( fDoubled  ) {

      /* take decision */
      if( GeneralCubeDecision( aarOutput, aarStdDev,
                               aarsStatistics, (ConstTanBoard)anBoard, &ci,
                               GetEvalCube(), NULL, NULL ) < 0 )
        return NULL;
	  
      switch( FindCubeDecision( arDouble,  aarOutput, &ci )) {
      case DOUBLE_PASS:
      case TOOGOOD_PASS:
      case REDOUBLE_PASS:
      case TOOGOODRE_PASS:
        szResponse = g_strdup( "drop\n" );
        break;

      case NODOUBLE_BEAVER:
      case DOUBLE_BEAVER:
      case NO_REDOUBLE_BEAVER:
        szResponse = g_strdup( "beaver\n" );
        break;
		    
      default:
        szResponse = g_strdup( "take\n" );
      }

#if 0
      /* this code is broken as the sign of fDoubled 
         indicates who doubled */
    } else if ( fDoubled < 0 ) {
              
      /* if opp wants to resign (extension to FIBS board) */

      float arOutput[ NUM_ROLLOUT_OUTPUTS ];
      float rEqBefore, rEqAfter;
      const float epsilon = 1.0e-6;

      getResignation( arOutput, anBoard, &ci, &esEvalCube );

      getResignEquities ( arOutput, &ci, -fDoubled,
                          &rEqBefore, &rEqAfter );

      /* if opponent gives up equity by resigning */
      if( ( rEqAfter - epsilon ) < rEqBefore )
        szResponse = g_strdup( "accept\n" );
      else
        szResponse = g_strdup( "reject\n" );

#endif /* broken */
    } else if( anDice[ 0 ] ) {
      /* move */
      char szMove[ 64 ];
      if( FindBestMove( anMove, anDice[ 0 ], anDice[ 1 ],
                        anBoard, &ci, &GetEvalChequer()->ec,
                        *GetEvalMoveFilter() ) < 0 )
        return NULL;

      FormatMovePlain( szMove, anBoardOrig, anMove );
      szResponse = g_strconcat( szMove, "\n", NULL );
    } else {
      /* double decision */
      if( GeneralCubeDecision( aarOutput, aarStdDev,
                               aarsStatistics, (ConstTanBoard)anBoard, &ci,
                               GetEvalCube(), NULL, NULL ) < 0 )
        return NULL;
		
      switch( FindCubeDecision( arDouble,  aarOutput, &ci )) {
      case DOUBLE_TAKE:
      case DOUBLE_PASS:
      case DOUBLE_BEAVER:
      case REDOUBLE_TAKE:
      case REDOUBLE_PASS:
        szResponse = g_strdup( "double\n" );
        break;
		    
      default:
        szResponse = g_strdup( "roll\n" );
      }
    }
	    
  }

  return szResponse;

}