本文整理汇总了C#中IGameState.GetDirections方法的典型用法代码示例。如果您正苦于以下问题:C# IGameState.GetDirections方法的具体用法?C# IGameState.GetDirections怎么用?C# IGameState.GetDirections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGameState
的用法示例。
在下文中一共展示了IGameState.GetDirections方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoMoveLocation
//Handles collision checking and movement tracking for a start and end point
private bool DoMoveLocation(Location ant, Location destination, IGameState state)
{
//Collect the best directions to go to from state.getdirections
//map.FindRoute(ant, destination);
ICollection<Direction> directions = state.GetDirections(ant, destination);
foreach (Direction direction in directions)
{
//Check whether those directions are appropriate
if (DoMoveDirection(ant, direction, state))
return true;
}
return false;
}
示例2: GetDirectionFromPath
private Direction GetDirectionFromPath(List<Location> path, IGameState state)
{
if (path == null || path.Count <= 1)
return Direction.None;
else
return new List<Direction>(state.GetDirections(path[0], path[1]))[0];
}
示例3: DoTurn
// DoTurn is run once per turn
public override void DoTurn(IGameState state)
{
if(radius == default(int)) // Init
radius = (int)Math.Sqrt(state.ViewRadius2) / 2;
foreach (Agent agent in new List<Agent>(agents)) // Die
{
if (!state.MyAnts.Contains(new Ant(agent.location.Row, agent.location.Col, state.MyAnts[0].Team)))
{
agent.decisionLog.AddReward(DIE);
agents.Remove(agent);
}
}
foreach (Ant a in state.MyAnts) //Spawn new ants
{
bool spawn = true;
foreach (Agent agent in agents)
{
if (agent.location.Equals(a))
{
spawn = false;
break;
}
}
if (spawn)
{
Agent ag = new Agent(a);
decisionLogs.Add(ag.decisionLog);
agents.Add(ag);
foreach (Agent age in agents) // Take food
{
if(age.path.Count > 0)
if (age.currentAction == Action.TakeFood && state.GetDistance(age.location, age.path[age.path.Count - 1]) <= 1)
age.decisionLog.AddReward(EAT);
}
}
}
foreach(Agent agent in agents){
if (agent.path.Count == 0)
{
State s = CalculateState(agent.location, state);
double[] desirabilities = rewardLog.GetDesirabilities(s);
int i = -1;
HashSet<Action> aas = s.GetActions();
double x = random.NextDouble();
if (x <= exploration) // Explore
{
do
{
i = random.Next(Enum.GetValues(typeof(Action)).Length);
}
while (!aas.Contains((Action)i));
}
else // Exploit
{
x = random.NextDouble();
for (i = 0; i < Enum.GetValues(typeof(Action)).Length; i++)
{
if (x <= desirabilities[i])
break;
else
x -= desirabilities[i];
}
}
if (i == Enum.GetValues(typeof(Action)).Length)
{
do
{
i = random.Next(Enum.GetValues(typeof(Action)).Length);
}
while (!aas.Contains((Action)i));
}
PerformAction(agent, s, (Action)i, state);
}
if (agent.path.Count == 0)
continue;
if (!state.GetIsPassable(agent.path[0]))
agent.path = Pathfinding.FindPath(agent.location, agent.path[agent.path.Count - 1], state);
Location next = agent.path[0];
agent.path.RemoveAt(0);
if (state.EnemyHills.Count > 0)
if (state.EnemyHills.Contains(new AntHill(next.Row, next.Col, state.EnemyHills[0].Team)))
agent.decisionLog.AddReward(WIN);
IssueOrder(agent.location, ((List<Direction>)state.GetDirections(agent.location, next))[0]);
agent.location = next;
}
}
示例4: PerformMove
// Move ant
public void PerformMove(CurrentTask task, Location to, IGameState state)
{
if (!to.Equals(task.from) && !task.warp)
IssueOrder(task.from, ((List<Direction>)state.GetDirections(task.from, task.to))[0]);
task.warp = false;
task.resolved = true;
nextTasks.Add(LocationToKey(to), task);
currentTasks.Remove(LocationToKey(task.from));
}