本文整理汇总了C#中IGameState.GetDestination方法的典型用法代码示例。如果您正苦于以下问题:C# IGameState.GetDestination方法的具体用法?C# IGameState.GetDestination怎么用?C# IGameState.GetDestination使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGameState
的用法示例。
在下文中一共展示了IGameState.GetDestination方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTurn
// DoTurn is run once per turn
public override void DoTurn(IGameState state)
{
// loop through all my ants and try to give them orders
foreach (Ant ant in state.MyAnts)
{
// try all the directions
foreach (Direction direction in Ants.Aim.Keys)
{
// GetDestination will wrap around the map properly
// and give us a new location
Location newLoc = state.GetDestination(ant, direction);
// GetIsPassable returns true if the location is land
if (state.GetIsPassable(newLoc) && !(orders.Contains(newLoc)))
{
IssueOrder(ant, direction);
orders.Add(newLoc);
break;
}
}
// check if we have time left to calculate more orders
if (state.TimeRemaining < 10) break;
}
orders.Clear();
}
示例2: IssueOrder
protected void IssueOrder(IGameState state, Ant ant, Direction direction)
{
if (direction != Direction.None) {
//only walk if there's no other ant standing in that location
if (state.GetIsUnoccupied(state.GetDestination(ant, direction))) {
ant.WaitTime = 0;
//tell the gamestate that the ant will be moved next turn
state.MoveAnt(ant, direction);
System.Console.Out.WriteLine("o {0} {1} {2}", ant.Row, ant.Col, direction.ToChar());
}
}
}
示例3: DoTurn
// DoTurn is run once per turn
public override void DoTurn(IGameState state)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine(string.Format("{0}: Starting turn {1}", DateTime.Now.ToLongTimeString(), turnCounter), "TURN");
#endif
// loop through all my ants and try to give them orders
foreach (Ant ant in state.MyAnts)
{
// try all the directions
foreach (Direction direction in Ants.Aim.Keys)
{
// GetDestination will wrap around the map properly
// and give us a new location
Location newLoc = state.GetDestination(ant, direction);
// GetIsPassable returns true if the location is land
if (state.GetIsPassable(newLoc))
{
IssueOrder(ant, direction);
// stop now, don't give 1 and multiple orders
break;
}
}
// check if we have time left to calculate more orders
if (state.TimeRemaining < 10) break;
}
#if DEBUG
System.Diagnostics.Debug.WriteLine(string.Format("{0}: Ending turn {1}", DateTime.Now.ToLongTimeString(), turnCounter++), "TURN");
if (true) { } // silly line just to set a breakpoint
#endif
}
示例4: GetNeighbours
static List<Location> GetNeighbours(Location loc, IGameState state)
{
List<Location> neighbours = new List<Location>();
for (int i = 0; i < 4; i++)
neighbours.Add(state.GetDestination(loc, (Direction)i));
return neighbours;
}
示例5: DoMoveDirection
//Handles collision checking and movement tracking
private bool DoMoveDirection(Location ant, Direction direction, IGameState state)
{
// GetDestination will wrap around the map properly
// and give us a new location
Location newLoc = state.GetDestination(ant, direction);
// GetIsPassable returns true if the location is land
if (state.GetIsPassable(newLoc) && !(orders.Contains(newLoc) && state.GetIsUnoccupied(newLoc)))
{
IssueOrder(ant, direction);
orders.Add(newLoc);
}
return false;
}
示例6: DoTurn
public override void DoTurn(IGameState state)
{
var usedMoves = new HashSet<Location>();
foreach (Ant ant in state.MyAnts)
{
int min = int.MaxValue;
Location minLoc = ant;
foreach (var point in state.FoodTiles)
{
int ras = state.GetDistance(point, ant);
if (min > ras)
{
min = ras;
minLoc = point;
}
}
int x1 = ant.Col;
int y1 = ant.Row;
int x2 = minLoc.Col;
int y2 = minLoc.Row;
int dx = Math.Abs(x1-x2);
int dy = Math.Abs(y1-y2);
var direction = Direction.East;
if (dx > 0)
{
if (dx < state.Width - dx)
direction = GetDirectionX(x2 - x1);
else
direction = GetDirectionX(x1 - x2);
}
else if(dy > 0)
{
if (dy < state.Height - dy)
direction = GetDirectionY(y2 - y1);
else
direction = GetDirectionY(y1 - y2);
}
Location newLoc = state.GetDestination(ant, direction);
if (state.GetIsPassable(newLoc) && !usedMoves.Contains(newLoc))
{
usedMoves.Add(newLoc);
IssueOrder(ant, direction);
}
/*for (int i = 0; i < 4; i++ )
{
var direction = _directions[
_random.Next(4)];
Location newLoc = state.GetDestination(ant, direction);
if (state.GetIsPassable(newLoc) && !usedMoves.Contains(newLoc))
{
usedMoves.Add(newLoc);
IssueOrder(ant, direction);
break;
}
}*/
if (state.TimeRemaining < 10) break;
}
}
示例7: DoTurn
// DoTurn is run once per turn
public override void DoTurn(IGameState gameState)
{
ProcessRewards(gameState);
// erase old state data since we start a new turn
this.lastStates = new List<StateAction>[gameState.Width * gameState.Height];
// loop through all my ants and give them orders
foreach (Ant ant in gameState.MyAnts) {
State s = GetState(gameState, ant);
Action a = this.learn.GetAction(s, this.rho);
Location newLoc;
if (a != Action.None) {
Direction direction = a.ToDirection();
this.IssueOrder(ant, direction);
newLoc = gameState.GetDestination(ant, direction);
} else {
newLoc = ant;
}
//If the move will be blocked, the new location of the ant
//is just were the ant is right now.
if (gameState[newLoc] == Tile.Water) {
newLoc = ant;
}
ushort newPosition = newLoc.ToUShort(gameState.Width);
if (lastStates[newPosition] == null)
lastStates[newPosition] = new List<StateAction>();
StateAction sa = new StateAction();
sa.State = s;
sa.Action = a;
this.lastStates[newPosition].Add(sa);
// check if we have time left to calculate more orders
if (gameState.TimeRemaining < 10) break;
}
this.SaveLastState(gameState);
this.learn.SaveFile(this.learnFile);
}
示例8: NumOfFoodNextTo
/// <summary>
/// Gets the number of food there was next to a certain location in the previous turn.
/// </summary>
/// <param name="gameState">The GameState.</param>
/// <param name="location">The Location to check.</param>
/// <returns>The number of food next to <paramref name="location"/> in the previous turn.</returns>
private int NumOfFoodNextTo(IGameState gameState, Location location)
{
int res = 0;
//in every direction, check whether there was food in the previous turn
foreach (Direction direction in Enum.GetValues(typeof(Direction))) {
Location checkLocation = gameState.GetDestination(location, direction);
if (gameState.OldMap[checkLocation.Row, checkLocation.Col] == Tile.Food) {
res++;
}
}
return res;
}
示例9: GetState
/// <summary>
/// Gets a State object representing the current state.
/// </summary>
/// <param name="state">The GameState.</param>
/// <param name="location">The Location from which to generate a state.</param>
/// <returns>A State object that repressents the current state given the location.</returns>
public State GetState(IGameState gameState, Location location)
{
QTile[] tiles = new QTile[statePositions.Length];
for (int i = 0; i < statePositions.Length; ++i) {
Location loc = gameState.GetDestination(location, statePositions[i]);
tiles[i] = gameState[loc].ToQTile();
}
ushort position = location.ToUShort(gameState.Width);
return new State(tiles, position);
}
示例10: SearchFood
// Find nearest food tile in range
public Location SearchFood(Location loc, IGameState state)
{
Location f = loc;
Direction g = Direction.North;
for (int i = 1; i <= foodRadius * 2; i++)
{
for (int k = 0; k < 2; k++)
{
for (int j = 0; j < i; j++)
{
f = state.GetDestination(f, g);
if (state[f.Row, f.Col] == Tile.Food && !yummies.Contains(f) && Pathfinding.ReachableWithin(loc, f, state, foodRadius))
return f;
}
g = DirectionExtensions.Rotate(g, 1);
if (i == foodRadius * 2)
{
for (int j = 0; j < i; j++)
{
f = state.GetDestination(f, g);
if (state[f.Row, f.Col] == Tile.Food && !yummies.Contains(f) && Pathfinding.ReachableWithin(loc, f, state, foodRadius))
return f;
}
}
}
}
return null;
}