コード例 #1
0
ファイル: BasicDFS.cs プロジェクト: SamirBanna/cs266-simcon
        /// <summary>
        /// This <code>clone</code> method is only used by the DFS algorithm and therefore includes some specifics!!!!
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Robot clone(int id)
        {
            //this is for adding the robot to the control loop
             Coordinates coord = ((DFSSensor)this.robot.Sensors["DFSSensor"]).getDoor();
             double orientation = 90;
             //size of robot is 5,5

             Robot newRobot = new Robot(id,"", coord, orientation,5,5);
             newRobot.CurrentAlgorithm = new BasicDFS(newRobot,false, moveRandom);
             newRobot.Sensors = new Dictionary<string, InputSensor>();
             foreach (String s in this.robot.Sensors.Keys){
                 InputSensor sens = SensorList.makeSensor(s);
                 sens.robot = newRobot;
                 newRobot.Sensors.Add(s, sens);
             }
             //assign attributes to the newly created robot
             ((BasicDFS)newRobot.CurrentAlgorithm).isTail = true;
             ((BasicDFS)newRobot.CurrentAlgorithm).pred = this.robot;
             ((BasicDFS)newRobot.CurrentAlgorithm).succ = null;

             //change attributes of second to last robot (this robot)
             succ = newRobot;
             isTail = false;

             return newRobot;
        }
コード例 #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="r"></param>
 /// <param name="degInterval">Interval at which to randomize angles. E.g. if 30, rand would only give 0, 30, 60, 90, ..., 360</param>
 /// <param name="probTurn">Probability of turning when agent isn't moving</param>
 /// <param name="moveDistance">Distance to move forward if moving</param>
 public NodeCounting(Robot r, int degInterval, double probTurn, double moveDistance)
     : base(r)
 {
     this.degInterval = degInterval;
     this.probTurn = probTurn;
     this.moveDistance = moveDistance;
 }
コード例 #3
0
ファイル: BasicDFS.cs プロジェクト: SamirBanna/cs266-simcon
 //public BasicDFS(Robot r)
 //    : base(r)
 //{
 //}
 /// <summary>
 /// The moveDistance that is passed in should be the length of one grid cell edge
 /// the very first robot created must be a leader
 /// </summary>
 /// <param name="r"></param>
 /// <param name="isLeader"></param>
 /// <param name="moveRandom"></param>
 public BasicDFS(Robot r, bool isLeader, bool moveRandom)
     : base(r)
 {
     this.isLeader = isLeader;
     this.moveRandom = moveRandom;
     this.isActive = true;
     this.isTurnPhase = true;
     this.isTail = true;
     rand = new Random();
 }
コード例 #4
0
 public NodeCounting(Robot r)
     : base(r)
 {
 }
コード例 #5
0
ファイル: Grid.cs プロジェクト: SamirBanna/cs266-simcon
        // Turn on continuous marking
        public void TurnOnContinuousMarking(Robot robot)
        {
            // Make a copy of the location
            Coordinates locCopy = new Coordinates(robot.Location.X, robot.Location.Y);

            // Get location of robot and store in prevLocations
            prevLocations.Add(robot, locCopy);
        }
コード例 #6
0
ファイル: Grid.cs プロジェクト: SamirBanna/cs266-simcon
 // Turn off continuous marking, take robot off of prevLocations list
 public void TurnOffContinuousMarking(Robot robot)
 {
     prevLocations.Remove(robot);
 }
コード例 #7
0
ファイル: Grid.cs プロジェクト: SamirBanna/cs266-simcon
        public void GridUpdate(Robot robot)
        {
            // Console.WriteLine(robot.Id);

            Console.WriteLine("ROBOT's X in gridupdate : " + robot.Location.X);
            Console.WriteLine("ROBOT's Y in gridupdate : " + robot.Location.Y);
            // Take out robot from locations of where robot is in the grid

            CellData location = findObj(robot);
            if (location != null)
            {
                location.objectsInSquare.Remove(robot);
            }

            // Add robot
            getGridLoc(robot.Location).objectsInSquare.Add(robot);

            Coordinates newLoc = new Coordinates(robot.Location.X, robot.Location.Y);

            CellData finalSpot = getGridLoc(newLoc);

            // Update prevLocationsForMark so that they're synchronized. This assume that Mark is called AFTER GridUpdate
            foreach (Robot r in prevLocations.Keys)
            {
                prevLocationsForMark[r] = new Coordinates(prevLocations[r].X, prevLocations[r].Y);
            }

            if(!prevLocations.ContainsKey(robot)){
                prevLocations[robot] = newLoc;
                finalSpot.numTimesVisited++;
                 return;
            }

            Coordinates prevLoc = new Coordinates(prevLocations[robot].X, prevLocations[robot].Y);
            Coordinates curLoc = new Coordinates(prevLocations[robot].X, prevLocations[robot].Y);

            CellData curSpot = getGridLoc(curLoc);
            CellData startSpot = getGridLoc(curLoc);

            if(finalSpot.row == curSpot.row && finalSpot.col == curSpot.col){
                // don't mark anything
                return;
            }

             double incr = (double)Math.Min((WorldHeight / NumSquaresY), (WorldWidth / NumSquaresX)) / 5.0;
                double dX = robot.Location.X - prevLocations[robot].X;
                double dY = robot.Location.Y - prevLocations[robot].Y;
                double incrX = incr * dX / (double)Math.Sqrt(dX * dX + dY * dY);
                double incrY = incr * dY / (double)Math.Sqrt(dX * dX + dY * dY);

              //  Console.WriteLine("Prev location is " + curLoc.X + ", " + curLoc.Y + " trying to reach " + newLoc.X + ", " + newLoc.Y);
                do
                {
                    CellData nextSpot;
                    // Increment X and Y
                    curLoc.X += incrX;
                    curLoc.Y += incrY;

                    // Get next grid spot
                    nextSpot = getGridLoc(curLoc);
                 //   Console.WriteLine("Current spot: " + nextSpot.col + " " + nextSpot.row);

                    // If different mark it
                    if (nextSpot != curSpot)
                    {
                        nextSpot.numTimesVisited++;
                        curSpot = nextSpot;
                    }
                    //if (!inBounds(curSpot, startSpot, finalSpot))
                    //{
                    //    break;
                    //}
                    //} while (curSpot != finalSpot);
                } while (curSpot.row != finalSpot.row || curSpot.col != finalSpot.col);
                prevLocations[robot] = curLoc;
                return;
        }
コード例 #8
0
 public NewRobotException(Robot newRobot)
 {
     this.robot = newRobot;
 }