Example #1
0
 public MapState Clone()
 {
     MapState ms = new MapState();
     foreach (var ps in PlayerStarts)
         ms.PlayerStarts.Add(ps.Clone());
     return ms;
 }
 public void FindFairStartingLocations(Map map, BalanceCheckerSettings settings, List<int> fixedStarts, int minimumCapitalDistance)
 {
     _MinimumDistanceBetweenCapitals = minimumCapitalDistance;
     _FixedStarts = fixedStarts;
     _Map = (Map)map.Clone();
     _balanceCheckerSettings = settings;
     _States = new PrioQueue<MapState, double>();
     _States.Enqueue(MapState.FromMap(map), 0);
     TopResult = null;
     _FairnessDict = new Dictionary<string, double>();
     Start();
 }
Example #3
0
 public static MapState FromMap(Map map)
 {
     MapState ms = new MapState();
     foreach(Tile t in map.GetAllTiles())
         foreach (Unit u in t.Units)
             if (u.UnitOwner != Game.BarbarianPlayerId)
             {
                 while (ms.PlayerStarts.Count <= u.UnitOwner)
                     ms.PlayerStarts.Add(new PlayerStart() { PlayerId = ms.PlayerStarts.Count });
                 ms.PlayerStarts[u.UnitOwner].StartX = t.X;
                 ms.PlayerStarts[u.UnitOwner].StartY = t.Y;
             }
     return ms;
 }
 private void Solve()
 {
     _IsRunning = true;
     while (!_Stop && !_States.IsEmpty())
     {
         MapState ms = _States.Dequeue();
         string key = ms.ToString();
         if (_FairnessDict.ContainsKey(key) && !double.IsNaN(_FairnessDict[key])) continue; // State already visited
         BalanceReport br = BalanceChecker.CheckBalance(_Map, _balanceCheckerSettings, ms);
         _FairnessDict[key] = br.Unfairness;
         if (br.Unfairness < _TopResultUnfairness)
         {
             _TopResultUnfairness = br.Unfairness;
             TopResult = ms;
         }
         foreach (MapState n in ms.GetNeighbouringStates(_Map, _FixedStarts, _MinimumDistanceBetweenCapitals))
         {
             string k = n.ToString();
             if (!_FairnessDict.ContainsKey(k))
             {
                 _States.Enqueue(n, br.Unfairness); //100000.0 / br.Unfairness);
                 _FairnessDict[k] = double.NaN;
             }
         }
         if (DateTime.Now - _LastProgressTime > ProgressFrequency)
         {
             if(Progress != null) Progress(this, EventArgs.Empty);
             _LastProgressTime = DateTime.Now;
         }
     }
     if(_StoppedSignal != null)
         _StoppedSignal.Release();
     _StoppedSignal = null;
     _IsRunning = false;
 }