public override void Activate(Pirate p) { base.Activate(p); //p.hasAmmo = true; p.PickupAmmo(); p.ExitStationTrigger(); p.EnterStationTrigger(this); }
public override CommandProcessor Given() { activeUnitId = Guid.NewGuid(); targetUnitId = Guid.NewGuid(); attackUnit = new Pirate { Id = activeUnitId, X = 10, Y = 4}; targetUnit = new Pirate { Id = targetUnitId, X = 10, Y = 5}; FirstPlayer.Units.Add(attackUnit); SecondPlayer.Units.Add(targetUnit); Calculator.CalculateDamage(attackUnit, targetUnit).Returns(expectedDamage); return new CommandProcessor(Calculator, State); }
public override void Activate(Pirate p) { base.Activate(p); sailClosed.SetRendererVisibility(false); sailIdle.SetRendererVisibility(false); sailOpen.SetRendererVisibility(true); sailOpen.PlayAnim(); //sailOpen.AnimEnded() => //{ //} myBoat.isSailOpen = true; }
public bool startTurn() { iteration++; int count = 0; count = Client.getPirateCount(connection); pirates = new Pirate[count]; for(int i = 0; i < count; i++) { pirates[i] = new Pirate(Client.getPirate(connection, i)); } count = Client.getPlayerCount(connection); players = new Player[count]; for(int i = 0; i < count; i++) { players[i] = new Player(Client.getPlayer(connection, i)); } count = Client.getPortCount(connection); ports = new Port[count]; for(int i = 0; i < count; i++) { ports[i] = new Port(Client.getPort(connection, i)); } count = Client.getShipCount(connection); ships = new Ship[count]; for(int i = 0; i < count; i++) { ships[i] = new Ship(Client.getShip(connection, i)); } count = Client.getTileCount(connection); tiles = new Tile[count]; for(int i = 0; i < count; i++) { tiles[i] = new Tile(Client.getTile(connection, i)); } count = Client.getTreasureCount(connection); treasures = new Treasure[count]; for(int i = 0; i < count; i++) { treasures[i] = new Treasure(Client.getTreasure(connection, i)); } if(!initialized) { initialized = true; init(); } return run(); }
static string Example1() { Pirate p = new Pirate(); StringLiteral s1 = new StringLiteral("H\ae\bl\fl\vo\0 \'P\"arrot!\n"); Call c1 = new Call("print", s1); StmtList sl = new StmtList(); CallStmt cs1 = new CallStmt(c1); sl.Add(cs1); Sub main = new Sub("main", sl); p.Add(main); StringWriter sw = new StringWriter(); PirateWriter pv = new PirateWriter(sw); DynamicVisitor.accept(p, pv); return sw.ToString(); }
public override void Activate(Pirate p) { base.Activate(p); if(hasAmmo) { myBoat.fireCannon(cannon); anim.PlayAnim(); hasAmmo = false; } else if(p.hasAmmo) { p.DropAmmo(); hasAmmo = true; } p.ExitStationTrigger(); p.EnterStationTrigger(this); }
public override bool PirateWent(Pirate pirate) { if (steps[stepsNumber].Contains(pirate)) { return(base.PirateWent(pirate)); } for (var i = stepsNumber; i > 0; i--) { if (steps[i - 1].Contains(pirate)) { steps[i - 1].Remove(pirate); KillFoesFor(steps[i], pirate); steps[i].Add(pirate); } } return(false); }
private Island GetClosestIsland(IPirateGame state, Pirate myPirate, List <Island> islands) { // Move from the island // Move to closest attacked island // int closetDIstance = int.MaxValue; Island closestIsland = null; islands.ForEach(island => { int distnace = state.Distance(myPirate, island); if (distnace < closetDIstance) { closestIsland = island; closetDIstance = distnace; } }); return(closestIsland); }
public static Pirate createPirate() { GameObject go = new GameObject(); Pirate pir = go.AddComponent <Pirate> (); /* * Rigidbody2D rb = go.AddComponent<Rigidbody2D> (); * rb.isKinematic = true; * rb.freezeRotation = true; * * BoxCollider2D bc = go.AddComponent <BoxCollider2D> (); * bc.size = new Vector2 (2.5, 0.7); * bc.offset = new Vector2 (0, 0.29); * * Animator anim = go.AddComponent <Animator> (); */ return(pir); }
public bool TryAttack(Pirate pirate, PirateGame game) { // Go over all enemies foreach (Aircraft enemy in game.GetEnemyLivingAircrafts()) { // Check if the enemy is in attack range if (pirate.InAttackRange(enemy)) { // Fire! game.Attack(pirate, enemy); // Print a message game.Debug("pirate " + pirate + " attacks " + enemy); // Did attack return(true); } } // Didnt attack return(false); }
private bool TryPush(Pirate pirate, Pirate enemy) { if (pirate.CanPush(enemy)) { if (enemy.HasCapsule()) { // Push the capsule to the initial location pirate.Push(enemy, GetClosestToBorder(enemy.Location)); Print("Pirate " + pirate + " pushes " + enemy + " (capsule holder) to " + GetClosestToBorder(enemy.Location)); } else { // Push the enemy to the border pirate.Push(enemy, GetClosestToBorder(enemy.Location)); Print("Pirate " + pirate + " pushes " + enemy + " towards " + GetClosestToBorder(enemy.Location)); } return(true); } return(false); }
public static void UpdatePiratePositions(Packet packet) { int count = packet.ReadInt(); for (int i = 1; i <= count; i++) { int id = packet.ReadInt(); Vector3 pos = packet.ReadVector3(); Quaternion rot = packet.ReadQuaternion(); if (!Pirates.ContainsKey(id)) { continue; } Pirate pirate = Pirates[id]; pirate.TargetPosition = pos; pirate.transform.localRotation = rot; } }
public override CommandProcessor Given() { var firstPlayer = new Player {Name = "shiftkey"}; var secondPlayer = new Player { Name = "aeoth" }; activeUnitId = Guid.NewGuid(); targetUnitId = Guid.NewGuid(); attackUnit = new Pirate { Id = activeUnitId, X = 10, Y = 4, }; targetUnit = new Pirate { Id = targetUnitId, X = 10, Y = 5, CurrentHitPoints = expectedDamage }; FirstPlayer.Units.Add(attackUnit); FirstPlayer.Player = firstPlayer; SecondPlayer.Units.Add(targetUnit); SecondPlayer.Player = secondPlayer; Calculator.CalculateDamage(attackUnit, targetUnit).Returns(expectedDamage); return new CommandProcessor(Calculator, State); }
private Location GetOptimalAsteroidInterception(Pirate enemy, Pirate friendly, Asteroid asteroid, Location destination) { if (asteroid.InRange(enemy, asteroid.Size)) { return(null); } var steps = enemy.Steps(destination.Towards(enemy, enemy.MaxSpeed)); var asteroidLocation = asteroid.Location; for (int i = 1; i < steps; i++)//Fix: changed I to 1 { // Get the location. var enemyLocation = enemy.Location.Towards(destination, enemy.MaxSpeed * i); if (asteroidLocation.Towards(enemyLocation, friendly.PushDistance + asteroid.Speed * (i - 1)).InRange(enemyLocation, asteroid.Size)) { return(enemyLocation); } } return(null); }
/// <summary> /// Updates the state, using the given game; Will be called every turn, from turn 2 onwards /// </summary> public override void Update(Game game) { this.treasureList.Clear(); this.threatenedTreasures.Clear(); this.safeTreasures.Clear(); this.treasureList = game.GetTreasures(TreasureState.FreeToTake); foreach (Treasure t in this.treasureList) { bool threatened = false; foreach (Pirate enemy in game.GetEnemyPirates(PirateState.Free)) { if (enemy.CanAttack && Game.InAttackRange(enemy, t, enemy.AttackRadius)) { threatened = true; break; } if (Game.ManhattanDistance(enemy, t) <= Utils.Min(enemy.MaxSpeed, game.ActionsPerTurn)) { threatened = true; break; } } Pirate p = game.GetPirateOn(t); if (p != null && p.State == PirateState.Drunk) { threatened = true; } if (threatened) { this.threatenedTreasures.Add(t); } else { this.safeTreasures.Add(t); } } }
// returns a prioritised queue of targets for the given Pirate private List <Pirate> findTargetsFor(Pirate p, IPirateGame game) { // TODO: if kamikaze and in enemy InitialLocation, don't shoot the Pirate with the id for the location List <Pirate> res = new List <Pirate>(); foreach (Pirate e in game.EnemySoberPirates()) { if (game.InRange(p, e) && e.DefenseExpirationTurns == 0) { if (!panic && e.ReloadTurns == 0) // if we aren't in panic, and we have no target, shoot the one that has ammo; TODO: alter ReloadTurns value { res.Add(e); } else if (e.HasTreasure) // always prioritise Pirates with Treasures { res.Insert(0, e); } } } return(res); }
public static void RecieveInputs(int fromClient, Packet packet) { int clientId = packet.ReadInt(); if (fromClient != clientId) { Debug.Log($"Player (ID: {fromClient}) has assumed the wrong client ID ({clientId})!"); return; } Pirate pirate = PirateManager.instance.Pirates[fromClient]; int inputNumber = packet.ReadInt(); for (int i = 0; i < inputNumber; i++) { Inputs input = (Inputs)packet.ReadInt(); bool down = packet.ReadBool(); pirate.networkInput.HandleInput(input, down); } }
private void onPirateTurnedIn(System.Object args) { Pirate turnedPirate = ((PirateTurnedInArgs)args).TurnedInPirate; if (currentState == MinionState.DROPOFF && turnedPirate == pickupList[0]) { pickupList.Remove(turnedPirate); if (pickupList.Count == 0) { currentState = MinionState.FOLLOW; } else { currentState = MinionState.PICKUP; } } else if (pickupList.Contains(turnedPirate)) { pickupList.Remove(turnedPirate); } }
public void PopulateEnemyTargets(List <Pirate> enemys, List <BaseAttacker> participants) { List <BodyGuard> guardians = participants.OfType <BodyGuard>().ToList(); GameSettings.Game.Debug("BodyGuards are ==> " + guardians.Count); Carrier c = participants.OfType <Carrier>().ToList()[0]; GameSettings.Game.Debug("Carrier is ==> " + c); enemys = enemys.OrderBy(Pirate => Pirate.Distance(c.Pirate)).ToList(); foreach (BodyGuard BG in guardians) { if (BG.TargetEnemy == null) { if (enemys.Count > 0) { BG.TargetEnemy = enemys[0]; enemys.RemoveAt(0); } } } }
public void PathShouldContainCroco() { // Arrange var field = new GreenField(); pirate = field.CurrentPirate; var startCell = field.Cells(3, 3); var crocoCell = new CrocoCell(4, 3); field.InsertCell(crocoCell); field.SetPirateOnCell(pirate, startCell); // Act field.MovePirateTo(pirate, crocoCell); // Assert pirate.Path.ShouldContain() .Elements(startCell.Position, crocoCell.Position, crocoCell.Position, startCell.Position); }
bool KillIfPossible(Pirate p) { if (p.HasTreasure || p.ReloadTurns > 0) { return(false); } foreach (var enemy in game.EnemySoberPirates()) { if (game.InRange(p, enemy) && enemy.HasTreasure) { game.Attack(p, enemy); return(true); } else if (game.InRange(p, enemy) && game.Distance(game.AllMyPirates()[2].InitialLocation, enemy.Location) < 6) { game.Attack(p, enemy); return(true); } } return(false); }
public void TreasureHunt(int moves, Pirate p0) { if (p0.HasTreasure) { game.SetSail(p0, tempDes(p0, p0.InitialLocation, 1)); turns--; } else { if (p0.TurnsToSober > 0) { return; } Treasure target = closestTreasure(FreeTreasures().ToList(), p0); if (target != null) { game.SetSail(p0, tempDes(p0, target.Location, moves)); turns -= moves; } } }
public void DoTurn(IPirateGame game) { int reamaining = 6; Pirate[] ps = new Pirate[4]; for (int i = 0; i < 4; i++) { ps[i] = game.GetMyPirate(i); } List <Pirate> ltp = game.MyPiratesWithTreasures(); reamaining -= ltp.Count; foreach (Pirate p in ltp) { game.SetSail(p, game.GetSailOptions(p, p.InitialLocation, 1)[0]); } for (int i = 0; i < 4; i++) { if (!ps[i].HasTreasure) { Treasure cull = null; int minD = int.MaxValue; foreach (Treasure t in game.Treasures()) { if (game.Distance(ps[i], t) < minD) { minD = game.Distance(ps[i], t); cull = t; } } game.SetSail(ps[i], game.GetSailOptions(ps[i], cull, reamaining)[0]); reamaining = 0; break; } } }
public bool TryPushMyCapsule(Pirate myPirateWithCapsule, Pirate pusherPirate) { if (!pusherPirate.CanPush(myPirateWithCapsule) || myPiratesWithCapsulePushes[myPirateWithCapsule] == myPirateWithCapsule.NumPushesForCapsuleLoss - 1) { return(false); } var destination = GetMyBestMothershipThroughWormholes(myPirateWithCapsule); var locationOfPush = myPirateWithCapsule.Location.Towards(destination, pusherPirate.PushDistance); if (!IsWorthPushing(myPirateWithCapsule, pusherPirate, locationOfPush, destination.Location)) { return(false); } availablePirates.Remove(pusherPirate); myPiratesWithCapsulePushes[myPirateWithCapsule]++; pusherPirate.Push( myPirateWithCapsule, game.GetMyMotherships().OrderBy(mothership => mothership.Distance(myPirateWithCapsule)) .FirstOrDefault()); return(true); }
/// <summary> /// Add possible responses to "chooser", based on the situation in "game" and in "statesManager" /// </summary> public override void AddResponseOptions(Game game, StatesManager statesManager, ActionsChooser chooser) { if (this.myPirate.State != PirateState.Drunk) { return; } Pirate enemy = game.GetPirateSpawnOn(this.myPirate); if (enemy != null && enemy.Owner == Owner.Enemy) { ActionsPack ap = ActionsPack.NewCommandPack(game, new DoNothingCommand(), base.Id); double value = BLOCKADE_VALUE; ap.AddEnemyPirate(enemy); ap.AddMyPirate(this.myPirate); ap.BurnInformation("Made in DrunkBlockadeEvent for pirate {0} on pirate {1}, Value: {2:F3}", this.myPirate, enemy.Id, value); chooser.AddActionsPack(ap, value); } }
private bool PushCarrier(Pirate pirate, PirateGame game) { // Go over all enemies. foreach (Pirate enemy in game.GetEnemyLivingPirates()) { // Check if the pirate can push the enemy. if (pirate.CanPush(enemy) && enemy.HasCapsule()) { // Push enemy! pirate.Push(enemy, enemy.InitialLocation); // Print a message. System.Console.WriteLine("pirate " + pirate + " pushes " + enemy + " towards " + enemy.InitialLocation); // Did push. return(true); } } // Didn't push. return(false); }
/// <summary> /// /// </summary> /// <returns></returns> /*public Location GetEnemyPirateMovementVector(Pirate enemyPirate) * { * Location locationVector = null; * * if (GameSettings.Game.Turn > 1) * { * Location enemyPreviousLocation = GameSettings.LastGameEnemyPirates[enemyPirate.Id]; * locationVector = enemyPirate.GetLocation().Subtract(enemyPreviousLocation); * } * * return locationVector; * }*/ /// <summary> /// Defines where the defender need to push /// </summary> /// <param name="enemyPirate"></param> /// <param name="range"></param> /// <returns></returns> public Location DefendersWhereToPush(Pirate enemyPirate, int range) { Location outOfBorder = GetCloseEnoughToBorder(enemyPirate, range); if (outOfBorder != null) { return(outOfBorder); } else { Location pushTowards = calculator.PredictLocationByMovement(enemyPirate, 10); return(pushTowards); //Location enemyPreviousLocation = GameSettings.LastGameEnemyPirates[enemyPirate.Id]; //Location oppositeSide = enemyPirate.GetLocation().Subtract(GameSettings.Game.GetEnemyMotherships()[0].GetLocation()); //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy //pushTowards = enemyPirate.GetLocation().Towards(enemyPirate.GetLocation().Add(pushTowards), enemyPirate.PushDistance).Multiply(1.5); //pushTowards.Row += enemyPreviousLocation.Row; //pushTowards.Col += enemyPreviousLocation.Col; //GameSettings.Game.Debug("pushTowards ==> " + pushTowards); } }
private int HandleIfPirateCanReach(Pirate pirate) { if (LocationType.MyPirate == Type) { var bestMothership = bot.GetMyBestMothershipThroughWormholes(pirate); if (!CanCatchUpAndPush(pirate, (Pirate)TargetLocationObject, bestMothership.Location)) { return(MAX_PRIORITY); } } else if (LocationType.Asteroid == Type) { Asteroid asteroid = (Asteroid)TargetLocationObject; var bestCapsule = bot.GetBestCapsuleForAsteroid(asteroid, game.GetEnemyCapsules() .Where(capsule => capsule.Holder != null)); if (pirate.Steps(asteroid) + asteroid.Steps(bestCapsule) > bestCapsule.Holder.Steps(bot.GetEnemyBestMothershipThroughWormholes(bestCapsule.Holder))) { return(MAX_PRIORITY); } } return(this.Priority); }
public static void IneractRequest(int fromClient, Packet packet) { int clientId = packet.ReadInt(); if (fromClient != clientId) { Debug.Log($"Player (ID: {fromClient}) has assumed the wrong client ID ({clientId})!"); return; } int id = packet.ReadInt(); BoatEntityType boatEntityType = (BoatEntityType)packet.ReadInt(); InteractionType interactionType = (InteractionType)packet.ReadInt(); Pirate pirate = PirateManager.instance.Pirates[clientId]; Interactable interactable = pirate.boat.GetInteractableEntityByTypeAndId(boatEntityType, id); if (interactable != null) { pirate.BeginInteractWith(interactable, interactionType); } }
/// <summary> Tries to either avoid or push the asteroid </summary> /// <returns> A tuple with bool and the action string </returns> protected static Tuple <bool, string> InteractWithAsteroid(Pirate pirate, Location to) { var asteroids = Utils.AsteroidsByDistance(pirate.Location).Where(ass => ass.Direction.Add(ass.Location).Distance(pirate) <= game.PushDistance + pirate.MaxSpeed + ass.Size).ToList(); foreach (Asteroid asteroid in asteroids) { if (pirate.CanPush(asteroid) && !Main.asteroidsPushed.Contains(asteroid)) { var pushTuple = Utils.OptimalAsteroidPushLocation(pirate.PushDistance, asteroid); if (pirate.InRange(asteroid.Location.Add(asteroid.Direction), asteroid.Size + pirate.MaxSpeed)) { pirate.Push(asteroid, pushTuple.Item1); return(new Tuple <bool, string>(true, "Pushed asteroid in an emergency")); } if (pushTuple.Item2 > 0) { pirate.Push(asteroid, pushTuple.Item1); Main.asteroidsPushed.Add(asteroid); Main.didTurn.Add(pirate.Id); return(new Tuple <bool, string>(true, "Pushed asteroid to best location")); } } bool shouldAvoid = pirate.Distance(asteroid) < game.PushDistance + asteroid.Size; shouldAvoid = shouldAvoid && game.GetEnemyLivingPirates().Any(p => p.InRange(asteroid, p.PushDistance + p.MaxSpeed)); if (Utils.AsteroidIsMoving(asteroid) && (shouldAvoid || pirate.Location == to)) { pirate.Sail(SafestCloestLocation(pirate.Location, to, pirate)); Main.didTurn.Add(pirate.Id); return(new Tuple <bool, string>(true, "Avoiding asteroid")); } } return(new Tuple <bool, string>(false, "Did not run")); }
public void run() { string[] line = System.Console.ReadLine().Split(); N = long.Parse(line[0]); P = long.Parse(line[1]); T = 0; Q1 = new PriorityQueue <Pirate>(); Q2 = new PriorityQueue <Pirate>(); for (int i = 0; i < P; i++) { line = System.Console.ReadLine().Split(); Q1.Enqueue(new Pirate(long.Parse(line[0]), long.Parse(line[1]), long.Parse(line[2]), long.Parse(line[3]), i - P, 0)); } while (!Q1.IsEmpty || !Q2.IsEmpty) { Pirate P1 = Q1.Peek(), P2 = Q2.Peek(); if (P2 == null || (P1 != null && P2.arrive > T && P1.arrive < P2.arrive)) { Q1.Dequeue(); if (N - Q2.Count > 0) { T = System.Math.Max(T, P1.arrive) + P1.t[0]; P1.arrive = T + P1.t[1]; P1.side = 1; Q2.Enqueue(P1); } } else { T = System.Math.Max(T, P2.arrive) + P2.t[2]; Q2.Dequeue(); P2.arrive = T + P2.t[3]; P2.side = 0; Q1.Enqueue(P2); N--; if (N == 0) { System.Console.WriteLine(T); return; } } } }
public void Assign(Pirate pirate, List <Mission> list) { return; if (!pirate.HasPaintball) { return; } var city = Globals.Game.GetNeutralCities().First(); int count = Globals.Game.GetEnemyLivingDrones().Count(x => x.InRange(city, 15)); if (count < 3) { return; } Resources a = new Resources(); a.AddPirate(pirate.Id); list.Add(new Mission(pirate.Id, (int)((200 - pirate.Distance(city)) / 200.0 * 800 * System.Math.Sqrt(count)), a, new MoveCommand(pirate, city.Location))); }
/// <summary> /// Makes the pirate try to push an enemy pirate. Returns true if it did. /// </summary> /// <param name="pirate">The pushing pirate.</param> /// <param name="game">The current game state.</param> /// <returns> true if the pirate pushed. </returns> public static bool TryPush(Pirate pirate) { // Go over all enemies. foreach (Pirate enemy in GameSettings.game.GetEnemyLivingPirates()) { // Check if the pirate can push the enemy. if (pirate.CanPush(enemy)) { //Changed //Push enemy! Location oppositeSide = enemy.GetLocation().Subtract(GameSettings.game.GetEnemyMothership().GetLocation()); //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy oppositeSide = enemy.GetLocation().Towards(enemy.GetLocation().Add(oppositeSide), 600); pirate.Push(enemy, oppositeSide); //Print a message. GameSettings.game.Debug("pirate " + pirate + " pushes " + enemy + " towards " + enemy.InitialLocation); //Did push. return(true); } } // Didn't push. return(false); }
private Pirate GetClosestPirate(IPirateGame state, Island island, List <Pirate> pirates) { // Move from the island // Move to closest attacked island // int closetDIstance = int.MaxValue; Pirate closestPirate = null; pirates.ForEach(pirate => { if (!pirate.IsLost) { int distnace = state.Distance(pirate, island); if (distnace < closetDIstance) { closestPirate = pirate; closetDIstance = distnace; } } }); return(closestPirate); }
//! Simulates collision of the missile and the target. private void Collide() { Meteor hitMeteor = target.gameObject.GetComponent <Meteor>(); Pirate hitPirate = target.gameObject.GetComponent <Pirate>(); if (hitMeteor != null) { if (hitMeteor.destroying == false) { hitMeteor.GetComponent <Meteor>().Explode(); } Explode(); } if (hitPirate != null) { if (hitPirate.destroying == false) { hitPirate.GetComponent <Pirate>().Explode(); } Explode(); } }
/// <summary> /// Returns all of the safe locations in distance maxMoves from start and the number of threating enemy pirates at the new location. /// </summary> private List <KeyValuePair <Location, double> > GetTreasureDodgeOptions(Pirate treasurePirate, Game game) { int moves = 1; List <KeyValuePair <Location, double> > safespots = new List <KeyValuePair <Location, double> >(); List <Pirate> threats = game.GetEnemyDangerousPiratesInAttackRange(treasurePirate); threats.RemoveAll(p => game.PredictAttack(p) == PredictionResult.False); if (treasurePirate.DefenseDuration > 0 || threats.Count == 0) { return(safespots); } List <Location> allSpots = new List <Location>(); allSpots.Add(new Location(treasurePirate.Location.Row + moves, treasurePirate.Location.Collumn)); allSpots.Add(new Location(treasurePirate.Location.Row - moves, treasurePirate.Location.Collumn)); allSpots.Add(new Location(treasurePirate.Location.Row, treasurePirate.Location.Collumn + moves)); allSpots.Add(new Location(treasurePirate.Location.Row, treasurePirate.Location.Collumn - moves)); foreach (Location spot in allSpots) { if (game.InMap(spot)) { List <Pirate> newThreats = game.GetEnemyDangerousPiratesInAttackRange(spot); newThreats.RemoveAll(p => game.PredictAttack(p) == PredictionResult.False); if (newThreats.Intersect(threats).Count() == 0) { safespots.Add(new KeyValuePair <Location, double>(spot, newThreats.Count)); } } } return(safespots); }
//////////Methods////////// /// <summary> /// Creates a new Pirate Manager, to manage the pirates of "owner" /// </summary> public PirateManager(IPirateGame game, Owner owner) { allPiratesProxy = new UpdateProxy <IPirateGame>(); // choose the list of all pirates to use List <Pirates.Pirate> allPirates; if (owner == Owner.Me) { allPirates = game.AllMyPirates(); } else { allPirates = game.AllEnemyPirates(); } // initialize the lists containing the pirates by states this.piratesByStates = new List <Pirate> [(int)PirateState.COUNT]; for (int i = 0; i < this.piratesByStates.Length; i++) { this.piratesByStates[i] = new List <Pirate>(); } // initialize the allPirates array this.allPirates = new Pirate[allPirates.Count]; // initialize all the pirates in the allPirates array, and add them to allPiratesProxy and freePirates foreach (Pirates.Pirate p in allPirates) { Pirate newPirate = new Pirate(p, game.GetActionsPerTurn()); this.allPirates[p.Id] = newPirate; this.piratesByStates[(int)PirateState.Free].Add(newPirate); this.allPiratesProxy.Add(newPirate); } this.Armada = this.GetAllPiratesCount() > 6; }
private void addPirate() { Pirate pirate = new Pirate(); pirate.x = minX; pirate.y = maxY; holder.AddChild(pirate); pirates.Add(pirate); }
public override CommandProcessor Given() { activeUnitId = Guid.NewGuid(); activeUnit = new Pirate { Id = activeUnitId, X = 10, Y = 4 }; FirstPlayer.Units.Add(activeUnit); return new CommandProcessor(Calculator, State); }
static string Example2() { NamedReg a = new NamedReg("a"); NamedReg b = new NamedReg("b"); NamedReg c = new NamedReg("c"); NamedReg det = new NamedReg("det"); IdList rl1 = new IdList(); rl1.Add(a); rl1.Add(b); rl1.Add(c); rl1.Add(det); LocalDecl ld1 = new LocalDecl(new NumType(), rl1); IntLiteral il3 = new IntLiteral(2); Assign a12 = new Assign(a, il3); IntLiteral il4 = new IntLiteral(-3); Assign a13 = new Assign(b, il4); IntLiteral il5 = new IntLiteral(-2); Assign a14 = new Assign(c, il5); UnaryNeg un1 = new UnaryNeg(b); TmpNumReg tnr0 = new TmpNumReg(0); Assign a1 = new Assign(tnr0, un1); TmpNumReg tnr1 = new TmpNumReg(1); BinaryMul bm1 = new BinaryMul(b, b); Assign a2 = new Assign(tnr1, bm1); TmpNumReg tnr2 = new TmpNumReg(2); IntLiteral il1 = new IntLiteral(4); BinaryMul bm2 = new BinaryMul(il1, a); Assign a3 = new Assign(tnr2, bm2); BinaryMul bm3 = new BinaryMul(tnr2, c); Assign a4 = new Assign(tnr2, bm3); TmpNumReg tnr3 = new TmpNumReg(3); IntLiteral il2 = new IntLiteral(2); BinaryMul bm4 = new BinaryMul(il2, a); Assign a5 = new Assign(tnr3, bm4); BinarySub bs1 = new BinarySub(tnr1, tnr2); Assign a6 = new Assign(det, bs1); TmpNumReg tnr4 = new TmpNumReg(4); Call sqrt = new Call("sqrt", det); Assign a7 = new Assign(tnr4, sqrt); NamedReg x1 = new NamedReg("x1"); NamedReg x2 = new NamedReg("x2"); IdList rl2 = new IdList(); rl2.Add(x1); rl2.Add(x2); LocalDecl ld2 = new LocalDecl(new NumType(), rl2); BinaryAdd ba1 = new BinaryAdd(tnr0, tnr4); Assign a8 = new Assign(x1, ba1); BinaryDiv bd1 = new BinaryDiv(x1, tnr3); Assign a9 = new Assign(x1, bd1); BinarySub bs2 = new BinarySub(tnr0, tnr4); Assign a10 = new Assign(x2, bs2); AssignDiv a11 = new AssignDiv(x2, tnr3); StringLiteral s1 = new StringLiteral("Answers to ABC formula are:\n"); Call c1 = new Call("print", s1); CallStmt print1 = new CallStmt(c1); StringLiteral s2 = new StringLiteral("x1 = "); Call c2 = new Call("print", s2); CallStmt print2 = new CallStmt(c2); Call c3 = new Call("print", x1); CallStmt print3 = new CallStmt(c3); StringLiteral s4 = new StringLiteral("\nx2 = "); Call c4 = new Call("print", s4); CallStmt print4 = new CallStmt(c4); Call c5 = new Call("print", x2); CallStmt print5 = new CallStmt(c5); StringLiteral s6 = new StringLiteral("\n"); Call c6 = new Call("print", s6); CallStmt print6 = new CallStmt(c6); StmtList sl1 = new StmtList(); sl1.Add(ld1); sl1.Add(a12); sl1.Add(a13); sl1.Add(a14); sl1.Add(a1); sl1.Add(a2); sl1.Add(a3); sl1.Add(a4); sl1.Add(a5); sl1.Add(a6); sl1.Add(a7); sl1.Add(ld2); sl1.Add(a8); sl1.Add(a9); sl1.Add(a10); sl1.Add(a11); sl1.Add(print1); sl1.Add(print2); sl1.Add(print3); sl1.Add(print4); sl1.Add(print5); sl1.Add(print6); Sub foo = new Sub("foo", sl1); Pirate p = new Pirate(); p.Add(foo); StringWriter sw = new StringWriter(); PirateWriter pv = new PirateWriter(sw); DynamicVisitor.accept(p, pv); return sw.ToString(); }
static string Example5() { NamedReg x1 = new NamedReg(); x1.name = "x1"; NamedReg x2 = new NamedReg(); x2.name = "x2"; IdList idl1 = new IdList(); idl1.Add(x1); idl1.Add(x2); LocalDecl ld1 = new LocalDecl(); ld1.type = new NumType(); ld1.id_list = idl1; AtomExprList ael1 = new AtomExprList(); ael1.Add(x1); ael1.Add(x2); ReturnStmt rs1 = new ReturnStmt(); rs1.rv = ael1; StmtList sl1 = new StmtList(); sl1.Add(ld1); sl1.Add(rs1); Sub abc = new Sub("abc", sl1); Pirate p = new Pirate(); p.Add(abc); StringWriter sw = new StringWriter(); PirateWriter pv = new PirateWriter(sw); DynamicVisitor.accept(p, pv); return sw.ToString(); }
static string Example4() { StmtList sl1 = new StmtList(); Sub foo = new Sub("foo", sl1); Pirate p = new Pirate(); p.Add(foo); ParamDecl pd1 = new ParamDecl(); pd1.type = new IntType(); IdList idl1 = new IdList(); NamedReg n = new NamedReg(); n.name = "n"; idl1.Add(n); pd1.id_list = idl1; sl1.Add(pd1); ParamDecl pd2 = new ParamDecl(); pd2.type = new StringType(); IdList idl2 = new IdList(); NamedReg message = new NamedReg(); message.name = "message"; idl2.Add(message); pd2.id_list = idl2; sl1.Add(pd2); StringWriter sw = new StringWriter(); PirateWriter pv = new PirateWriter(sw); DynamicVisitor.accept(p, pv); return sw.ToString(); }
public virtual void Activate(Pirate p) { isActive = true; //activePirate = p; }
static string Example3() { Pirate p = new Pirate(); StmtList sl1 = new StmtList(); Sub joe = new Sub("joe", sl1); p.Add(joe); LocalDecl ld1 = new LocalDecl(); ld1.type = new StringType(); NamedReg name = new NamedReg(); name.name = "name"; IdList idl1 = new IdList(); idl1.Add(name); ld1.id_list = idl1; sl1.Add(ld1); Assign a1 = new Assign(); a1.lval = name; StringLiteral s1 = new StringLiteral(); s1.value = " Joe!"; a1.rval = s1; sl1.Add(a1); Assign a2 = new Assign(); StringLiteral s2 = new StringLiteral(); s2.value = "Hi!"; TmpStringReg tsr0 = new TmpStringReg(); tsr0.number = 0; a2.lval = tsr0; a2.rval = s2; sl1.Add(a2); Assign a3 = new Assign(); TmpStringReg tsr1 = new TmpStringReg(); tsr1.number = 1; BinaryCat bc1 = new BinaryCat(); bc1.a = tsr0; bc1.b = name; a3.lval = tsr1; a3.rval = bc1; sl1.Add(a3); AssignCat a4 = new AssignCat(); a4.lval = tsr1; StringLiteral s3 = new StringLiteral(); s3.value = "\n"; a4.rval = s3; sl1.Add(a4); CallStmt cs1 = new CallStmt(); Call c1 = new Call(); c1.func = "print"; c1.args = tsr1; cs1.call = c1; sl1.Add(cs1); StringWriter sw = new StringWriter(); PirateWriter pv = new PirateWriter(sw); DynamicVisitor.accept(p, pv); return sw.ToString(); }
static string Example6() { AtomExprList ael1 = new AtomExprList(); Call c1 = new Call("foo", ael1); CallStmt cs1 = new CallStmt(c1); NumLiteral n1 = new NumLiteral(3.14); TmpNumReg tnr0 = new TmpNumReg(0); Assign a1 = new Assign(tnr0, n1); TmpIntReg tir0 = new TmpIntReg(0); IntLiteral i1 = new IntLiteral(42); StringLiteral s1 = new StringLiteral("hi"); AtomExprList ael2 = new AtomExprList(); ael2.Add(tir0); ael2.Add(i1); ael2.Add(s1); Call c2 = new Call("bar", ael2); CallStmt cs2 = new CallStmt(c2); NamedReg a = new NamedReg("a"); LocalDecl ld1 = new LocalDecl(new IntType(), a); NamedReg b = new NamedReg("b"); LocalDecl ld2 = new LocalDecl(new NumType(), b); NamedReg c = new NamedReg("c"); LocalDecl ld3 = new LocalDecl(new StringType(), c); TmpNumReg tnr2 = new TmpNumReg(2); NumLiteral n2 = new NumLiteral(2.7); Assign a2 = new Assign(tnr2, n2); StringLiteral s2 = new StringLiteral("hello yourself"); AtomExprList ael3 = new AtomExprList(); ael3.Add(tnr2); ael3.Add(s2); Call c3 = new Call("baz", ael3); RegList rl4 = new RegList(); rl4.Add(a); rl4.Add(b); rl4.Add(c); Assign a3 = new Assign(rl4, c3); StmtList sl1 = new StmtList(); sl1.Add(cs1); sl1.Add(a1); sl1.Add(cs2); sl1.Add(ld1); sl1.Add(ld2); sl1.Add(ld3); sl1.Add(a2); sl1.Add(a3); Sub main = new Sub("main", sl1); StringLiteral s3 = new StringLiteral("Foo!\n"); Call c4 = new Call("print", s3); CallStmt cs3 = new CallStmt(c4); StmtList sl2 = new StmtList(); sl2.Add(cs3); Sub foo = new Sub("foo", sl2); NamedReg i = new NamedReg("i"); ParamDecl pd1 = new ParamDecl(new NumType(), i); NamedReg answer = new NamedReg("answer"); ParamDecl pd2 = new ParamDecl(new IntType(), answer); NamedReg message = new NamedReg("message"); ParamDecl pd3 = new ParamDecl(new StringType(), message); StringLiteral s4 = new StringLiteral("Bar!\n"); Call print1 = new Call("print", s4); CallStmt cs4 = new CallStmt(print1); Call print2 = new Call("print", i); CallStmt cs5 = new CallStmt(print2); StringLiteral s5 = new StringLiteral("\n"); Call print3 = new Call("print", s5); CallStmt cs6 = new CallStmt(print3); Call print4 = new Call("print", answer); CallStmt cs7 = new CallStmt(print4); CallStmt cs8 = new CallStmt(print3); Call print5 = new Call("print", message); CallStmt cs9 = new CallStmt(print5); StmtList sl3 = new StmtList(); sl3.Add(pd1); sl3.Add(pd2); sl3.Add(pd3); sl3.Add(cs4); sl3.Add(cs5); sl3.Add(cs6); sl3.Add(cs7); sl3.Add(cs8); sl3.Add(cs9); Sub bar = new Sub("bar", sl3); NamedReg e = new NamedReg("e"); ParamDecl pd4 = new ParamDecl(new NumType(), e); NamedReg msg = new NamedReg("msg"); ParamDecl pd5 = new ParamDecl(new StringType(), msg); StringLiteral s6 = new StringLiteral("Baz!\n"); Call print7 = new Call("print", s6); CallStmt cs10 = new CallStmt(print7); Call print8 = new Call("print", e); CallStmt cs11 = new CallStmt(print8); Call print9 = new Call("print", s5); CallStmt cs12 = new CallStmt(print9); Call print10 = new Call("print", msg); CallStmt cs13 = new CallStmt(print10); AtomExprList ael4 = new AtomExprList(); ael4.Add(new IntLiteral(1000)); ael4.Add(new NumLiteral(1.23)); ael4.Add(new StringLiteral("hi from baz")); ReturnStmt rs1 = new ReturnStmt(ael4); StmtList sl4 = new StmtList(); sl4.Add(pd4); sl4.Add(pd5); sl4.Add(cs10); sl4.Add(cs11); sl4.Add(cs12); sl4.Add(cs13); sl4.Add(rs1); Sub baz = new Sub("baz", sl4); Pirate p = new Pirate(); p.Add(main); p.Add(foo); p.Add(bar); p.Add(baz); StringWriter sw = new StringWriter(); PirateWriter pv = new PirateWriter(sw); DynamicVisitor.accept(p, pv); return sw.ToString(); }
private PirateAndCandidate GetCandidate(IPirateGame game, Pirate pirate) { var treasures = game.Treasures(); var selectedTreasure = treasures.OrderBy(t => game.Distance(pirate, t)).FirstOrDefault(); return new PirateAndCandidate { Pirate = pirate, Treasure = selectedTreasure, Distance = game.Distance(pirate, selectedTreasure) }; }
private void MoveToBase(IPirateGame game, Pirate pirate) { game.Debug("Move pirate {0} home", pirate.Id); List<Location> possibleLocations = game.GetSailOptions(pirate, pirate.InitialLocation, 1); game.SetSail(pirate, possibleLocations[0]); }