public void Awake() { GlobalData.Init(2); map = Instantiate(Resources.Load("GameObjects/Map", typeof(Map))) as Map; map.name = "Map"; map.GenerateMap(GlobalData.maxPlayers); cities = GameObject.Find("Cities").GetComponent <Cities>(); cities.SendMessage("GenerateCitiesGroup", GlobalData.maxPlayers); armies = GameObject.Find("Armies").GetComponent <Armies>(); armies.SendMessage("GenerateArmiesGroup", GlobalData.maxPlayers); Province province = map.GetRandomLandProvince(); Province[] provinceNeighbors = province.GetNeighbors(); foreach (Province reg in provinceNeighbors) { reg.Show(); } province.Show(); GameObject.Find("Main Camera").GetComponent <CameraMove> ().TranslateCamera(province.transform.position); }
//Reset the territory public void Reset() { Name = null; Colour = defaultColor; Armies.Clear(); Parent = null; }
public void EvaluateGameState() { // Don't switch from a lost game to an open game if (IsGameCompletelyLost) { return; } var ownArmies = new Armies(0); foreach (var territory in BotState.VisibleMap.GetOwnedTerritories()) { ownArmies = ownArmies.Add(territory.Armies); } var opponents = BotState.Opponents.Where(o => o.State == GamePlayerState.Playing).Select(o => new OpponentInfo(BotState, o)).ToList(); // int opponentIncome = // BotState.getGuessedOpponentIncome(BotState.VisibleMap); if (opponents.Count == 1 && BotState.MyIncome.Total == BotState.Settings.MinimumArmyBonus && opponents[0].Income >= BotState.MyIncome.Total * 2.4 && opponents[0].TotalArmies.NumArmies * 3 > ownArmies.NumArmies) { IsGameCompletelyLost = true; } }
public int ArmiesToTake(Armies defenseArmies) { Assert.Fatal(!defenseArmies.Fogged, "ArmiesToTake called on fog"); var ret = SharedUtility.Round((defenseArmies.DefensePower / Settings.OffenseKillRate) - 0.5); if (ret == SharedUtility.Round(defenseArmies.DefensePower * Settings.DefenseKillRate)) { ret++; } if (Settings.RoundingMode == RoundingModeEnum.WeightedRandom && (!UseRandomness || RandomUtility.RandomNumber(3) != 0)) { ret++; } if (Settings.LuckModifier > 0) { //Add up some armies to account for luck var factor = UseRandomness ? RandomUtility.BellRandom(2.5, 17.5) : 10.0; ret += SharedUtility.Round(Settings.LuckModifier / factor * ret); } return(ret); }
internal void CopyArmy() { PlanArmy army = SelectedArmy.PlanArmy; army.PlanUnits.Clear(); var armyItems = new List <PlanUnit>(); foreach (PlanUnitViewModel armyItemVM in SelectedArmy.PlanUnits) { PlanUnit armyItem = armyItemVM.PlanUnit; armyItem.Options = armyItemVM.Options.Select(option => option.Option).ToList(); army.PlanUnits.Add(armyItemVM.PlanUnit); } var copiedArmy = new PlanArmyViewModel() { PlanArmy = StaticHelper.DeepClone(army) }; Armies.Add(copiedArmy); SelectedArmy = copiedArmy; }
public static Moves CalculateBreakTerritoryTask(BotMain state, BotTerritory opponentTerritory, int maxDeployment, BotTerritory.DeploymentType conservativeLevel) { var outvar = new Moves(); var opponentArmies = opponentTerritory.GetArmiesAfterDeploymentAndIncomingAttacks(conservativeLevel); var neededAttackArmies = opponentTerritory.getNeededBreakArmies(opponentArmies.DefensePower); var ownedNeighbors = opponentTerritory.GetOwnedNeighbors(); var presortedOwnedNeighbors = state.TerritoryValueCalculator.SortDefenseValue(ownedNeighbors); var sortedOwnedNeighbors = BotMap.GetOrderedListOfTerritoriesByIdleArmies(presortedOwnedNeighbors); var territoryToUse = sortedOwnedNeighbors[0]; var idleArmies = territoryToUse.GetIdleArmies(); var neededDeployment = Math.Max(0, neededAttackArmies - idleArmies.AttackPower); if (neededDeployment > maxDeployment) { return(null); } if (neededDeployment > 0) { outvar.AddOrder(new BotOrderDeploy(state.Me.ID, territoryToUse, neededDeployment)); } Armies attackArmies = new Armies(neededAttackArmies); //var atm = new BotOrderAttackTransfer(state.Me.ID, territoryToUse, opponentTerritory, idleArmies.Add(new Armies(neededDeployment)), "OneHitBreakTerritoryTask"); var atm = new BotOrderAttackTransfer(state.Me.ID, territoryToUse, opponentTerritory, attackArmies, "OneHitBreakTerritoryTask"); outvar.AddOrder(atm); return(outvar); }
public string Source; //just for debugging, never used for logic decisions public BotOrderAttackTransfer(PlayerIDType playerID, BotTerritory from, BotTerritory to, Armies armies, string source) { this.PlayerID = playerID; this.From = from; this.To = to; this.Armies = armies; this.Source = source; }
public BotTerritory(BotMap parent, TerritoryIDType id, PlayerIDType playerID, Armies armies) { this.Parent = parent; this.ID = id; this.OwnerPlayerID = playerID; this.Armies = armies; }
public override void Initialize() { drag = false; // Set grid values gridWidth = Globals.GRID_WIDTH; gridHeight = 3; gridLocation = new Point(Globals.GridLocation.X, Globals.GridLocation.Y + Globals.TILE_HEIGHT * 5); // Set sprites/textures background = ArtAssets.backgroundGrassLevel; // UI statsUI = new StatsUI(); Globals.statsUI = statsUI; Globals.statsUI.Diamonds = Globals.diamonds; armyShowCase = ArtAssets.ArmyShowCase; armyShowCase.position = ArmyShowCasePosition; // Set buttons buttons.Add(new Button(ArtAssets.StartButton, StartButtonPosition)); buttons[0].ClickEvent += Ready; buttons.Add(new Button(ArtAssets.HomeButton, HomeButtonPosition)); buttons[1].ClickEvent += Quit; Armies.army = new List <Character>(); Armies.army.Add(Armies.GetCharacter(Character.Rank.Leader).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.General).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.General).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.Captain).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.Captain).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.Soldier).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.Soldier).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.Miner).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.Bomb).Clone()); Armies.army.Add(Armies.GetCharacter(Character.Rank.Bomb).Clone()); Armies.army[0].position = Grid.ToPixelLocation(new Point(0, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[1].position = Grid.ToPixelLocation(new Point(1, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[2].position = Grid.ToPixelLocation(new Point(2, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[3].position = Grid.ToPixelLocation(new Point(3, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[4].position = Grid.ToPixelLocation(new Point(4, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[5].position = Grid.ToPixelLocation(new Point(5, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[6].position = Grid.ToPixelLocation(new Point(6, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[7].position = Grid.ToPixelLocation(new Point(7, 0), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[8].position = Grid.ToPixelLocation(new Point(0, 1), gridLocation, Globals.TileDimensions).ToVector2(); Armies.army[9].position = Grid.ToPixelLocation(new Point(1, 1), gridLocation, Globals.TileDimensions).ToVector2(); SelectCharacter(Armies.army[0]); armyName = ArtAssets.ArmyNames; armyName.position = RankNamePosition; SetArmyDictionary(Character.Army.Normal); }
public Armies GetSurroundingIdleArmies() { var idleArmies = new Armies(0); foreach (var neighbor in this.GetOwnedNeighbors()) { idleArmies = idleArmies.Add(neighbor.GetIdleArmies()); } return(idleArmies); }
private void ChangeCharacter(Character.Rank rank) { Vector2 position = selectedCharacter.position; int index = Armies.army.IndexOf(selectedCharacter); Armies.army[index] = Armies.GetCharacter(rank, currentArmy); Armies.army[index].position = position; SelectCharacter(Armies.army[index]); }
private async void InitiliseMainPage() { IEnumerable <PlanArmy> armies = await _armyProvider.GetArmies(); foreach (PlanArmy army in armies) { Armies.Add(new PlanArmyViewModel { PlanArmy = army }); } }
public void CreateNewArmy() { var newArmy = new PlanArmyViewModel() { PlanArmy = new PlanArmy() }; Armies.Add(newArmy); SelectedArmy = newArmy; }
public Armies GetIncomingArmies() { var incomingArmies = new Armies(0); foreach (var atm in this.IncomingMoves) { incomingArmies = incomingArmies.Add(atm.Armies); } return(incomingArmies); }
public IResponse AddArmy(Army army) { if (Started) { return(new ErrorResponse("Battle already started")); } Armies.Add(army); return(new SuccessResponse()); }
private static Armies CalculateOpponentAttackingArmies(BotTerritory territory, Moves opponentAttacks) { var attackingArmies = new Armies(0); foreach (var atm in opponentAttacks.Orders.OfType <BotOrderAttackTransfer>()) { if (atm.To.ID == territory.ID) { attackingArmies = attackingArmies.Add(atm.Armies); } } return(attackingArmies); }
public OpponentInfo(BotMain state, GamePlayer opponent) { this.Territories = state.VisibleMap.OpponentTerritories(opponent.ID); var opponentArmies = new Armies(0); foreach (var territory in Territories) { opponentArmies = opponentArmies.Add(territory.Armies); } TotalArmies = opponentArmies; this.Income = state.HistoryTracker.OpponentDeployment(opponent.ID); }
public void AddArmyFromBorderBattle(VisualArmy armyPrefab, Army army) { Armies.Add(army); SupportOnly = Armies.All(x => x.Type == ArmyType.Support); if (!Territories.Contains(army.TargetTerritory)) { Territories.Add(army.TargetTerritory); } if (!Players.Contains(army.SourcePlayer)) { Players.Add(army.SourcePlayer); } if (!Players.Contains(army.TargetPlayer)) { Players.Add(army.TargetPlayer); } // Visual List <Vector2> walkPath = new List <Vector2>(); if (army.IsWaterArmy) { WaterConnection wc = army.SourceTerritory.Region.GetWaterConnectionTo(army.TargetTerritory.Region); System.Tuple <Vector2, float> center = new System.Tuple <Vector2, float>(wc.Center, wc.FromRegion == army.SourceTerritory.Region ? wc.Angle - 90 : wc.Angle + 90); Vector2 borderCenter = center.Item1; float targetAngle = center.Item2 + 180; float approachDistance = wc.Length / 2f; float xTarget = Mathf.Sin(Mathf.Deg2Rad * targetAngle) * approachDistance; float yTarget = Mathf.Cos(Mathf.Deg2Rad * targetAngle) * approachDistance; Vector2 coastPos = borderCenter + new Vector2(xTarget, yTarget); walkPath.Add(borderCenter); walkPath.Add(coastPos); } else { System.Tuple <Vector2, float> center = army.SourceTerritory.Region.GetBorderCenterPositionTo(army.TargetTerritory.Region); Vector2 borderCenter = center.Item1; walkPath.Add(borderCenter); } Vector2 targetPos = army.TargetTerritory.Region.CenterPoi; walkPath.Add(targetPos); VisualArmy visualArmy = GameObject.Instantiate(armyPrefab); visualArmy.Init(army, walkPath, ParriskGame.ArmyApproachTime); }
public override void Initialize() { Node.size = Globals.TILE_WIDTH; Globals.diamonds = 0; Globals.soundManager = new SoundManager(); ArtAssets.LoadTextures(); ArtAssets.LoadFont(Globals.contentManager); AudioAssets.Load(Globals.contentManager); AnimationAssets.LoadAnimations(Globals.graphicsDevice, Globals.contentManager); Armies.SetUpCharacters(); StateManager.ChangeState(Settings.STATES.MainMenu); }
/// <summary>For opponent territories.</summary> public Armies GetArmiesAfterDeploymentAndIncomingAttacks(DeploymentType type) { var remainingArmies = this.GetArmiesAfterDeployment(type); foreach (var atm in IncomingMoves) { //remainingArmies = remainingArmies.Subtract(new Armies(SharedUtility.Round(atm.Armies.NumArmies * BotState.Settings.OffensiveKillRate))); remainingArmies = remainingArmies.Subtract(new Armies(getOwnKills(atm.Armies.NumArmies, remainingArmies.DefensePower))); } if (!remainingArmies.Fogged && remainingArmies.NumArmies < 1) { remainingArmies = new Armies(1, remainingArmies.SpecialUnits); } return(remainingArmies); }
private void PrintFightField() { Armies.ForEach(army => Console.WriteLine(army)); }
public override void ResolveBattle() { // Calculate amount of troops for each player Dictionary <Player, int> remainingTroops = new Dictionary <Player, int>(); foreach (Army army in Armies) { if (!remainingTroops.ContainsKey(army.SourcePlayer)) { remainingTroops.Add(army.SourcePlayer, army.NumTroops); } else { remainingTroops[army.SourcePlayer] += army.NumTroops; } } List <Player> remainingPlayers = remainingTroops.Where(x => x.Value > 0).Select(x => x.Key).ToList(); // Calculate strength of each player (weighted average of all armies of that player) Dictionary <Player, float> playerStrength = new Dictionary <Player, float>(); foreach (Player p in remainingPlayers) { Casualties.Add(p, 0); List <Army> playerArmies = Armies.Where(x => x.SourcePlayer == p).ToList(); int totalTroops = remainingTroops[p]; float totalStrength = 0; foreach (Army army in playerArmies) { totalStrength += (army.NumTroops * army.Strength); } float strength = totalStrength / totalTroops; playerStrength.Add(p, strength); //Debug.Log("Player " + p.Name + " Strength: " + strength); } // Fight until only one player has armies left while (remainingPlayers.Count > 1) { float totalStrength = 0f; foreach (Player p in remainingPlayers) { totalStrength += playerStrength[p]; } float rng = Random.Range(0, totalStrength); float tmp = 0f; int c = 0; Player winner = null; while (winner == null) { tmp += playerStrength[remainingPlayers[c]]; if (tmp >= rng) { winner = remainingPlayers[c]; } c++; } foreach (Player p in remainingPlayers) { if (p != winner) { remainingTroops[p]--; Casualties[p]++; } } remainingPlayers = remainingTroops.Where(x => x.Value > 0).Select(x => x.Key).ToList(); } // Set post-battle values Winner = remainingPlayers[0]; Losers = Players.Where(x => x != Winner).ToList(); WinnerSourceTerritory = Armies.First(x => x.SourcePlayer == Winner).SourceTerritory; WinnerTargetTerritory = Armies.First(x => x.SourcePlayer == Winner).TargetTerritory; WinnerTroopsRemaining = remainingTroops[Winner]; }
levelDesign = LevelDesignReturn(Armies, situations, 150);