Example #1
0
QString AveragesTab::statisticTable(const Quackle::Simulator &simulator)
{
	QString ret;
	for (int levelIndex = 0; levelIndex < simulator.numLevels(); ++levelIndex)
	{
		for (int playerIndex = 0; playerIndex < simulator.numPlayersAtLevel(levelIndex); ++playerIndex)
		{
			if (levelIndex == 0 && playerIndex == 0)
				continue;

			const Quackle::SimmedMoveList::const_iterator end(simulator.simmedMoves().end());
			
			// Little bit of fudgery so that the turn after our next turn is #2,
			// and turn after oppo's next turn is also #2.
			const int turnNumber = levelIndex + (playerIndex == 0? 0 : 1);
			QString name = tr("%1 turn #%2").arg(playerIndex == 0? "Our" : "Oppo").arg(turnNumber);
			if (playerIndex == 1 && levelIndex == 0)
			{
				name = tr("Oppo next turn");
			}
			else if (playerIndex == 0 && levelIndex == 1)
			{
				name = tr("Our next turn");
			}
			ret += QString("<h2>%1</h2>").arg(name);
			
			ret += "<table border=0 cellspacing=4>";
			ret += tr("<tr><th>Candidate</th><th>Score</th><th>Std. Dev.</th><th>Bingo %</th></tr>");
			for (Quackle::SimmedMoveList::const_iterator it = simulator.simmedMoves().begin(); it != end; ++it)
			{
				if (!(*it).includeInSimulation())
					continue;

				ret += "<tr>";
				ret += tr("<td>%1</td>").arg(QuackleIO::Util::moveToDetailedString((*it).move));

				Quackle::AveragedValue value = (*it).getPositionStatistics(levelIndex, playerIndex).getStatistic(Quackle::PositionStatistics::StatisticScore);
				Quackle::AveragedValue bingos = (*it).getPositionStatistics(levelIndex, playerIndex).getStatistic(Quackle::PositionStatistics::StatisticBingos);

				ret += QString("<td>%1</td><td>%2</td>").arg(value.averagedValue()).arg(value.standardDeviation());
				ret += QString("<td>%1</td>").arg(bingos.averagedValue() * 100.0);
				ret += "</tr>";
			}
			ret += "</table>";
		}
	}

	return ret;
}
Example #2
0
void testSimulation(Quackle::Game &game)
{
	const int kibitzLength = 3;
	game.currentPosition().kibitz(kibitzLength);

	//UVcout << game.currentPosition() << endl;
	UVcout << game.currentPosition().moves() << endl;

	Quackle::Simulator simulator;
	simulator.setLogfile("quackletest.simulation", false);
	simulator.setPosition(game.currentPosition());

	simulator.simulate(20, 5);
	UVcout << simulator.simmedMoves() << endl;
	UVcout << "after " << simulator.iterations() << " iterations pruning to those within five points" << endl;

	simulator.pruneTo(5, kibitzLength);

	int iterationStep = 1;
	int iterationsToRun = 2;

	const bool longSim = true;
	if (longSim)
	{
		iterationStep = 10;
		iterationsToRun = 50;
	}

	const int plies = 2;

	simulator.setIgnoreOppos(false);

	for (int iterations = 0; iterations < iterationsToRun; iterations += iterationStep)
	{
		simulator.simulate(plies, iterationStep);
		UVcout << "sim results after " << iterations + iterationStep << " iterations: " << endl;

		const Quackle::SimmedMoveList &moves = simulator.simmedMoves();

		for (Quackle::SimmedMoveList::const_iterator it = moves.begin(); it != moves.end(); ++it)
		{
			UVcout << *it << endl;
		}

		UVcout << endl;
	}
}
Example #3
0
void AveragesTab::setSimulator(const Quackle::Simulator &simulator)
{
	QString html;

	html += statisticTable(simulator);

	html += "<hr />";

	const Quackle::SimmedMoveList::const_iterator end(simulator.simmedMoves().end());
	for (Quackle::SimmedMoveList::const_iterator it = simulator.simmedMoves().begin(); it != end; ++it)
	{
		if (!(*it).includeInSimulation())
			continue;

		QString levels;
		for (Quackle::LevelList::const_iterator levelIt = (*it).levels.begin(); levelIt != (*it).levels.end(); ++levelIt)
		{
			QString plays;
			for (Quackle::PositionStatisticsList::const_iterator valueIt = (*levelIt).statistics.begin(); valueIt != (*levelIt).statistics.end(); ++valueIt)
			{
				//plays += QString("(%1) ").arg((*valueIt).score.averagedValue());
				//plays += tr("(bingos %1) ").arg((*valueIt).bingos.averagedValue());
			}

			if (!plays.isEmpty())
				levels += QString("<li>%1</li>").arg(plays);
		}

		html += QString("<h3>%1</h3><ol>%2</ol>").arg(QuackleIO::Util::moveToDetailedString((*it).move)).arg(levels);

		html += "<ul>";
		if ((*it).residual.hasValues())
			html += tr("<li>Rack leftover value: %1</li>").arg((*it).residual.averagedValue());
		if ((*it).gameSpread.hasValues())
			html += tr("<li>Spread: %1 (sd %2)</li>").arg((*it).gameSpread.averagedValue()).arg((*it).gameSpread.standardDeviation());
		html += tr("<li>Valuation: %1</li>").arg((*it).calculateEquity());
		html += tr("<li>Bogowin %: %1%</li>").arg((*it).calculateWinPercentage());
		html += "</ul>";
	}

	// TODO don't scroll to top when resetting
	m_textEdit->setHtml(html);
}
Example #4
0
void AveragesTab::setSimulator(const Quackle::Simulator &simulator)
{
	QString html;

	html += statisticTable(simulator);

	html += "<hr />";

	for (const auto& it : simulator.simmedMoves())
	{
		if (!it.includeInSimulation())
			continue;

		QString levels;
		for (const auto& levelIt : it.levels)
		{
			QString plays;
			for (const auto& valueIt : levelIt.statistics)
			{
				//plays += QString("(%1) ").arg((*valueIt).score.averagedValue());
				//plays += tr("(bingos %1) ").arg((*valueIt).bingos.averagedValue());
			}

			if (!plays.isEmpty())
				levels += QString("<li>%1</li>").arg(plays);
		}

		html += QString("<h3>%1</h3><ol>%2</ol>").arg(QuackleIO::Util::moveToDetailedString(it.move)).arg(levels);

		html += "<ul>";
		if (it.residual.hasValues())
			html += tr("<li>Rack leftover value: %1</li>").arg(it.residual.averagedValue());
		if (it.gameSpread.hasValues())
			html += tr("<li>Spread: %1 (sd %2)</li>").arg(it.gameSpread.averagedValue()).arg(it.gameSpread.standardDeviation());
		html += tr("<li>Valuation: %1</li>").arg(it.calculateEquity());
		html += tr("<li>Bogowin %: %1%</li>").arg(it.calculateWinPercentage());
		html += "</ul>";
	}

	// TODO don't scroll to top when resetting
	m_textEdit->setHtml(html);
}