コード例 #1
0
static void
StartFromDatabase( hyperequity ahe[], const int nC, 
                   const char *szFilename ) {

  FILE *pf;
  int nPos = Combination( 25 + nC, nC );
  unsigned char ac[ 28 ];
  unsigned int us;
  int i, j, k;
  float r;

  if ( ! ( pf = g_fopen ( szFilename, "r+b" ) ) ) {
    perror ( szFilename );
    exit(2);
  }

  /* skip header */

  fseek( pf, 40, SEEK_SET );

  for ( i = 0; i < nPos; ++i )
    for ( j = 0; j < nPos; ++j ) {

      if (fread( ac, 1, 28, pf ) != 28)
      {
	      perror(szFilename);
	      exit(EXIT_FAILURE);
      }

      for ( k = 0; k < NUM_OUTPUTS; ++k ) {
        us = ac[ 3 * k ] | ( ac[ 3 * k + 1 ] ) << 8 | ( ac[ 3 * k + 2 ] ) << 16;
        r = us / 16777215.0;
        g_assert( r >= 0 && r <= 1 );
        ahe[ i * nPos + j ].arOutput[ k ] = r;
      }

      for ( k = 0; k < 4; ++k ) {
        us = ac[ 15 + 3 * k ] | ( ac[ 15 + 3 * k + 1 ] ) << 8 |  
           ( ac[ 15 + 3 * k + 2 ] ) << 16;
        r = ( us / 16777215.0f - 0.5f ) * 6.0f;
        g_assert( r >= -3 && r <= 3 );
        ahe[ i * nPos + j ].arEquity[ k + 1 ] = r;
      }

      ahe[ i * nPos + j ].arEquity[ 0 ] = 
        Utility ( ahe[ i * nPos  + j ].arOutput, &ci );

    }
  
                         

  fclose( pf );

}
コード例 #2
0
ファイル: format.c プロジェクト: alcacoop/libgnubg-android
extern int
DumpPosition(const TanBoard anBoard, char *szOutput,
             const evalcontext * pec, cubeinfo * pci, int fOutputMWC,
             int UNUSED(fOutputWinPC), int fOutputInvert, const char *szMatchID)
{

    float aarOutput[2][NUM_ROLLOUT_OUTPUTS];
    positionclass pc = ClassifyPosition(anBoard, pci->bgv);
    int i, nPlies;
    int j;
    evalcontext ec;
    static const char *aszEvaluator[] = {
        N_("Over"),
        N_("Hypergammon-1"),
        N_("Hypergammon-2"),
        N_("Hypergammon-3"),
        N_("Bearoff2"),
        N_("Bearoff-TS"),
        N_("Bearoff1"),
        N_("Bearoff-OS"),
        N_("Race"),
        N_("Crashed"),
        N_("Contact")
    };

    strcpy(szOutput, "");

    sprintf(strchr(szOutput, 0), "%s:\t", _("Position ID"));
    strcat(szOutput, PositionID(anBoard));
    strcat(szOutput, "\n");
    if (szMatchID) {
        sprintf(strchr(szOutput, 0), "%s:\t", _("Match ID"));
        strcat(szOutput, szMatchID);
        strcat(szOutput, "\n");
    }
    strcat(szOutput, "\n");

    sprintf(strchr(szOutput, 0), "%s: \t", _("Evaluator"));
    strcat(szOutput, gettext(aszEvaluator[pc]));
    strcat(szOutput, "\n\n");
    acdf[pc] (anBoard, strchr(szOutput, 0), pci->bgv);
    szOutput = strchr(szOutput, 0);

    sprintf(strchr(szOutput, 0),
            "\n"
            "        %-7s %-7s %-7s %-7s %-7s %-9s %-9s\n",
            _("Win"), _("W(g)"), _("W(bg)"), _("L(g)"), _("L(bg)"),
            (!pci->nMatchTo || (pci->nMatchTo && !fOutputMWC)) ? _("Equity") : _("MWC"), _("Cubeful"));

    nPlies = pec->nPlies > 9 ? 9 : pec->nPlies;

    memcpy(&ec, pec, sizeof(evalcontext));

    for (i = 0; i <= nPlies; i++) {
        szOutput = strchr(szOutput, 0);


        ec.nPlies = i;

        if (GeneralCubeDecisionE(aarOutput, anBoard, pci, &ec, 0) < 0)
            return -1;

        if (!i)
            strcpy(szOutput, _("static"));
        else
            sprintf(szOutput, "%2d %s", i, _("ply"));

        szOutput = strchr(szOutput, 0);

        if (fOutputInvert) {
            InvertEvaluationR(aarOutput[0], pci);
            InvertEvaluationR(aarOutput[1], pci);
            pci->fMove = !pci->fMove;
        }

        /* Print %'s and equities */

        strcat(szOutput, ": ");

        for (j = 0; j < 5; ++j) {
            sprintf(strchr(szOutput, 0), "%-7s ", OutputPercent(aarOutput[0][j]));
        }

        if (pci->nMatchTo)
            sprintf(strchr(szOutput, 0), "%-9s ", OutputEquity(Utility(aarOutput[0], pci), pci, TRUE));
        else
            sprintf(strchr(szOutput, 0), "%-9s ", OutputMoneyEquity(aarOutput[0], TRUE));

        sprintf(strchr(szOutput, 0), "%-9s ", OutputMWC(aarOutput[0][6], pci, TRUE));

        strcat(szOutput, "\n");

        if (fOutputInvert) {
            pci->fMove = !pci->fMove;
        }
    }

    /* if cube is available, output cube action */
    if (GetDPEq(NULL, NULL, pci)) {

        evalsetup es;

        es.et = EVAL_EVAL;
        es.ec = *pec;

        strcat(szOutput, "\n\n");
        strcat(szOutput, OutputCubeAnalysis(aarOutput, NULL, &es, pci));

    }

    return 0;
}
コード例 #3
0
static void
HyperEquity ( const int nUs, const int nThem,
              hyperequity *phe, const int nC, const hyperequity aheOld[],
              float arNorm[] ) {

  TanBoard anBoard;
  TanBoard anBoardTemp;
  movelist ml;
  int i, j;
  unsigned int k;
  int nUsNew, nThemNew;
  hyperequity heBest;
  hyperequity heOld;
  hyperequity heNew;
  int nPos = Combination ( 25 + nC, nC );
  const hyperequity *phex;
  float r;
  hyperclass hc;

  /* save old hyper equity */

  memcpy ( &heOld, phe, sizeof ( hyperequity ) );

  /* generate board for position */
  
  PositionFromBearoff ( anBoard[ 0 ], nThem, 25, nC );
  PositionFromBearoff ( anBoard[ 1 ], nUs, 25, nC );

  switch ( ( hc = ClassifyHyper ( anBoard ) ) ) {
  case HYPER_OVER:

    HyperOver ( (ConstTanBoard)anBoard, phe->arOutput, nC );

    for ( k = 0; k < 5; ++k )
      phe->arEquity[ k ] = Utility ( phe->arOutput, &ci );

    /* special calc for Jacoby rule */

    phe->arEquity[ EQUITY_CENTER_JACOBY ] = 
      Utility ( phe->arOutput, &ciJacoby );

    return;
    break;

  case HYPER_ILLEGAL:

    return;
    break;

  case HYPER_BEAROFF:
  case HYPER_CONTACT:

    for ( k = 0; k < NUM_OUTPUTS; ++k )
      heNew.arOutput[ k ] = 0.0f;
    for ( k = 0; k < 5; ++k )
      heNew.arEquity[ k ] = 0.0f;

    for ( i = 1; i <= 6; ++i ) 
      for ( j = 1; j <= i; ++j ) {
      
        GenerateMoves ( &ml, (ConstTanBoard)anBoard, i, j, FALSE );

        if ( ml.cMoves ) {

          /* at least one legal move: find the equity of the best move */

          for ( k = 0; k < 5; ++k )
            heBest.arEquity[ k ] = -10000.0f;
        
          for ( k = 0; k < ml.cMoves; ++k ) {
          
            PositionFromKey ( anBoardTemp, &ml.amMoves[ k ].key );
          
            nUsNew = PositionBearoff( anBoardTemp[ 1 ], 25, nC );
            nThemNew = PositionBearoff( anBoardTemp[ 0 ], 25, nC );
          
            g_assert ( nUsNew >= 0 );
            g_assert ( nUsNew < nUs );
            g_assert ( nThemNew >= 0 );

            /* cubeless */

            phex = &aheOld[ nPos * nThemNew + nUsNew ];

            r = - phex->arEquity[ EQUITY_CUBELESS ];
 
            if ( r >= heBest.arEquity[ EQUITY_CUBELESS ] ) {
              memcpy ( heBest.arOutput, phex->arOutput, 
                       NUM_OUTPUTS * sizeof ( float ) );
              InvertEvaluation ( heBest.arOutput );
              heBest.arEquity[ EQUITY_CUBELESS ] = r;
            }

            /* I own cube:
               from opponent's view he doesn't own cube */

            r = - phex->arEquity[ EQUITY_OPPONENT ];
          
            if ( r >= heBest.arEquity[ EQUITY_OWNED ] )
              heBest.arEquity[ EQUITY_OWNED ] = r;

            /* Centered cube, i.e., centered for opponent too */

            r = - CubeEquity ( phex->arEquity[ EQUITY_CENTER ],
                               phex->arEquity[ EQUITY_OPPONENT ],
                               +1.0 );
            
            if ( r >= heBest.arEquity[ EQUITY_CENTER ] )
              heBest.arEquity[ EQUITY_CENTER ] = r;

            /* centered cube with Jacoby rule */

            r = - CubeEquity ( phex->arEquity[ EQUITY_CENTER_JACOBY ],
                               phex->arEquity[ EQUITY_OPPONENT ],
                               +1.0 );
            
            if ( r >= heBest.arEquity[ EQUITY_CENTER_JACOBY ] )
              heBest.arEquity[ EQUITY_CENTER_JACOBY ] = r;

            /* Opponent owns cube: from opponent's view he owns cube */

            r = - CubeEquity ( phex->arEquity[ EQUITY_OWNED ],
                               phex->arEquity[ EQUITY_OPPONENT ],
                               +1.0 );

            if ( r >= heBest.arEquity[ EQUITY_OPPONENT ] )
              heBest.arEquity[ EQUITY_OPPONENT ] = r;

          }

        }
        else {

          /* no legal moves: equity is minus the equity of the reverse
             position, which has the opponent on roll */
          
          memcpy( &heBest, &aheOld[ nPos * nThem  + nUs ], 
                  sizeof ( hyperequity ) );

          InvertEvaluation ( heBest.arOutput );
          
          for ( k = 0; k < 5; ++k )
            heBest.arEquity[ k ] = - heBest.arEquity[ k ];

        }

        /* sum up equities */

        for ( k = 0; k < NUM_OUTPUTS; ++k )
          heNew.arOutput[ k ] += 
            ( i == j ) ? heBest.arOutput[ k ] : 2.0 * heBest.arOutput[ k ];
        for ( k = 0; k < 5; ++k )
          heNew.arEquity[ k ] += 
            ( i == j ) ? heBest.arEquity[ k ] : 2.0 * heBest.arEquity[ k ];

      }
  
    /* normalise */

    for ( k = 0; k < NUM_OUTPUTS; ++k )
      phe->arOutput[ k ] = heNew.arOutput[ k ] / 36.0;
    for ( k = 0; k < 5; ++k )
      phe->arEquity[ k ] = heNew.arEquity[ k ] / 36.0;

    break;

  }

  /* calculate contribution to norm */

  for ( k = 0; k < NUM_OUTPUTS; ++k ) {
    r = fabsf ( phe->arOutput[ k ] - heOld.arOutput[ k ] );
    if ( r > arNorm[ k ] ) {
       arNorm[ k ] = r;
       aiNorm[ k ] = nUs * nPos + nThem;
    }
  }
  for ( k = 0; k < 5; ++k ) {
    r = fabsf( phe->arEquity[ k ] - heOld.arEquity[ k ] );
    if ( r > arNorm[ 5 + k ] ) {
       arNorm[ 5 + k ] = r;
       aiNorm[ 5 + k ] = nUs * nPos + nThem;
    }
  }


}
コード例 #4
0
static void
StartGuessHyper ( hyperequity ahe[], const int nC, bearoffcontext *pbc ) {

  int i, j;
  unsigned int k;
  int nPos = Combination( 25 + nC, nC );
  TanBoard anBoard;

  int ai[ 4 ] = { 0,0,0,0 };

  for ( i = 0; i < nPos; ++i ) {
    for ( j = 0; j < nPos; ++j ) {

      PositionFromBearoff ( anBoard[ 0 ], j, 25, nC );
      PositionFromBearoff ( anBoard[ 1 ], i, 25, nC );

      switch ( ClassifyHyper ( anBoard ) ) {
      case HYPER_OVER:
        HyperOver ( (ConstTanBoard)anBoard, ahe[ i * nPos + j ].arOutput, nC );

        for ( k = 0; k < 5; ++k )
          ahe[ i * nPos + j ].arEquity[ k ] = 
            Utility ( ahe[ i * nPos + j ].arOutput, &ci );

        /* special calc for Jacoby rule */
        
        ahe[ i * nPos + j ].arEquity[ EQUITY_CENTER_JACOBY ] = 
          Utility ( ahe[ i * nPos + j ].arOutput, &ciJacoby );

        ++ai[0];

        break;

      case HYPER_CONTACT:
        ++ai[ 1 ];
        --ai[2];
      case HYPER_BEAROFF:

        memset ( &ahe[ i * nPos + j  ], 0, sizeof ( hyperequity ) );

        ahe[ i * nPos + j ].arOutput[ 0 ] = 1.0;
        ahe[ i * nPos + j ].arOutput[ 1 ] = 1.0;
        ahe[ i * nPos + j ].arOutput[ 2 ] = 0.0;
        ahe[ i * nPos + j ].arOutput[ 3 ] = 0.0;
        ahe[ i * nPos + j ].arOutput[ 4 ] = 0.0;
        ahe[ i * nPos + j ].arEquity[ 0 ] = 
          Utility ( ahe[ i * nPos + j ].arOutput, &ci );

        ++ai[2];

        break;

      case HYPER_ILLEGAL:

        memset ( &ahe[ i * nPos + j  ], 0, sizeof ( hyperequity ) );
        ++ai[3];

        break;

      default:

        g_assert ( FALSE );
        break;

      }

    }
  }

  printf("%-25s: %10d\n", _("Number of game-over positions"), ai[ 0 ]);
  printf("%-25s: %10d\n", _("Number of non-contact positions"), ai[ 2 ]);
  printf("%-25s: %10d\n", _("Number of contact positions"), ai[ 1 ]);
  printf("%-25s: %10d\n", _("Total number of legal positions"), ai[ 0 ] + ai[ 2 ] + ai[ 1 ]);
  printf("%-25s: %10d\n", _("Number of illegal positions"), ai[ 3 ]);
  printf("%-25s: %10d\n", _("Total number of positions in file"), nPos * nPos );
            
}
コード例 #5
0
ファイル: UD_INCR.CPP プロジェクト: cdaffara/symbiandump-os2
/** Initiates a database recovery operation.

This is the incremental version of RDbDatabase::Recover().
Recover() will try to rebuild database indexes if they are broken.
If the database data is corrupted, it cannot be recovered.

@param aDatabase The database to recover.
@param aStep On return, contains the initial step count for the incremental 
operation. This value should be passed in to subsequent calls to NextL().

@return KErrNone if successful, or one of the DBMS database error codes. If 
recovery fails with either KErrNoMemory or KErrDiskFull, then recovery may 
be attempted again when more memory or disk space is available.

@see RDbDatabase::Recover() 

@capability Note For a secure shared database, the caller must satisfy the schema 
            access policy for the database.
*/
EXPORT_C TInt RDbIncremental::Recover(RDbDatabase& aDatabase,TInt& aStep)
	{
	return Utility(iState,aDatabase.iDatabase,aStep,CDbDatabase::ERecover);
	}
