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! }
public OracleSuggestion(UnitPosition position, Directions lockingDirection, Map lockedFinalMap, double metrics = 0) { Position = position; LockingDirection = lockingDirection; this.LockedFinalMap = lockedFinalMap; Metrics = metrics; }
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; }
public Map TeleportUnit(UnitPosition position) { return new Map(Id, Filled, new PositionedUnit(Unit.Unit, position), NextUnits, UsedPositions, Scores); }
public static IEnumerable<Directions> GetPath(this IFinder finder, Map map, UnitPosition target) { return finder.GetSpellLengthAndPath(map, target).Item2; }
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(); }
public PositionedUnit WithNewPosition(UnitPosition pos) { return new PositionedUnit(Unit, pos); }
public PositionedUnit(Unit unit, UnitPosition position) { Unit = unit; Position = position; }
public PositionedUnit(Unit unit, int rotationIndex, Point pivotLocation) { Unit = unit; Position = new UnitPosition(pivotLocation, (rotationIndex + Unit.Period) % Unit.Period); }
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; } }
protected bool Equals(UnitPosition other) { return Point.Equals(other.Point) && Angle == other.Angle; }
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); }