// can we move the given Pirate to the given Location according to the number of moves? // if so --> move it! private static int move(PirateContainer p, Location t, int moves, IPirateGame game, bool dontHitEnemies = false) { if (moves == 0 || !p.AVALIBLE || p.P.Location.Equals(t)) { return(0); } // calculate the best route /*foreach (Location l in game.GetSailOptions(p.P, t, moves)) * { * if (!QueuedMotion.isOccupied(l, game, dontHitEnemies) && p.move(l, game)) * return game.Distance(p.P, l); * }*/ var X = from l in game.GetSailOptions(p.P, t, moves) where (!QueuedMotion.isOccupied(l, game, dontHitEnemies) && p.move1(l, game)) select l; if (X.Count() > 0) { PirateContainer.free.Remove(p); Location loc = X.ElementAt(rand.Next(X.Count())); game.SetSail(p.P, loc); new QueuedMotion(p.P, loc); return(game.Distance(p.P, loc)); } else if (X.Count() == 0) { if (PirateContainer.GetRemainingMoves() > 2) { Location loc = p.P.Location; p.move(loc, game); } } game.Debug("Failed to find a move for " + p.P.Id + " to " + t); return(0); }