コード例 #1
0
        public void AddZeebot(Zeebot zeebot)
        {
            if (z1 == null)
            {
                // First zeebot, assume (0, 0, ?).
                z1 = zeebot;
                Zeebots[zeebot] = new MovingPoint(0, 0, double.NaN);
            }
            else
                if (z2 == null)
                {
                    // Second zeebot, assume (d, 0, ?). Later compute ?.
                    z2 = zeebot;
                    double d = z1.DistanceTo(z2);
                    Zeebots[zeebot] = new MovingPoint(d, 0, double.NaN);
                }
                else
                    if (z3 == null)
                    {
                        // Third zeebot, compute (x, y, ?). After compute all ? facings.
                        z3 = zeebot;
                        double x, y, success;
                        ComputeZ3(out x, out y);
                        // If y = 0, they are colinear, so I'll move it a bit before.
                        if (Util.IsZero(y))
                        {
                            z3.TryMove(1.0, out success);
                            ComputeZ3(out x, out y);
                            // If y = 0, change its facing, then move it again.
                            if (Util.IsZero(y))
                            {
                                z3.ChangeFacing(Math.PI / 2);
                                z3.ChangeFacing(1.0);
                                ComputeZ3(out x, out y);
                            }
                        }

                        Zeebots[zeebot] = new MovingPoint(x, y, double.NaN);

                        // Can now compute all facings: move one zeebot in a direction,
                        // then intersect the 3 circles to find its exact position -> determine facing.
                        ComputeFacing(z3);
                        ComputeFacing(z2);
                        ComputeFacing(z1);
                    }
                    else
                    {
                        // We already have the base in place, now use that to compute this
                        // zeebot's exact coordinates.
                        Point location = ComputeLocation(zeebot);
                        Zeebots[zeebot] = new MovingPoint(location, double.NaN);
                        ComputeFacing(zeebot);

                        // Now we determing the general facing direction (+/-) of the Coordinate System.
                        if (Sign == 0)
                            ComputeFacingDirection(zeebot);
                    }
        }
コード例 #2
0
ファイル: MovingPoint.cs プロジェクト: mihneagiurgea/zfind
 public MovingPoint(MovingPoint toCopy)
 {
     Location = toCopy.Location;
     Facing = toCopy.Facing;
 }
コード例 #3
0
ファイル: MapContext.cs プロジェクト: mihneagiurgea/zfind
 public void AddZeebotAt(IZeebot zeebot, MovingPoint position)
 {
     zeebot.Id = zeebots.Count;
     zeebot.MapContext = this;
     zeebots[zeebot] = position;
 }