Пример #1
0
 private void turn(DecoratedRobot dr, RobotAction ra)
 {
     RobotTurnAction rta = (RobotTurnAction)ra;
     dr.setHeading(getNewHeading(dr.getHeading(),rta.getDirection()));
 }
Пример #2
0
 private void walk(DecoratedRobot dr)
 {
     Point currentPosition = getRobotBoardCoordinates(dr);
     Point destinationPosition = getRelativeCoordinate(currentPosition, dr.getHeading());
     if (!isPointOnBoard(destinationPosition)) {
         board[currentPosition.X, currentPosition.Y] = null;
         robotIndex.Remove(dr);
         simulatorWindow.log(dr.getName() + " fell off the board!");
     } else if (isPositionEmpty(destinationPosition)) {
         board[currentPosition.X, currentPosition.Y] = null;
         board[destinationPosition.X, destinationPosition.Y] = dr;
     }
 }
Пример #3
0
        private RobotEvent scan(DecoratedRobot dr)
        {
            Point thisRobotsCoordinates = getRobotBoardCoordinates(dr);

            double closestRobotDistance = 999;
            DecoratedRobot closestRobot = null;
            double x = 999;
            foreach (DecoratedRobot r in robotIndex) {
                if (r == dr) continue;
                if (closestRobot == null ||
                    (x = getPointDistance(getRobotBoardCoordinates(r),
                        getRobotBoardCoordinates(dr))) < closestRobotDistance) {
                    closestRobotDistance = x;
                    closestRobot = r;
                }
            }

            return new RobotScanEvent(getSimpleDistance(getRobotBoardCoordinates(dr),
                getRobotBoardCoordinates(closestRobot)));
        }
Пример #4
0
 private void removeRobotFromSimulation(DecoratedRobot dr)
 {
     for(int i=0;i<robotIndex.Count;i++) {
         if (robotIndex[i] == dr) {
             if (i <= currentRobot) {
                 currentRobot--;
             }
         }
     }
     Point p = getRobotBoardCoordinates(dr);
     board[p.X, p.Y] = null;
     robotIndex.Remove(dr);
 }
Пример #5
0
 private RobotLookEvent look(DecoratedRobot dr)
 {
     Point p = getRelativeCoordinate(getRobotBoardCoordinates(dr),dr.getHeading());
     int distance = 1;
     while (isPointOnBoard(p)) {
         SimulationActor sa = board[p.X, p.Y];
         if (sa == null) {
             p = getRelativeCoordinate(p, dr.getHeading());
             distance++;
             continue;
         }
         switch (sa.getType()) {
             case SimulationActor.Type.ROBOT:
                 return new RobotLookEvent(RobotLookEvent.ContactType.ROBOT, distance);
             default:
                 return new RobotLookEvent(RobotLookEvent.ContactType.SOMETHING, distance);
         }
     }
     return new RobotLookEvent(RobotLookEvent.ContactType.EDGE, distance);
 }
Пример #6
0
 private RobotKillEvent kill(DecoratedRobot dr)
 {
     Point p = getRelativeCoordinate(getRobotBoardCoordinates(dr), dr.getHeading());
     SimulationActor target = board[p.X, p.Y];
     if (target != null && (target.getType() == SimulationActor.Type.ROBOT)) {
         DecoratedRobot victim = (DecoratedRobot)target;
         removeRobotFromSimulation(victim);
         simulatorWindow.log(dr.getName() + " killed " + victim.getName());
         return new RobotKillEvent();
     }
     return null;
 }
Пример #7
0
 private Point getRobotBoardCoordinates(DecoratedRobot dr)
 {
     for(int x=0;x<16;x++)
         for (int y = 0; y < 12; y++) {
             if (board[x, y] == dr) return new Point(x,y);
         }
     throw new Exception("specified robot is not on the board");
 }