public MyRentController() {
   Car car = new Car();
   car.setPlateNumber("11AA22");
   car.setRented(false);
   cars.add(car);
   car = new Car();
   car.setPlateNumber("22BB33");
   car.setRented(false);
   cars.add(car);
 }
 /**
  * Rent a car.
  *
  * @param plateNumber
  * @return car specifications
  * @throws Exception no car with this plate number or already rented
  */
 @RequestMapping(value = "/car/{plateNumber}", method = RequestMethod.DELETE)
 @ResponseStatus(HttpStatus.OK)
 @Override
 public void rentCar(@PathVariable("plateNumber") String plateNumber) throws Exception {
   List<CarDTO> dtos = new ArrayList<CarDTO>();
   Car car;
   for (int i = 0; i < cars.size(); i++) { // parcours BDD
     car = cars.get(i); // extrait ième voiture
     if (car.getPlateNumber().equals(plateNumber)) {
       car.setRented(true);
     }
   }
 }
 /** @return all cars not rented */
 @RequestMapping(value = "/car", method = RequestMethod.GET)
 @ResponseStatus(HttpStatus.OK)
 @ResponseBody
 @Override
 public List<CarDTO> getCars() {
   List<CarDTO> dtos = new ArrayList<CarDTO>();
   Car car;
   for (int i = 0; i < cars.size(); i++) { // parcours BDD
     car = cars.get(i); // extrait ième voiture
     if (car.isRented() == false) { // ? louée
       CarDTO dto = new CarDTO(car); // non louée : création DTO
       dtos.add(dto);
     }
   }
   return dtos;
 }
示例#4
0
  @Override
  public void doSmth(Move move, Car self, World world, Game game) {
    if (self.getOilCanisterCount() > 0) {
      MovingPoint currentPoint = Utils.getMap().getCurrentPoint(self, world, game);

      if (currentPoint.isTurn()) {
        move.setSpillOil(true);
      }
    }
  }
  @Override
  public Collection<Action<?>> decide(
      Car self, World world, Game game, Move move, Navigator navigator) {
    if (happened) {
      return Collections.emptySet();
    }

    if (initializing) {
      double speed = StrictMath.hypot(self.getSpeedX(), self.getSpeedY());

      if (speed > 1.0D) {
        log.print("Init\n");
        initializing = false;
      } else {
        return Collections.emptySet();
      }
    }

    Collection<Car> cars = cars(self, world, game).collect(Collectors.toList());

    log.printf(
        "Sides #%d: %s%n",
        tick, cars.stream().map(e -> new Point(e.getX(), e.getY())).collect(Collectors.toList()));

    if (cars.size() >= 2 && tick == 0) {
      tick = world.getTick();
    } else if (cars.size() >= 2 && world.getTick() - tick > THRESHOLD) {
      log.printf(
          "Let idiots pass: %s%n",
          cars.stream().map(e -> new Point(e.getX(), e.getY())).collect(Collectors.toList()));
      happened = true;
      return Collections.singleton(new SpeedAction(Priority.HIGH, 0.1D));
    } else if (cars.size() < 2) {
      tick = world.getTick();
    }

    return Collections.emptySet();
  }
示例#6
0
  public void run() throws IOException {
    try {
      remoteProcessClient.writeToken(token);
      int teamSize = remoteProcessClient.readTeamSize();
      remoteProcessClient.writeProtocolVersion();
      Game game = remoteProcessClient.readGameContext();

      Strategy[] strategies = new Strategy[teamSize];

      for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
        strategies[strategyIndex] = new MyStrategy();
      }

      PlayerContext playerContext;

      while ((playerContext = remoteProcessClient.readPlayerContext()) != null) {
        Car[] playerCars = playerContext.getCars();
        if (playerCars == null || playerCars.length != teamSize) {
          break;
        }

        Move[] moves = new Move[teamSize];

        for (int carIndex = 0; carIndex < teamSize; ++carIndex) {
          Car playerCar = playerCars[carIndex];

          Move move = new Move();
          moves[carIndex] = move;
          strategies[playerCar.getTeammateIndex()].move(
              playerCar, playerContext.getWorld(), game, move);
        }

        remoteProcessClient.writeMoves(moves);
      }
    } finally {
      remoteProcessClient.close();
    }
  }