示例#1
0
LightWidget::LightWidget(QWidget* parent)
{
	SetIcon(":/Images/Components/Light.png");
	SetName("Light");

	cboLightType = new QComboBox();
	//indexÓëLightType¶ÔÓ¦
	cboLightType->addItem("Directional");
	cboLightType->addItem("Spot");
	cboLightType->addItem("Point");
	frameLayout_->addWidget(cboLightType);
	connect(cboLightType,SIGNAL(currentIndexChanged(int)),this,SLOT(onLightTypeChanged(int)));

	QHBoxLayout* colorSelect = getNewRow();
	QLabel* lblColor = new QLabel("Color");
	colorSelect->addWidget(lblColor);
	selColor = new ColorPickerWidget(NULL,QColor(0,0,0));
	colorSelect->addWidget(selColor);
	connect(selColor,SIGNAL(colorChanged(Urho3D::Color)),this,SLOT(onLightColorChanged(Urho3D::Color)));

	QHBoxLayout* rowSpec = getNewRow();
	lblSpeInden = new LabelTextBox();
	lblSpeInden->SetName("Specular Itensity");
	lblSpeInden->SetValueRange(0,5);
	rowSpec->addWidget(lblSpeInden);
	connect(lblSpeInden,SIGNAL(valueChanged(float)),this,SLOT(onLightSpeckIntenChanged(float)));
}
/*!\brief Either increments or decrements values in a heuristic table
 * to facilitate the heuristic sweep function.
 *
 * \param row
 * 	The row around which to modify the heuristic values.
 *
 * \param column
 * 	The column around which to modify heuristic values.
 *
 * \param add
 * 	Whether to deduct or add heuristic stats.
 */
void GameBoard::updateHeuristicsTable(unsigned row, unsigned column, bool add)
{
	for (int i = 0; i < total_directions_; ++i)
	{
		if (myCheckRelativePositionOpen(row, column, Direction(i)))
		{
			if (add)
			{
				board_(getNewRow(row, Direction(i)), getNewColumn(column, Direction(i)))
					.setHeuristicValue(board_(getNewRow(row, Direction(i)),
					getNewColumn(column, Direction(i))).getHeuristicValue()+1);
			}
			else
			{
				board_(getNewRow(row, Direction(i)), getNewColumn(column, Direction(i)))
					.setHeuristicValue(board_(getNewRow(row, Direction(i)),
					getNewColumn(column, Direction(i))).getHeuristicValue()-1);
			}
		}
	}
}
/*!\brief Performs a heuristic sweep of the tour locations.
 *
 * Significantly better performance than the static sweep.
 *
 * \param row
 * 	The row to start sweeping from.
 *
 * \param column
 * 	The column to start sweeping from.
 *
 * \return true if a solution was found, false otherwise.
 */
bool GameBoard::heuristicSweepNeighbors(const unsigned row, const unsigned column)
{
	// First, update the heuristics table to reflect our current position.
	updateHeuristicsTable(row, column, false);
	// So, we sweep the same way as the static, but use a heuristic sort
	// to cut down on the number of checks we have to do in the end.
	std::vector<std::pair<unsigned, unsigned> > new_coords;
	for (int i = 0; i < total_directions_; ++i)
	{
		try
		{
			if (myCheckRelativePositionOpen(row, column, Direction(i)))
			{
				// It's open, let's shove it into a box for further...
				// adjustments.
				new_coords.push_back(std::pair<unsigned, unsigned>(getNewRow(row, Direction(i)), getNewColumn(column, Direction(i))));
			}
		}
		catch (BoardException &)
		{
			// Do nothing! These should be safe errors.
		}
	}

	// We has a valid list of moves now.
	std::stable_sort(new_coords.begin(), new_coords.end(), HeuristicSorter(board_));

	// And now, chug through everything.
	std::vector<std::pair<unsigned, unsigned> >::iterator iter;

	for (iter = new_coords.begin(); iter != new_coords.end(); ++iter)
	{
		if (myPlaceKnight((*iter).first, (*iter).second))
			return(true);
	}

	// Reverse our heuristics changes.
	updateHeuristicsTable(row, column, true);

	return(false);
}
/*!\brief Sweeps for tour locations using a static, naive algorithm.
 *
 * Is very slow for anything above approximately a 7x7 grid.
 *
 * \param row
 * 	The current row to start sweeping from.
 *
 * \param column
 * 	The current column to start sweeping from.
 *
 * \return true if a solution was found, false otherwise.
 */
bool GameBoard::staticSweepNeighbors(const unsigned row, const unsigned column)
{
	// Check for open positions...
	for (int i = 0; i < total_directions_; ++i)
	{
		try
		{
			// Too complicated to do a directional container.
			// So...
			// Cast i into the Direction enum.
			// Should do everything in order!
			if(myCheckRelativePositionOpen(row, column, Direction(i)))
			{
#ifdef MARCUS_DEBUG
				std::cerr << "Position is good, let's go..." << std::endl;
#endif
				// It's open, let's check that too!
				if(myPlaceKnight(getNewRow(row, Direction(i)), getNewColumn(column, Direction(i))))
				{
#ifdef MARCUS_DEBUG
					std::cerr << "Zomg, we're done!" << std::endl;
#endif
					return(true);
				}
			}
		}
		catch(BoardException &e)
		{
			// Do nothing. Or maybe debug stuff.
			// It was probably just an index going out of bounds,
			// which we shall ignore for now -- this should be safe,
			// and we will move on to the next iteration of this
			// loop with no issues.
#ifdef MARCUS_DEBUG
			std::cerr << e.what() << std::endl;
#endif
		}
	}

	return(false);
}