private void turn(DecoratedRobot dr, RobotAction ra) { RobotTurnAction rta = (RobotTurnAction)ra; dr.setHeading(getNewHeading(dr.getHeading(),rta.getDirection())); }
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; } }
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))); }
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); }
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); }
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; }
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"); }