コード例 #6
0
ファイル: UD_INCR.CPP プロジェクト: cdaffara/symbiandump-os2
/** Initiates the operation of compacting a database. This is the incremental form 
of RDbDatabase::Compact().

@param aDatabase The database to compact.
@param aStep On return, contains the initial step count for the incremental 
operation. This value should be passed in to subsequent calls to Next() to 
continue the operation.
@return KErrNone if successful, otherwise another of the system-wide error 
codes.
@see RDbDatabase::Compact() 

@capability Note For a secure shared database, the caller must satisfy the schema 
            access policy for the database.
*/
EXPORT_C TInt RDbIncremental::Compact(RDbDatabase& aDatabase,TInt& aStep)
	{
	return Utility(iState,aDatabase.iDatabase,aStep,CDbDatabase::ECompact);
	}
コード例 #7
0
ファイル: UD_INCR.CPP プロジェクト: cdaffara/symbiandump-os2
/** Initiates the operation of calculating and updating database statistics.

This is the incremental form of RDbDatabase::UpdateStats()

@param aDatabase The database whose statistics are to be updated.
@param aStep On return, contains the initial step count for the incremental 
operation. This value should be passed in to subsequent calls to Next() to 
continue the operation.
@return KErrNone if successful, otherwise another of the system-wide error 
codes.
@see RDbDatabase::UpdateStats() 

@capability Note For a secure shared database, the caller must satisfy the schema 
            access policy for the database.
*/
EXPORT_C TInt RDbIncremental::UpdateStats(RDbDatabase& aDatabase,TInt& aStep)
	{
	return Utility(iState,aDatabase.iDatabase,aStep,CDbDatabase::EStats);
	}