/// <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) { //Counts how many of the pirates in the cluster carry treasure, will be used for event value. List <Pirate> treasurePiratesInCluster = this.hotspot.Intersect(game.GetMyPirates(PirateState.CarryingTreasure)).ToList(); int valueInCluster = treasurePiratesInCluster.Sum(pirate => pirate.CarriedTreasureValue); if (valueInCluster == 0) { return; } // the pirates in the threat zone List <Pirate> enemiesInCluster = game.GetEnemyPiratesInAttackRange(this.hotspot, PirateState.Free).Union( game.GetEnemyPiratesInAttackRange(this.hotspot, PirateState.Drunk)).ToList(); //Checks if there is an enemy in the cluster already, if so - sends in the cavalry! foreach (Pirate enemy in enemiesInCluster) { if (enemy.State == PirateState.Drunk && game.GetPirateSpawnOn(enemy.Location) != null && game.GetPirateSpawnOn(enemy.Location).Owner != Owner.Me) { continue; } foreach (Pirate myPirate in game.GetMyPirates(PirateState.Free)) { var sailOptions = game.GetCompleteSailOptions(myPirate, enemy, myPirate.DefenseDuration == 0 && !Game.InAttackRange(myPirate, enemy, enemy.AttackRadius), Terrain.CurrentTreasureLocation); foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, pair.Key), this.Id); ap.AddEnemyPirate(enemy); double value = BASE_VAL + valueInCluster * TREASURE_VAL + (this.hotspot.Count - treasurePiratesInCluster.Count) * NO_TREASURE_VAL + enemiesInCluster.Count * ENEMY_VAL - Utils.Pow(pair.Value, 1.25); if (this.hotspot.Contains(myPirate)) { value += IS_HOME_VAL; } if (statesManager.GetState <ImpendingVictoryState>().IsVictoryIncoming) { value *= IMPENDING_VICTORY_MULT; } ap.BurnInformation("Made in AntiTeroristEvent against {0}, Value: {1:F3}", enemy.Id, value); chooser.AddActionsPack(ap, value); } } } } }
/// <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.CanMove || this.myPirate.State != PirateState.CarryingTreasure) // can't move = can't dodge / if I'm shielded no point in dodging { return; } TreasureDancingState treasureDancingState = statesManager.GetState <TreasureDancingState>(); bool dodgedLastTurn = treasureDancingState.IsPirateDancing(this.myPirate); List <Pirate> enemies = game.GetEnemyPirates(PirateState.Free); if (enemies.Count == 0) // no enemies = no threat { return; } if (!dodgedLastTurn) //Pirate is carrying Treasure - can only move 1 step { foreach (var pair in GetTreasureDodgeOptions(this.myPirate, game)) { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); double distanceLeft = Game.ManhattanDistance(pair.Key, this.myPirate.InitialLocation); double getCloserPrioritize = (distanceLeft == 0 ? myPirate.CarriedTreasureValue * 65536 : (distanceLeft + 1.0) / (distanceLeft)); //This is so it would prioritize moving in the direction that makes us closer. double value = myPirate.CarriedTreasureValue * PIRATE_WITH_TREASURE_DODGING - pair.Value / (pair.Value + 1.0) + getCloserPrioritize; ap.BurnInformation("Made by DodgeEvent - case: dodge attack, Value: {0:F3}", value); chooser.AddActionsPack(ap, value); } } else { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, this.myPirate), base.Id); double value = myPirate.CarriedTreasureValue * PIRATE_WITH_TREASURE_DODGING - 0.1; ap.BurnInformation("Made by DodgeEvent - case: dodge ram stage 2, Value: {0:F3}", value); chooser.AddActionsPack(ap, value); } foreach (var pair in GetRamDodgeOptions(this.myPirate, game)) { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); double value = myPirate.CarriedTreasureValue * PIRATE_WITH_TREASURE_DODGING - pair.Value / (pair.Value + 1.0); ap.BurnInformation("Made by DodgeEvent - case: dodge ram stage 1, Value: {0:F3}", value); chooser.AddActionsPack(ap, value); } }
/// <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) { //Counts how many of the pirates in the cluster carry treasure, will be used for event value. List <Pirate> treasurePiratesInCluster = this.hotspot.Intersect(game.GetEnemyPirates(PirateState.CarryingTreasure)).ToList(); int valueInCluster = treasurePiratesInCluster.Sum(pirate => pirate.CarriedTreasureValue); List <Pirate> protectors = game.GetEnemyPiratesInAttackRange(this.hotspot, PirateState.Free); bool myPirateInCluster = false; int drunkDouches = game.GetMyPiratesInAttackRange(this.hotspot, PirateState.Drunk).Count; //Checks if there is a pirate in the cluster already, if so - tells it to be a smart douchebag! foreach (Pirate myPirate in game.GetMyPirates(PirateState.Free)) { if (Game.InAttackRange(myPirate, this.hotspot, myPirate.AttackRadius)) // pirate is in cluster already! { myPirateInCluster = true; //Release the douche!; if (treasurePiratesInCluster.Count > 0) { foreach (Pirate enemy in treasurePiratesInCluster) // go to an enemy with treasure spawn to lock it (act as a douch) { if (game.GetPirateOn(enemy.InitialLocation) != null && game.GetPirateOn(enemy.InitialLocation) != myPirate) { continue; } List <Pirate> threats = game.GetEnemyDangerousPiratesInAttackRange(myPirate); var sailOptions = game.GetCompleteSailOptions(myPirate, enemy.InitialLocation, false, Terrain.CurrentTreasureLocation); foreach (var pair in sailOptions) { if (pair.Key.Equals(enemy.InitialLocation) || game.GetEnemyDangerousPiratesInAttackRange(pair.Key).Union(threats).Count() == 0 || myPirate.DefenseDuration > 0) { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = DOUCH_SPAWN_CAMP + valueInCluster * TREASURE_VAL + (this.hotspot.Count - treasurePiratesInCluster.Count) * NO_TREASURE_VAL - Game.ManhattanDistance(enemy.InitialLocation, enemy) - Utils.Pow(pair.Value, 1.2); if (enemy.HasPowerup(SpeedPowerup.NAME) && statesManager.GetState <ImpendingDoomState>().IsDoomIncoming) { value *= IMPENDING_POWERUP_MULTIPLYER; } ap.BurnInformation("Made in DouchebagEvent - case: spawn-camp pirate {0}, Value: {1:F3}", enemy.Id, value); chooser.AddActionsPack(ap, value); } } } } /*else * { * foreach (var pair in game.GetCompleteSailOptions(myPirate, this.hotspot, 0, 0, myPirate.MaxSpeed, true, 0, myPirate.MaxSpeed, 2, Terrain.CurrentTreasureLocation, Terrain.EnemyLocation)) // or return to the center of the cluster * { * //ActionsPack ap = ActionsPack.NewSailPack(game, myPirate, pair.Key, this.Id); * ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, pair.Key), base.Id); * * double value = DOUCH_CLUSTER_CAMP + (this.enemiesInCluster.Count - treasurePiratesInCluster.Count) * NO_TREASURE_VAL - Utils.Pow(pair.Value, 1.2) - PROTECTOR_VAL * protectors.Count + treasurePiratesInCluster.Count * TREASURE_VAL; * * ap.BurnInformation("Made in DouchebagEvent case: cluster-camp, Value: {0:F3}", value); * * chooser.AddActionsPack(ap, value); * } * }*/ } } if (!myPirateInCluster && drunkDouches < treasurePiratesInCluster.Count) // no pirate in cluster - send in the douches! (become a doouche) { foreach (Pirate myPirate in game.GetMyPirates(PirateState.Free)) { foreach (Pirate enemy in treasurePiratesInCluster) // go to an enemy with treasure spawn to lock it (act as a douch) { var sailOptions = game.GetCompleteSailOptions(myPirate, enemy.InitialLocation, Terrain.CurrentTreasureLocation); foreach (var pair in sailOptions) { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = DOUCH_BECOME + valueInCluster * TREASURE_VAL + (this.hotspot.Count - treasurePiratesInCluster.Count) * NO_TREASURE_VAL - Game.ManhattanDistance(enemy.InitialLocation, enemy) - Utils.Pow(pair.Value, 1.5) - PROTECTOR_VAL * protectors.Count; if (enemy.HasPowerup(SpeedPowerup.NAME) && statesManager.GetState <ImpendingDoomState>().IsDoomIncoming) { value *= IMPENDING_POWERUP_MULTIPLYER; } ap.BurnInformation("Made in DouchebagEvent case: become spawn-camper on pirate {0}, Value: {1:F3}", enemy.Id, value); chooser.AddActionsPack(ap, value); } } /*var sailOptions = game.GetCompleteSailOptions(myPirate, this.hotspot, 0, 0, myPirate.MaxSpeed, true, 0, myPirate.MaxSpeed, 2, Terrain.CurrentTreasureLocation); * * foreach (var pair in sailOptions) * { * if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place * { * //ActionsPack ap = ActionsPack.NewSailPack(game, myPirate, pair.Key, this.Id); * ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, pair.Key), base.Id); * * double value = DOUCH_BECOME + treasurePiratesInCluster.Count * TREASURE_VAL + (this.enemiesInCluster.Count - treasurePiratesInCluster.Count) * NO_TREASURE_VAL - Utils.Pow(pair.Value, 1.25) - PROTECTOR_VAL * protectors.Count; * value = 0.2 * value; * * ap.BurnInformation("Made in DouchebagEvent case: become cluster-camper, Value: {0:F3}", value); * * chooser.AddActionsPack(ap, value); * } * }*/ } } }
/// <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.CanMove || this.myPirate.State != PirateState.Free) //If my pirate can't move, or isn't free he can't Seek&Destroy { return; } // get all the enemy pirates with treasure, sorted by their manhattan distance to me List <Pirate> enemyPiratesWithTreasure = game.GetEnemyClosestPirates(this.myPirate, PirateState.CarryingTreasure); ImpendingDoomState impendingDoom = statesManager.GetState <ImpendingDoomState>(); double pirateCountMultiplier = (double)game.ActionsPerTurn / (double)game.GetAllEnemyPiratesCount(); pirateCountMultiplier = pirateCountMultiplier > 1 ? 1.0 : pirateCountMultiplier; // If the enemy has treasure foreach (Pirate enemy in enemyPiratesWithTreasure) { if (Game.InAttackRange(this.myPirate, enemy, this.myPirate.AttackRadius - 1)) { continue; //We are in attack range to AttackEvent. This should be handled by it. } int distanceLeftForEnemy = Game.ManhattanDistance(enemy, enemy.InitialLocation); if (distanceLeftForEnemy <= 1 || distanceLeftForEnemy < Game.ManhattanDistance(this.myPirate, enemy) / game.ActionsPerTurn) { continue; //It's too late now, we can't reach him. Douchebag should handle this. } //get the sailing directions ILocateable dest = enemy; int distanceFromDest = (int)this.myPirate.AttackRadius - 2; foreach (Powerup up in game.GetPowerups()) { if (up is AttackPowerup && Game.OnTrack(myPirate, enemy, up)) { dest = up; distanceFromDest = 0; break; } } var sailOptions = game.GetCompleteSailOptions(this.myPirate, enemy, 0, distanceFromDest, Terrain.CurrentTreasureLocation, Terrain.EnemyLocation); //Get sailing packs - with Value and Burnt information according to the Distance Category from the enemy switch (GetDistanceCategory(game, enemy, Game.EuclideanDistance(myPirate, enemy))) { case DistanceCategory.Close: //enemy is close to me foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = CLOSE_ENEMY_HAS_TREASURE * enemy.CarriedTreasureValue - Utils.Pow((pair.Value), 1.5) - Game.ManhattanDistance(pair.Key, enemy.InitialLocation); if (impendingDoom.IsDoomIncoming) { value = value * IMPENDING_DOOM_MULTIPLYER; } if (myPirate.HasPowerup(AttackPowerup.NAME)) { value = value * ATTACK_POWERUP_MULTIPLYER; } //value *= pirateCountMultiplier; ap.BurnInformation("Made in SeekAndDestroyEvent, against {0}, value: {1:F3}, case: close treasure", enemy.Id, value); chooser.AddActionsPack(ap, value); } } break; case DistanceCategory.Medium: //enemy is in medium range foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = MEDIUM_RANGE_ENEMY_HAS_TREASURE * enemy.CarriedTreasureValue - Utils.Pow((pair.Value) + (game.ActionsPerTurn + 1) / 2 - 2, 1.3) - Game.ManhattanDistance(pair.Key, enemy.InitialLocation); if (enemy.HasPowerup(SpeedPowerup.NAME)) { value += ENEMY_WITH_SPEED_UP_AND_TREASURE; } if (impendingDoom.IsDoomIncoming) { value = value * IMPENDING_DOOM_MULTIPLYER; } if (myPirate.HasPowerup(AttackPowerup.NAME)) { value = value * ATTACK_POWERUP_MULTIPLYER; } value *= pirateCountMultiplier; ap.BurnInformation("Made in SeekAndDestroyEvent, against {0}, value: {1:F3}, case: medium treasure", enemy.Id, value); chooser.AddActionsPack(ap, value); } } break; case DistanceCategory.Far: //enemy is far away foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = FAR_RANGE_ENEMY_HAS_TREASURE * enemy.CarriedTreasureValue - Utils.Pow((pair.Value) - game.ActionsPerTurn / 3 - 2, 1.2) - Game.ManhattanDistance(pair.Key, enemy.InitialLocation); if (enemy.HasPowerup(SpeedPowerup.NAME)) { value += ENEMY_WITH_SPEED_UP_AND_TREASURE; } if (impendingDoom.IsDoomIncoming) { value = value * IMPENDING_DOOM_MULTIPLYER; } if (myPirate.HasPowerup(AttackPowerup.NAME)) { value = value * ATTACK_POWERUP_MULTIPLYER; } value *= pirateCountMultiplier; ap.BurnInformation("Made in SeekAndDestroyEvent, against {0}, value: {1:F3}, case: far treasure", enemy.Id, value); chooser.AddActionsPack(ap, value); } } break; } } Pirate closest = null; if (game.GetEnemyPiratesCount(PirateState.Free) > 0) { closest = game.GetEnemyClosestPirates(myPirate, PirateState.Free)[0]; } //if the enemy doesn't have a treasure foreach (Pirate enemy in game.GetEnemyPirates(PirateState.Free)) { if (Game.InAttackRange(this.myPirate, enemy, this.myPirate.AttackRadius)) { continue; //We are in attack range to AttackEvent. This should be handled by it. } //get the sailing directions var sailOptions = game.GetCompleteSailOptions(this.myPirate, enemy, 0, (int)this.myPirate.AttackRadius, Terrain.CurrentTreasureLocation, Terrain.EnemyLocation); //Get sailing packs - with Value and Burnt information according to the Distance Category from the enemy if (enemy.PowerupCount > 0) { switch (GetDistanceCategory(game, enemy, Game.EuclideanDistance(myPirate, enemy))) { case DistanceCategory.Close: //enemy is close to me foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = CLOSE_ENEMY_HAS_POWERUP - Utils.Pow((pair.Value), 1.3); if (myPirate.HasPowerup(AttackPowerup.NAME)) { value = value * ATTACK_POWERUP_MULTIPLYER; } value *= pirateCountMultiplier; ap.BurnInformation("Made in SeekAndDestroyEvent, against {0}, value: {1:F3}, case: close powerup", enemy.Id, value); chooser.AddActionsPack(ap, value); } } break; case DistanceCategory.Medium: //enemy is in medium range foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = MEDIUM_RANGE_ENEMY_HAS_POWERUP - Utils.Pow((pair.Value) + (game.ActionsPerTurn + 1) / 2 - 2, 1.2); if (myPirate.HasPowerup(AttackPowerup.NAME)) { value = value * ATTACK_POWERUP_MULTIPLYER; } value *= pirateCountMultiplier; ap.BurnInformation("Made in SeekAndDestroyEvent, against {0}, value: {1:F3}, case: medium powerup", enemy.Id, value); chooser.AddActionsPack(ap, value); } } break; case DistanceCategory.Far: //enemy is far away foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = FAR_RANGE_ENEMY_HAS_POWERUP - Utils.Pow((pair.Value) - game.ActionsPerTurn / 3 - 2, 1); if (myPirate.HasPowerup(AttackPowerup.NAME)) { value = value * ATTACK_POWERUP_MULTIPLYER; } value *= pirateCountMultiplier; ap.BurnInformation("Made in SeekAndDestroyEvent, against {0}, value: {1:F3}, case: far powerup", enemy.Id, value); chooser.AddActionsPack(ap, value); } } break; } } else if (enemy == closest || !game.EnemyArmada) { if (impendingDoom.IsDoomIncoming) { return; } if (myPirate.CanAttack) //Seek and Destroy a non-treasure enemy only if you can shoot him { if (Game.InAttackRange(this.myPirate, enemy, this.myPirate.AttackRadius)) { continue; //We are in attack range to AttackEvent. This should be handled by it.; } //Get sailing packs foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddEnemyPirate(enemy); double value = Utils.Max(ENEMY_HAS_NO_TREASURE - Utils.Pow(pair.Value, 0.7), 1.0 / (pair.Value + 1.0)); if (myPirate.HasPowerup(AttackPowerup.NAME)) { value = value * ATTACK_POWERUP_MULTIPLYER; } value *= pirateCountMultiplier; ap.BurnInformation("Made in SeekAndDestroyEvent, against {0}, value: {1:F3}, case: no Treasure", enemy.Id, value); chooser.AddActionsPack(ap, value); } } } } } }
/// <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.CanMove || this.myPirate.State != PirateState.Free) { return; } int myMaxSteps = myPirate.MaxSpeed; int enemyMaxSteps; double multiplyer = Utils.Pow(1 - ((double)game.GetMyPiratesCount(PirateState.CarryingTreasure)) / game.GetMyPiratesCount(PirateState.Free, PirateState.CarryingTreasure), 2); ThreatenedTreasureState treasureState = statesManager.GetState <ThreatenedTreasureState>(); List <Treasure> treasures = treasureState.GetThreatenedTreasures().OrderBy(t => Game.ManhattanDistance(t, this.myPirate)).ToList(); while (treasures.Count > 0 && game.GetPirateOn(treasures[0]) != null) { treasures.Remove(treasures[0]); } if (treasures.Count == 0) { return; } if (Game.ManhattanDistance(this.myPirate, treasures[0]) > myMaxSteps) //only do area clear if close enough to capture treasure { return; } Treasure closestTreasure = treasures[0]; multiplyer *= closestTreasure.Value; foreach (Pirate enemy in game.GetEnemyPirates(PirateState.Free)) { enemyMaxSteps = enemy.MaxSpeed; if (Game.ManhattanDistance(enemy, closestTreasure) > enemyMaxSteps)//only do area clear if enemy is close enough to capture treasure { continue; } if (!Game.InAttackRange(this.myPirate, closestTreasure, this.myPirate.AttackRadius + 1)) //Get closer. { var sailOptions = game.GetCompleteSailOptions(this.myPirate, closestTreasure, (int)this.myPirate.AttackRadius + 1, (int)this.myPirate.AttackRadius + 1, Terrain.InEnemyRange, Terrain.CurrentTreasureLocation); foreach (var pair in sailOptions) { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), this.Id); ap.AddTreasure(treasures[0]); double value = CLEAR_VALUE * multiplyer; ap.BurnInformation("Made in AreaClearEvent on Treasure {0} - case: not close enough, Value {1:F3}", closestTreasure.Id, value); chooser.AddActionsPack(ap, value); } } else if (Game.InAttackRange(this.myPirate, closestTreasure, this.myPirate.AttackRadius) && this.myPirate.CanAttack && enemy.DefenseDuration == 0 && Game.InAttackRange(this.myPirate, enemy, this.myPirate.AttackRadius)) //Attack enemy. { ActionsPack ap = ActionsPack.NewCommandPack(game, new AttackCommand(this.myPirate, enemy), this.Id); ap.AddTreasure(treasures[0]); ap.AddEnemyPirate(enemy); double value = CLEAR_VALUE * multiplyer; ap.BurnInformation("Made in AreaClearEvent on Treasure {0} - case: too close, attack pirate {1}, Value: {2:F3}", closestTreasure.Id, enemy.Id, value); chooser.AddActionsPack(ap, value); } else if (Game.InAttackRange(this.myPirate, closestTreasure, this.myPirate.AttackRadius + 1)) //Stay Still. TODO: ask Adi/Itai why isn't this an else { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, this.myPirate), this.Id); ap.AddTreasure(closestTreasure); double value = CLEAR_VALUE * multiplyer; ap.BurnInformation("Made in AreaClearEvent on Treasure {0} - case: close enough, Value {1:F3}", closestTreasure.Id, value); chooser.AddActionsPack(ap, value); } } }
/// <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.CanMove || this.myPirate.State != PirateState.Free) //If my pirate can't move or isn't free, he can't go to fetch treasures. { return; } // Get threatened treasure state ThreatenedTreasureState treasureState = statesManager.GetState <ThreatenedTreasureState>(); // Get all the free treasures and sort them by manhattan distance to me List <Treasure> freeTreasures = treasureState.GetSafeTreasures().OrderBy(t => Game.ManhattanDistance(t, this.myPirate)).ToList(); // calculate the maximum amount of treasures to check int maxTreasuresToCheck = (int)Utils.Min(freeTreasures.Count, game.GetMyPiratesCount(PirateState.Free), game.ActionsPerTurn, game.MaxCommandsPerTurn); // remove all the excess treasures, based on their value Dictionary <int, int> usedTreasuresDict = new Dictionary <int, int>(); // the key is the value of the treasure, and the value is how many treasures with the value are already in the list for (int i = 0; i < freeTreasures.Count;) { if (usedTreasuresDict.ContainsKey(freeTreasures[i].Value)) { usedTreasuresDict[freeTreasures[i].Value]++; if (usedTreasuresDict[freeTreasures[i].Value] > maxTreasuresToCheck) { freeTreasures.RemoveAt(i); } else { i++; } } else { usedTreasuresDict.Add(freeTreasures[i].Value, 1); i++; } } double multiplyer = Utils.Pow(1 - ((double)game.GetMyPiratesCount(PirateState.CarryingTreasure)) / game.GetMyPiratesCount(PirateState.Free, PirateState.CarryingTreasure), 2); // try to sail to each treasure foreach (Treasure t in freeTreasures) { if (game.GetPirateOn(t) != null) // there is a pirate where the treasure is, most likely a drunk one. Leave it be. { continue; } ILocateable dest = t; // search for a speed powerup on the way to the treasure foreach (Powerup up in game.GetPowerups()) { if (up is SpeedPowerup && Game.OnTrack(myPirate, t, up)) { dest = up; break; } } var sailOptions = game.GetCompleteSailOptions(this.myPirate, dest, Terrain.EnemyLocation, Terrain.CurrentTreasureLocation); int maxActionsUsed = (int)Utils.Min(this.myPirate.MaxSpeed, game.ActionsPerTurn, Game.ManhattanDistance(this.myPirate, dest)); foreach (var pair in sailOptions) { if (sailOptions[0].Value > pair.Value) //sail only if it's actually better than staying in place { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(this.myPirate, pair.Key), base.Id); ap.AddTreasure(t); double returnDistance = Game.ManhattanDistance(this.myPirate.InitialLocation, t); double maxDistance = game.Rows + game.Collumns; double value = (FETCH_VALUE - Utils.Pow(pair.Value, 0.9)) * multiplyer * ((maxDistance - returnDistance) / (maxDistance)); if (game.GetTreasuresCount(TreasureState.BeingCarried, TreasureState.Taken) == 0 && Game.ManhattanDistance(pair.Key, this.myPirate) == maxActionsUsed) { value += GAME_START_MULT; } value *= t.Value; if (myPirate.HasPowerup(SpeedPowerup.NAME)) { value *= SPEED_POWERUP_MULTIPLYER; } ap.BurnInformation("Made in FetchTreasureEvent. Fetching Treasure: {0}, value: {1:F3}", t.Id, value); chooser.AddActionsPack(ap, value); } } } }
/// <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.treasurePirate.State != PirateState.CarryingTreasure) { return; } //Counts how many of the pirates in the cluster carry treasure, will be used for event value. List <Pirate> enemyPirates = new List <Pirate>(); foreach (Pirate enemy in game.GetEnemyPirates(PirateState.Free)) { if (Game.InAttackRange(enemy, treasurePirate, enemy.AttackRadius + enemy.MaxSpeed)) { enemyPirates.Add(enemy); } } enemyPirates = enemyPirates.OrderBy(p => Game.EuclideanDistance(p, this.treasurePirate)).ToList(); if (enemyPirates.Count == 0) //No threats { return; } TreasureDancingState treasureDancingState = statesManager.GetState <TreasureDancingState>(); ImpendingVictoryState impendingVictory = statesManager.GetState <ImpendingVictoryState>(); //Sends in an escort to destory/block an enemy foreach (Pirate myPirate in game.GetMyPirates(PirateState.Free)) { //Bodyguard foreach (Pirate enemy in enemyPirates) // try to block an enemy's path/destroy it { //1st priority - shoot him! if (game.IsAttackPossible(myPirate, enemy) && !game.IsAttackPossible(enemy, treasurePirate)) { ActionsPack ap = ActionsPack.NewCommandPack(game, new AttackCommand(myPirate, enemy), base.Id); double value = ESCORT_GUARD_VALUE - Game.EuclideanDistance(enemy, this.treasurePirate); if (impendingVictory.IsVictoryIncoming) { value = value * IMPENDING_VICTORY_MULTIPLYER; } value *= this.treasurePirate.CarriedTreasureValue; ap.BurnInformation("Made in EscortEvent - case: shoot threat, Value: {0:F3}", value); chooser.AddActionsPack(ap, value); } //2nd priority - ram him! if (Game.ManhattanDistance(enemy, myPirate) <= myPirate.MaxSpeed) { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, enemy), base.Id); ap.AddEnemyPirate(enemy); double value = ESCORT_GUARD_VALUE - Game.EuclideanDistance(enemy, this.treasurePirate) - Game.ManhattanDistance(enemy, myPirate); if (impendingVictory.IsVictoryIncoming) { value = value * IMPENDING_VICTORY_MULTIPLYER; } value *= this.treasurePirate.CarriedTreasureValue; ap.BurnInformation("Made in EscortEvent - case: ram enemy {0}, Value: {1:F3}", enemy.Id, value); chooser.AddActionsPack(ap, value); } //3rd priority - body block him if (Game.EuclideanDistance(enemy, treasurePirate) >= game.AttackRadius) { foreach (var pair in game.GetCompleteSailOptions(myPirate, ClosestOnCircle(myPirate.AttackRadius, this.treasurePirate, enemy), 0, 1, Terrain.CurrentTreasureLocation, Terrain.EnemyLocation)) { ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, pair.Key), base.Id); double value = ESCORT_VALUE - Game.EuclideanDistance(enemy, this.treasurePirate) - Utils.Pow(pair.Value, 1.3); if (impendingVictory.IsVictoryIncoming) { value = value * IMPENDING_VICTORY_MULTIPLYER; } value *= this.treasurePirate.CarriedTreasureValue; ap.BurnInformation("Made in EscortEvent - case: block enemy {0}, Value: {1:F3}", enemy.Id, value); chooser.AddActionsPack(ap, value); } } } //This code does escorts even if there are no enemies close, currently not implemented /*else if (enemyPirates.Count <= 0) * { * foreach (var pair in game.GetCompleteSailOptions(myPirate, treasurePirate, Terrain.CurrentTreasureLocation, Terrain.EnemyLocation)) * { * ActionsPack ap = ActionsPack.NewCommandPack(game, new SailCommand(myPirate, pair.Key), base.Id); * * double value = 0.8 * (ESCORT_VALUE - Utils.Pow(Game.ManhattanDistance(myPirate, pair.Key), 1.3)); * if (impendingVictory.IsVictoryIncoming) * value = value * IMPENDING_VICTORY_MULTIPLYER; * value *= this.treasurePirate.CarriedTreasureValue; * * ap.BurnInformation("Made in EscortEvent - case: become escort, Value: {0:F3}", value); * * chooser.AddActionsPack(ap, value); * } * }*/ } }