public bool TryDeploy(TerritoryIDType terrID, int armies, bool force = false) { if (!force && Bot.AvoidTerritories.Contains(terrID)) { return(false); } Assert.Fatal(Bot.Standing.Territories[terrID].OwnerPlayerID == Bot.PlayerID, "Not owned"); if (armies == 0) { return(true); //just pretend like we did it } Assert.Fatal(armies > 0); if (!Bot.MakeOrders.IncomeTracker.TryRecordUsedArmies(terrID, armies)) { return(false); } var existing = Orders.OfType <GameOrderDeploy>().FirstOrDefault(o => o.DeployOn == terrID); if (existing != null) { existing.NumArmies += armies; } else { AddOrder(GameOrderDeploy.Create(Bot.PlayerID, armies, terrID)); } return(true); }
public static GameOrderDeploy Create(int numArmies, PlayerIDType playerID, TerritoryIDType deployOn) { var o = new GameOrderDeploy(); o.NumArmies = numArmies; o.PlayerID = playerID; o.DeployOn = deployOn; return(o); }
public static GameOrderDeploy Create(PlayerIDType playerID, int numArmies, TerritoryIDType deployOn, string reason) { var o = new GameOrderDeploy(); o.NumArmies = numArmies; o.PlayerID = playerID; o.DeployOn = deployOn; o.Reason = reason; return(o); }
public GameOrderDeploy Clone() { GameOrderDeploy clone = new GameOrderDeploy(); clone.PlayerID = PlayerID; clone.DeployOn = DeployOn; clone.NumArmies = NumArmies; clone.Reason = Reason; return(clone); }
private void AddBorderTerritoryDeployment(MultiMoves movesSoFar, int availableDeployment) { TerritoryStanding territoryToDeployTo = MapInformer.GetOwnedBorderTerritories(movesSoFar.GetTerritoryStandingsAfterAllMoves(), GameState.MyPlayerId).FirstOrDefault(); if (territoryToDeployTo == null) { territoryToDeployTo = MapInformer.GetOwnedTerritories(GameState.CurrentTurn().LatestTurnStanding.Territories.Values.ToList(), GameState.MyPlayerId).First(); } movesSoFar.AddDeployOrder(GameOrderDeploy.Create(GameState.MyPlayerId, availableDeployment, territoryToDeployTo.ID, REASON)); }
public void AddDeployOrder(GameOrderDeploy deployOrder) { standingCache = null; GameOrderDeploy alreadyPresentDeployOrder = DeployMoves.Where(o => o.DeployOn == deployOrder.DeployOn).FirstOrDefault(); if (alreadyPresentDeployOrder == null) { DeployMoves.Add(deployOrder); } else { alreadyPresentDeployOrder.NumArmies += deployOrder.NumArmies; } }
public bool PumpArmies(TerritoryIDType pumpTarget, int amountArmies, String reason) { standingCache = null; List <GameOrderAttackTransfer> pumpPath = GetPumpPath(pumpTarget); var endStandings = GetTerritoryStandingsAfterAllMoves(); int stillAvailableDeployment = GameState.CurrentTurn().GetMyIncome() - GetCurrentDeployment(); // check if attempt to pump to owned territory if (pumpPath.Count == 0) { if (amountArmies > 0 && stillAvailableDeployment >= amountArmies) { GameOrderDeploy deployOrder = GameOrderDeploy.Create(GameState.MyPlayerId, amountArmies, pumpTarget, reason); AddDeployOrder(deployOrder); } return(stillAvailableDeployment >= amountArmies); } var armiesAvailableForPump = endStandings[pumpPath[0].From].NumArmies.ArmiesOrZero - endStandings[pumpPath[0].From].ArmiesMarkedAsUsed.ArmiesOrZero - 1; // deploy if we have to if (armiesAvailableForPump < amountArmies) { int missingArmies = amountArmies - armiesAvailableForPump; if (missingArmies > 0 && stillAvailableDeployment >= missingArmies) { GameOrderDeploy deployOrder = GameOrderDeploy.Create(GameState.MyPlayerId, missingArmies, pumpPath[0].From, reason); AddDeployOrder(deployOrder); armiesAvailableForPump += deployOrder.NumArmies; } } int pumpArmies = Math.Max(0, Math.Min(amountArmies, armiesAvailableForPump)); foreach (GameOrderAttackTransfer attackOrder in pumpPath) { attackOrder.NumArmies = new Armies(attackOrder.NumArmies.ArmiesOrZero + pumpArmies); } return(pumpArmies == amountArmies); }
private void PumpBiggestAttack(MultiMoves movesSoFar, GameOrderAttackTransfer biggestAttack, int availableDeployment) { if (availableDeployment == 0) { return; } movesSoFar.AddDeployOrder(GameOrderDeploy.Create(GameState.MyPlayerId, availableDeployment, biggestAttack.From, REASON)); var endAttack = biggestAttack; bool foundStep = true; while (foundStep) { foundStep = false; // probably endless loop possible as soon as we add transfer moves back to attacking territory var nextAttack = movesSoFar.AttackMoves.Where(a => a.From == endAttack.To).FirstOrDefault(); if (nextAttack != null) { endAttack = nextAttack; foundStep = true; } } movesSoFar.PumpArmies(endAttack.To, availableDeployment, REASON); }
private bool TryDeploy(TerritoryIDType terrID, int armies) { Assert.Fatal(Standing.Territories[terrID].OwnerPlayerID == PlayerID); Assert.Fatal(armies > 0); if (!IncomeTracker.TryRecordUsedArmies(terrID, armies)) { return(false); } IEnumerable <GameOrderDeploy> deploys = Orders.OfType <GameOrderDeploy>(); GameOrderDeploy existing = deploys.FirstOrDefault(o => o.DeployOn == terrID); if (existing != null) { existing.NumArmies += armies; } else { AddOrder(GameOrderDeploy.Create(armies, PlayerID, terrID)); } return(true); }
private GameOrder Convert(BotOrderDeploy o) { return(GameOrderDeploy.Create(o.PlayerID, o.Armies, o.Territory.ID, false)); }