// Walk takes an arbitrary value and an interface and traverses the // value, calling callbacks on the interface if they are supported. // The interface should implement one or more of the walker interfaces // in this package, such as PrimitiveWalker, StructWalker, etc. //~ func Walk(data, walker interface{}) (err error) { public static void Walk(object data, IWalker walker) { //~ v := reflect.ValueOf(data) //~ ew, ok := walker.(EnterExitWalker) //~ if ok { //~ err = ew.Enter(WalkLoc) //~ } var v = data; var ew = walker as IEnterExitWalker; if (ew != null) { ew.Enter(Location.WalkLoc); } //~ if err == nil { //~ err = walk(v, walker) //~ } WalkInternal(ref v, walker); //~ if ok && err == nil { //~ err = ew.Exit(WalkLoc) //~ } if (ew != null) { ew.Exit(Location.WalkLoc); } //~ return }
IWalker GetNewTarget(IZombiePlayer player, List <IWalker> humans) { if (ThinkOutLoud) { Console.WriteLine("Choosing new target. Humans are:"); } foreach (IWalker h in humans) { if (ThinkOutLoud) { Console.WriteLine(" - {0}", h); } } IWalker closest = null; foreach (IWalker h in humans) { if (closest == null || player.DistanceFrom(h) < player.DistanceFrom(closest)) { closest = h; } } if (ThinkOutLoud) { Console.WriteLine("Chosen: {0}", closest); } return(closest); }
/// <summary> /// Returns the distance after which a walker's path, at the current heading, would probably collide with the specified item. /// </summary> /// <returns>A positive distance at which a collision would occur, OR a negative number when no collision would occur.</returns> internal static double CollisionDistance(this IWalker a, ITakeSpace b, double proposedDistanceForward) { if (proposedDistanceForward < 0) { throw new ArgumentException("proposedDistanceForward can't be negative.", "proposedDistanceForward"); } // if the player goes forward here, would they intersect? double distTraveled = 0.0; var h = a.Heading.ToRadians(); double distPerStep = Math.Max(0.05, (Math.Min(WorldConstants.HumanSpeed, WorldConstants.ZombieSpeed) / WorldConstants.StepsPerTurn)); var distXPerStep = distPerStep * Math.Sin(h); var distYPerStep = -distPerStep *Math.Cos(h); var curX = a.Position.X; var curY = a.Position.Y; while (distTraveled < proposedDistanceForward) { if (Intersects(curX, curY, a.Radius, b.Position.X, b.Position.Y, b.Radius)) { return(distTraveled); } distTraveled += distPerStep; curX += distXPerStep; curY += distYPerStep; } return(-1); }
public Walker(IWalker objectToWalk, float speed) { this.objectToWalk = objectToWalk; this.speed = speed; walkerStatus = WalkerStatus.CollectingBlocks; }
public bool Act(IContext context) { IWalker walker = (IWalker)context.GetVariable("IWalker"); walker.MoveUp(walker.GetWalkerSpeed()); return(true); }
/// <summary> /// 开始寻路;若无法找到目标点则返回异常; /// </summary> public WayPath <T> Search(IWalker <T> map, IRange <T> searchRange, T starting, T destination) { if (map == null) { throw new ArgumentNullException("map"); } if (searchRange == null) { throw new ArgumentNullException("searchRange"); } Walker = map; SearchRange = searchRange; Starting = starting; Destination = destination; if (starting.Equals(destination)) { throw new ArgumentException("起点与终点为同一个位置;"); } if (SearchRange.IsOutRange(Destination)) { throw new DestinationNotFoundException("目的地超出了最大搜索范围的定义;"); } if (IsTrapped(Starting)) { throw new TrappedException("起点周围不可行走,物体可能被困住;"); } if (IsTrapped(Destination)) { throw new TrappedException("目的地本身或周围不可行走;"); } return(Search()); }
/// /// <summary> * walk the tree starting at e. /// * </summary> /// * <param name="e"> the root element to walk </param> /// * <returns> n the number of traversed elements </returns> /// public virtual int walk(KElement e) { if (e == null) { return(0); } int n = 0; IWalker w = theFactory.getWalker(e); bool b = true; if (w != null) { n++; b = w.walk(e); } if (b) // follow kids if still alive { VElement v = e.getChildElementVector_KElement(null, null, null, true, -1); // do // not // follow // refelements int size = v.Count; for (int i = 0; i < size; i++) { KElement e2 = v[i]; n += walk(e2); } } return(n); }
public bool Act(IContext context) { IWalker walker = (IWalker)context.GetVariable("IWalker"); IFollower follower = (IFollower)context.GetVariable("IFollower"); FacingDirection facingDirection = walker.GetFacingDirection(); float maxWalkingSpeed = walker.GetWalkerSpeed(); //= (float)context.GetVariable("maxWalkingSpeed"); Vector2 myPosition = walker.GetWalkerTransform().position; Vector2 direction = follower.GetCurrentWaypoint().GetWaypointPosition() - myPosition; direction.Normalize(); if (direction.x > 0) { if (facingDirection == FacingDirection.LEFT) { walker.ChangeDirection(FacingDirection.RIGHT); } walker.MoveRight(maxWalkingSpeed); } else if (direction.x < 0) { if (facingDirection == FacingDirection.RIGHT) { walker.ChangeDirection(FacingDirection.LEFT); } walker.MoveLeft(maxWalkingSpeed); } return(true); }
public bool Act(IContext context) { IWalker walker = ((IWalker)context.GetVariable("IWalker")); walker.FallDown(); return(true); }
private static void WriteIndent(this IWalker walker) { walker.Builder.AppendLine(); if (walker.Level > 0 && walker.Indent > 0) { walker.Builder.Append(' '.Repeat(walker.Indent * walker.Level)); } }
private void dfs(State currentState, String path, IWalker walker) { walker.meet(path, currentState); for (Character transition : currentState.getTransitions()) { State targetState = currentState.nextState(transition); dfs(targetState, path + transition, walker); } }
private void LvAnimals_MouseDoubleClick(object sender, MouseButtonEventArgs e) { IWalker selectedAnimal = lvAnimals.SelectedItem as IWalker; if (selectedAnimal != null) { selectedAnimal.walk(); } }
/// <summary> /// Gives the smallest angle that the walker must turn in order to have a particular heading. /// </summary> public static double AngleToHeading(this IWalker a, double heading) { var desired = (90.0 - heading.PositiveAngle()).ToRadians(); // relative to the x-axis double curHeading = (90.0 - a.Heading).ToRadians(); // relative to the x-axis Vector vHeading = new Vector(-Math.Cos(curHeading), Math.Sin(curHeading)); Vector vTarget = new Vector(-Math.Cos(desired), Math.Sin(desired)); return(Vector.AngleBetween(vHeading, vTarget).MinimumAngle()); }
/// <summary>Calculates how many degrees a zombie/human should turn to avoid a particular thing</summary> public static double AngleAvoiding(this IWalker a, ITakeSpace b) { var angleTo = a.AngleTo(b); if (Math.Abs(angleTo + 90.0) > Math.Abs(angleTo - 90.0)) { return((angleTo - 90.0).MinimumAngle()); } return((angleTo + 90.0).MinimumAngle()); }
private static void WalkProgramCode(IWalker walker, string programCode) { var lexer = new Lexer(programCode); var tokens = lexer.ReadTokens(); var parser = new Parser(tokens); var program = parser.Parse(); program.Accept(walker); }
public bool Reached(IWalker walker) { float distance = Vector2.Distance(walker.GetWalkerPosition(), m_Transform.position); if (distance <= m_WaypointReachedRadius) { return(true); } return(false); }
/// <summary>Calculates how many degrees a zombie/human should turn to face away from a particular thing</summary> public static double AngleAwayFrom(this IWalker a, ITakeSpace b) { var angleTo = a.AngleTo(b); if (angleTo + 180.0 >= 180.0) { return((180.0 - angleTo).MinimumAngle()); } return((angleTo + 180.0).MinimumAngle()); }
public bool Act(IContext context) { IWalker walker = ((IWalker)context.GetVariable("IWalker")); FacingDirection facingDirection = walker.GetFacingDirection(); if (facingDirection == FacingDirection.LEFT) { walker.ChangeDirection(FacingDirection.RIGHT); } walker.MoveRight(walker.GetWalkerSpeed()); return(true); }
/// <summary> /// Returns the angle to turn to face particular coordinates. /// </summary> public static double AngleToCoordinates(this IWalker a, double x, double y) { double distToTarget = a.DistanceFrom(x, y); double curHeading = (90.0 - a.Heading).ToRadians(); // relative to the x-axis double xC = a.Position.X + distToTarget * Math.Cos(curHeading); double yC = a.Position.Y + -distToTarget *Math.Sin(curHeading); // let the built-in vector math sort it all out :-). Vector vHeading = new Vector(a.Position.X - xC, a.Position.Y - yC); Vector vTarget = new Vector(a.Position.X - x, a.Position.Y - y); return(Vector.AngleBetween(vHeading, vTarget).MinimumAngle()); }
public void MoveToTargetTile(IWalker walker, Vector2 myTargetPos) { Tile currentTile = RoomManager.instance.myRoom.MyGrid.GetTileAt((int)walker.speakerPos.x, (int)walker.speakerPos.y); if (currentTile.myCharacter == walker) { currentTile.myCharacter = null; } walker.walkerTargetPos = myTargetPos; StartCoroutine(MoveCoroutine(walker)); }
// Singleton // // ---- MOVE CHARACTER ---- // public void MoveByPath(IWalker walker, List <Vector2> posList) { Queue <Vector2> path = new Queue <Vector2> (); foreach (Vector2 pos in posList) { path.Enqueue(pos); } walker.walkerPath = path; walker.walkerTargetPos = walker.walkerPath.Dequeue(); MoveToTargetTile(walker, walker.walkerTargetPos); }
//~ func walkPrimitive(v reflect.Value, w interface{}) error { private static void WalkPrimitive(ref object v, IWalker w) { //~ if pw, ok := w.(PrimitiveWalker); ok { //~ return pw.Primitive(v) //~ } var pw = w as IPrimitiveWalker; if (pw != null) { pw.Primitive(ref v); } //~ return nil }
public Traveler(string currentZoneName, World world, IWalker walker) { Walker = walker; Walker.IsStuck += WalkerOnIsStuck; Walker.PropertyChanged += WalkerOnPropertyChanged; World = world; CurrentZone = world.GetZoneByName(currentZoneName); // Position = walker.CurrentPosition; CurrentZone.Map.AddKnownNode(walker.CurrentPosition); PathMaker = new GridPathMaker { ZoneMap = CurrentZone.Map }; }
public override object Accept(IWalker walker) { if (InterpretationContext.Instance != null) InterpretationContext.Instance.CurrentLocation = Token.Location; try { return walker.Walk(this); } catch (Exception e) { if (e is ParseException || e is BikeObject || e is ControlFlow) throw; // throw; throw ErrorFactory.CreateClrError(e); } }
public override object Accept(IWalker walker) { if (InterpretationContext.Instance != null) { InterpretationContext.Instance.CurrentLocation = Token.Location; } try { return(walker.Walk(this)); } catch (Exception e) { if (e is ParseException || e is BikeObject || e is ControlFlow) { throw; } // throw; throw ErrorFactory.CreateClrError(e); } }
/// <summary>Calculates how many degrees a zombie/human should turn to face a particular thing</summary> /// <returns>The angle to turn. A negative number means a left turn, a positive number means a right turn.</returns> public static double AngleTo(this IWalker a, ITakeSpace b) { /* * Thanks to Chris for inspiring me to fix this; my version didn't work, and his version didn't work either. * (Atleast for what Yusuf was wanting them to do. XD ) * * GreedyHuman fails on the Plentiful map with either implementation. * On the other hand, this version works well, gives left-or-right turns, and it's short & clean too. */ double distToTarget = a.DistanceFrom(b); double curHeading = (90.0 - a.Heading).ToRadians(); // relative to the x-axis // the heading intersects a circle with radius /distAB/ at some point, call it C. Find that point of intersection. // x = xA + r cos (heading) // y = yA + r sin (heading) double xC = a.Position.X + distToTarget * Math.Cos(curHeading); double yC = a.Position.Y + -distToTarget *Math.Sin(curHeading); // let the built-in vector math sort it all out :-). Vector vHeading = new Vector(a.Position.X - xC, a.Position.Y - yC); Vector vTarget = new Vector(a.Position.X - b.Position.X, a.Position.Y - b.Position.Y); return(Vector.AngleBetween(vHeading, vTarget).MinimumAngle()); }
public void WalkFaster(IWalker walker) { walker.State = new RunningWalkState(); Console.WriteLine("Бежим"); }
public void WalkSlower(IWalker walker) { walker.State = new SlowWalkState(); Console.WriteLine("Замедляемся к минимальной скорости"); }
public abstract object Accept(IWalker walker);
/// <summary> /// 开始寻路;若无法找到目标点则返回异常; /// </summary> public WayPath <T> Search(IWalker <T> map, T starting, T destination) { return(Search(map, UnlimitedRange <T> .Instance, starting, destination)); }
public static void PrintSwim(IWalker walk) { walk.Walk(); }
public void SetUp() { mockWalker = new Mock<IWalker>(); walker = mockWalker.Object; }
public void Accept(IWalker walker) { walker.Walk(this); }
public PathResolver(IWalker walker) { _walker = walker; }
/// <summary> /// Walks the given files recursively to obtain the full tree. /// This triggers List requests against Google Drive. /// </summary> /// <param name="walker"></param> /// <param name="files"></param> /// <returns></returns> private static IFileNode[] Walk(IWalker walker, IFile[] files) { return files.Select(f => walker.ListRecurse(f)).ToArray(); }
public FileBackupService(IWalker walker, IDownloader downloader, IFileSystem fileSystem) { _walker = walker; _downloader = downloader; _fileSystem = fileSystem; }