Beispiel #1
0
UINT CConverter::Read(void FAR* lpBuf, UINT nCount)
{
	ASSERT(m_bForeignToRtf);
	if (m_bDone)
		return 0;
	// if converter is done
	int cch = nCount;
	BYTE* pBuf = (BYTE*)lpBuf;
	while (cch != 0)
	{
		if (m_nBytesAvail == 0)
		{
			if (m_pBuf != NULL)
				GlobalUnlock(m_hBuff);
			m_pBuf = NULL;
			SetEvent(m_hEventConv);
			WaitForConverter();
			VERIFY(ResetEvent(m_hEventFile));
			if (m_bConvErr)
				AfxThrowFileException(CFileException::generic);
			if (m_bDone)
				return nCount - cch;
			m_pBuf = (BYTE*)GlobalLock(m_hBuff);
			ASSERT(m_pBuf != NULL);
		}
		int nBytes = min(cch, m_nBytesAvail);
		memcpy(pBuf, m_pBuf, nBytes);
		pBuf += nBytes;
		m_pBuf += nBytes;
		m_nBytesAvail -= nBytes;
		cch -= nBytes;
		OutputPercent(m_nPercent);
	}
	return nCount - cch;
}
Beispiel #2
0
UINT CTrackFile::Read(void FAR* lpBuf, UINT nCount)
{
	UINT n = CFile::Read(lpBuf, nCount);
	if (m_dwLength != 0)
		OutputPercent((int)((GetPosition()*100)/m_dwLength));
	return n;
}
Beispiel #3
0
extern char *
OutputPercents(const float ar[], const int f)
{

    static char sz[80];

    strcpy(sz, "");

    strcat(sz, OutputPercent(ar[OUTPUT_WIN]));
    strcat(sz, " ");
    strcat(sz, OutputPercent(ar[OUTPUT_WINGAMMON]));
    strcat(sz, " ");
    strcat(sz, OutputPercent(ar[OUTPUT_WINBACKGAMMON]));
    strcat(sz, " - ");
    if (f)
        strcat(sz, OutputPercent(1.0f - ar[OUTPUT_WIN]));
    else
        strcat(sz, OutputPercent(ar[OUTPUT_WIN]));
    strcat(sz, " ");
    strcat(sz, OutputPercent(ar[OUTPUT_LOSEGAMMON]));
    strcat(sz, " ");
    strcat(sz, OutputPercent(ar[OUTPUT_LOSEBACKGAMMON]));

    return sz;

}
Beispiel #4
0
CTrackFile::~CTrackFile()
{
	OutputPercent(100);
	if (m_pFrameWnd != NULL)
		m_pFrameWnd->SetMessageText(AFX_IDS_IDLEMESSAGE);
}
static void
GTKRolloutProgress(float aarOutput[][NUM_ROLLOUT_OUTPUTS],
		   float aarStdDev[][NUM_ROLLOUT_OUTPUTS],
		   const rolloutcontext * prc,
		   const cubeinfo aci[],
		   unsigned int initial_game_count,
		   const int iGame,
		   const int iAlternative,
		   const int nRank,
		   const float rJsd,
		   const int fStopped,
		   const int fShowRanks, int fCubeRollout, rolloutprogress * prp)
{

	static unsigned int n_games_todo = 0;
	static unsigned int n_games_done = 0;
	static int min_games_done = 0;
	char sz[32];
	int i;
	gchar *gsz;
	double frac;
	GtkTreeIter iter;

	if (!prp || !prp->pwRolloutResult)
		return;

	gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(prp->pwRolloutResultList), &iter, NULL, iAlternative);
	gtk_list_store_set(prp->pwRolloutResultList, &iter, TRIALS_C, iGame + 1, -1);
	for (i = 0; i < NUM_ROLLOUT_OUTPUTS; i++) {

		/* result */

		if (i < OUTPUT_EQUITY)
			strcpy(sz, OutputPercent(aarOutput[iAlternative][i]));
		else if (i == OUTPUT_EQUITY)
			strcpy(sz, OutputEquityScale(aarOutput[iAlternative][i],
						     &aci[iAlternative], &aci[0], TRUE));
		else
			strcpy(sz,
			       prc->fCubeful ? OutputMWC(aarOutput[iAlternative][i],
							 &aci[0], TRUE) : "n/a");

		gtk_list_store_set(prp->pwRolloutResultList, &iter, i + 3, sz, -1);

	}
	if (prc->fCubeful)
			strcpy(sz, OutputMWC(aarStdDev[iAlternative][OUTPUT_CUBEFUL_EQUITY], &aci[0], FALSE));
	else
			strcpy(sz, OutputEquityScale(aarStdDev[iAlternative][OUTPUT_EQUITY], &aci[iAlternative], &aci[0], FALSE));
	gtk_list_store_set(prp->pwRolloutResultList, &iter, i + 3, sz, -1);
	if (fShowRanks && iGame > 1) {
		gtk_list_store_set(prp->pwRolloutResultList, &iter, RANK_C, nRank, -1);
		if (nRank != 1 || fCubeRollout)
			sprintf(sz, "%5.3f", rJsd);
		else
			strcpy(sz, " ");
		gtk_list_store_set(prp->pwRolloutResultList, &iter, i + 4, sz, -1);
	}

	/* Update progress bar with highest number trials for all the alternatives */
	if (iAlternative == 0) {
		n_games_todo = 0;
		n_games_done = 0;
		min_games_done = prc->nTrials;
	}
	n_games_done += iGame + 1;
	if (!fStopped) {
		n_games_todo += prc->nTrials - (iGame + 1);
		if (iGame < min_games_done)
			min_games_done = iGame + 1;
	}
	if (iAlternative == (prp->n - 1)) {
		frac = ((float)min_games_done)/prc->nTrials;
		gsz = g_strdup_printf("%d/%d (%d%%)", min_games_done, prc->nTrials, (int)(100.0f * frac));
		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(prp->pwRolloutProgress), frac);
		gtk_progress_bar_set_text(GTK_PROGRESS_BAR(prp->pwRolloutProgress), gsz);
		g_free(gsz);
		prp->nGamesDone = min_games_done;
	}

	/* calculate estimate time left */

	if ((iAlternative == (prp->n - 1)) && n_games_done > initial_game_count) {
		time_t t = time_left(n_games_todo, n_games_done, initial_game_count, prp->tStart);
		gtk_label_set_text(GTK_LABEL(prp->pwElapsed), formatDelta(time(NULL) - prp->tStart));
		gtk_label_set_text(GTK_LABEL(prp->pwLeft), formatDelta(t));

	}

	/* calculate estimated SE */

	if (!iAlternative && iGame > 10) {

		float r;

		if (prc->fCubeful) {
			r = estimatedSE(aarStdDev[0][OUTPUT_CUBEFUL_EQUITY], iGame, prc->nTrials);
			gtk_label_set_text(GTK_LABEL(prp->pwSE), OutputMWC(r, &aci[0], FALSE));
		} else {
			r = estimatedSE(aarStdDev[0][OUTPUT_EQUITY], iGame, prc->nTrials);
			gtk_label_set_text(GTK_LABEL(prp->pwSE),
					   OutputEquityScale(r, &aci[0], &aci[0], FALSE));
		}

	}

	return;
}
Beispiel #6
0
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;
}
Beispiel #7
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);
  }

}