示例#1
0
 /**
  * Metoda wklada ksiazke do kieszeni
  *
  * @param book
  */
 public void putToCache(Book book) {
   if (cache.size() >= cacheLimit) {
     logger.level3("Proba wlozenia ksiazki do pelnej kieszeni: " + book);
     throw new EnvinronmentException("Proba wlozenia przepelnienia kieszeni robota: " + this);
   }
   logger.level1("Wlozono ksiazke do kieszeni: " + book);
   cache.add(book);
 }
示例#2
0
 /**
  * Metoda wyjmuje ksiazke z kieszeni
  *
  * @param isbn
  * @return true jesli ksiazka tam byla
  */
 public Book takeFromCache(int isbn) {
   for (Book book : cache) {
     if (book.getIsbn() == isbn) {
       if (cache.remove(book)) {
         logger.level1("Wyjeto ksiazke z kieszeni: " + book);
         return book;
       }
     }
   }
   logger.level2("Proba wyjecia ksiazki ktorej nie ma z kieszeni: " + isbn);
   return null;
 }
 public StudentDecision decide(
     StudentView controlledStudent, StudentEnvironmentView environmentView) {
   // jesli juz dotarlismy do celu
   if (controlledStudent.getLocation().equals(target)) {
     logger.level1("[StudentRouteAlgorithm] Osiagnieto cel:" + target);
     // dotarlismy
     target = null;
   }
   // jesli nie mamy celu
   if (target == null) {
     // pytamy algorytm wewnetrzny o decyzje
     StudentDecision internalAlgorithmDecision =
         internalAlgorithm.decide(controlledStudent, environmentView);
     logger.level1("[StudentRouteAlgorithm] Wykonywanie rozkazu: " + internalAlgorithmDecision);
     if (internalAlgorithmDecision.getDecisionType() == StudentDecisionType.GO_TO) {
       // zapis nowego celu
       target = (Location) internalAlgorithmDecision.getArg0();
       logger.level1("[StudentRouteAlgorithm] Obrano nowy cel: " + target);
     } else {
       // podejmowanie innej decyzji
       return internalAlgorithmDecision;
     }
   }
   // dazenie do celu
   // jesli stoimy na celu
   if (controlledStudent.getLocation().equals(target)) {
     logger.level1("[StudentRouteAlgorithm] Osiagneto cel: " + target);
     // to nie robimy nic bo nie ma to sensu
     return new StudentDecision(StudentDecisionType.WAIT, null, null);
   }
   // tworzenie grafu
   Graph graph =
       new Graph(
           environmentView.getWidth(),
           environmentView.getHeight(),
           controlledStudent.getLocation(),
           environmentView.getStudentAreaMarkerViews());
   List<Location> path = graph.getPathToLocation(target);
   logger.level1("[StudentRouteAlgorithm] Wyznaczono sciezke: " + path);
   // interesuje nsa nastepny krok wiec
   Turn turn = Turn.getTurn(path.get(0), path.get(1), 1);
   // zwracanie rozkazu
   return new StudentDecision(StudentDecisionType.MOVE, turn, null);
 }
示例#4
0
 /**
  * Ustawia nowa lokalizacje robota
  *
  * @param location
  */
 public void setLocation(Location location) {
   if (logger != null) {
     logger.level1("Zmiana polozenia na: " + location);
   }
   this.location = location;
 }