Example #1
0
Direction MaxOfFewSearch::move(GameState& state, int ms
#ifdef DEBUG
							   , std::list<Direction>& moveSequence
#endif
  							  )
{
	Direction bestMove = DIR_END;
	double bestValue = -std::numeric_limits<double>::infinity();
	for(int i = 0; i < k_ || bestMove == DIR_END; ++i)
	{
		Direction direction = rand() % DIR_END;
		if(!state.canMove(direction))
			continue;
		
		state.move(direction);
		double value = heuristic_(state);
		state.undo(direction);
		
		if(value > bestValue || bestMove == DIR_END)
		{
			bestMove = direction;
			bestValue = value;
		}
	}
	
#ifdef DEBUG
	moveSequence.clear();
	moveSequence.push_front(bestMove);
#endif
	
	return bestMove;
}