예제 #1
0
 public Tuple<int, IEnumerable<Directions>> GetSpellLengthAndPath(Map map, UnitPosition target)
 {
     UpdateMap(map);
     var path = !Parents.ContainsKey(target) ? null
                    : RestoreDirections(target).Reverse();
     return Tuple.Create(0, path); //TODO not zero!
 }
예제 #2
0
 public OracleSuggestion(UnitPosition position, Directions lockingDirection, Map lockedFinalMap, double metrics = 0)
 {
     Position = position;
     LockingDirection = lockingDirection;
     this.LockedFinalMap = lockedFinalMap;
     Metrics = metrics;
 }
예제 #3
0
        public Tuple<int, IEnumerable<Directions>> GetSpellLengthAndPath(Map map, UnitPosition target)
        {
            Tuple<int, IEnumerable<Directions>> best = null;
            int bestCost = -1;

            foreach (var sequence in GenerateSpellsSequences())
            {
                var midPositions = new UnitPosition[sequence.Count];
                var finish = target;
                for (int i = 0; i < sequence.Count; i++)
                    midPositions[i] = finish = GetMidPositionByPhrase(finish, sequence[i], map.Unit.Unit.Period);

                var path = dfsFinder.GetSpellLengthAndPath(map, finish);
                if (path?.Item2 == null)
                    continue;

                var maps = midPositions.Select(p => new Map(map.Id, map.Filled, new PositionedUnit(map.Unit.Unit, p),
                                                            map.NextUnits, map.UsedPositions, map.Scores)).ToArray();
                bool ok = true;
                for (int i = 0; i < sequence.Count && ok; i++)
                    ok &= maps[i].IsGoodPath(sequence[i]);
                if (!ok)
                    continue;

                var result = path.Item2.Concat(((IEnumerable<Directions[]>)sequence).Reverse().SelectMany(s => s)).ToArray();
                if (map.IsGoodPath(result))
                {
                    if (!ChooseCarefully)
                        return Tuple.Create<int, IEnumerable<Directions>>(0, result);
                    var originalPhrase = phrases.ToOriginalPhrase(result.ToPhrase());
                    int cost = phrases.GetPowerScoreWithoutUniqueBonus(originalPhrase);
                    if (cost > bestCost)
                    {
                        bestCost = cost;
                        best = Tuple.Create<int, IEnumerable<Directions>>(0, result);
                    }
                }
            }

            if (best == null)
                best = dfsFinder.GetSpellLengthAndPath(map, target);
            return best;
        }
예제 #4
0
파일: Map.cs 프로젝트: xoposhiy/icfpc2015
 public Map TeleportUnit(UnitPosition position)
 {
     return new Map(Id, Filled, new PositionedUnit(Unit.Unit, position), NextUnits, UsedPositions, Scores);
 }
예제 #5
0
 public static IEnumerable<Directions> GetPath(this IFinder finder, Map map, UnitPosition target)
 {
     return finder.GetSpellLengthAndPath(map, target).Item2;
 }
예제 #6
0
파일: Form.cs 프로젝트: xoposhiy/icfpc2015
 private void Grid_MovementRequested1(UnitPosition obj)
 {
     if (mapHistory.Playing) return;
     var path = mapHistory.Solver.Finder.GetPath(Map,obj);
     if (path == null)
     {
         MessageBox.Show("Сам туда иди!");
         return;
     }
     var program = phrases.ToOriginalPhrase(path.ToPhrase());
     mapHistory.History.Append(program, "Hand");
     mapHistory.Play();
 }
예제 #7
0
 public PositionedUnit WithNewPosition(UnitPosition pos)
 {
     return new PositionedUnit(Unit, pos);
 }
예제 #8
0
 public PositionedUnit(Unit unit, UnitPosition position)
 {
     Unit = unit;
     Position = position;
 }
예제 #9
0
 public PositionedUnit(Unit unit, int rotationIndex, Point pivotLocation)
 {
     Unit = unit;
     Position = new UnitPosition(pivotLocation, (rotationIndex + Unit.Period) % Unit.Period);
 }
예제 #10
0
 private IEnumerable<Directions> RestoreDirections(UnitPosition target)
 {
     while (true)
     {
         var tuple = Parents[target];
         if (tuple == null) yield break;
         yield return tuple.Item2;
         target = tuple.Item1.Unit.Position;
     }
 }
예제 #11
0
 protected bool Equals(UnitPosition other)
 {
     return Point.Equals(other.Point) && Angle == other.Angle;
 }
예제 #12
0
        private static UnitPosition GetMidPositionByPhrase(UnitPosition target, IEnumerable<Directions> directions, int period)
        {
            int x = target.Point.X;
            int y = target.Point.Y;
            int a = target.Angle;

            foreach (var dir in directions.Reverse())
            {
                switch (dir)
                {
                    case Directions.W:
                        x++;
                        break;
                    case Directions.SW:
                        if (y % 2 == 1)
                            x++;
                        y--;
                        break;
                    case Directions.E:
                        x--;
                        break;
                    case Directions.SE:
                        if (y % 2 == 0)
                            x--;
                        y--;
                        break;
                    case Directions.CCW:
                        a = (a + 1) % period;
                        break;
                    case Directions.CW:
                        a = (a - 1 + period) % period;
                        break;
                }
            }
            return new UnitPosition(new Point(x, y), a);
        }