/** Scheduler. Determine what action is called for, and do it. */
  public boolean pickAndExecuteAnAction() {
    /* Think of this next rule as:
             Does there exist a table and customer,
             so that table is unoccupied and customer is waiting.
             If so seat him at the table.
    */

    if (Orders != null) {
      synchronized (Orders) {
        for (int i = 0; i < Orders.size(); i++) {
          if (Orders.get(i).s == OrderState.done) {
            DeliverOrder(Orders.get(i));
            return true;
          } else if (Orders.get(i).s == OrderState.pending) {
            TryRestockOrder(Orders.get(i));
            return true;
          }
        }
      }
    }

    return false;
    // we have tried all our rules and found
    // nothing to do. So return false to main loop of abstract agent
    // and wait.
  }
 public ItalianMarketRole(String name) {
   super(name);
   Foods.add(new Food("Steak", 11, 15, 15.99)); // name, restocking time, inventory, low, price
   Foods.add(new Food("Chicken", 12, 20, 10.99));
   Foods.add(new Food("Salad", 10, 100, 5.99));
   Foods.add(new Food("Pizza", 13, 100, 8.99));
 }
Ejemplo n.º 3
0
  Person(String name, double moneyz) {
    this.name = name;
    this.money = moneyz;
    roles.add(new ApartmentResidentRole(this, getName(), "Apartment Resident"));
    roles.add(new HousingResidentRole(this, getName(), "Housing Resident"));
    roles.add(new BankCustomerRole(this, getName(), "Bank Customer"));
    roles.add(new MarketCustomerRole(this, getName(), "Market Customer"));
    roles.add(
        new ChineseRestaurantCustomerRole(
            this,
            getName(),
            "Restaurant Customer",
            Phonebook.getPhonebook().getChineseRestaurant()));
    roles.add(new AmericanRestaurantCustomerRole(this, getName(), "Restaurant Customer"));
    nextTask = new Timer();
    atCityDestination = new Semaphore(0, true);
    setHunger(HungerLevel.full);
    hasFoodInFridge = false;

    // add restaurants to queue
    restaurantQueue = new ArrayList<String>();
    restaurantQueue.add("Chinese Restaurant");
    restaurantQueue.add("American Restaurant");
    restaurantQueue.add("Italian Restaurant");
    //	restaurantQueue.add("Chinese Restaurant");
    restaurantQueue.add("Seafood Restaurant");
  }
 public void msgHereIsPayment(ItalianCashier cashier, Double payment) {
   synchronized (Orders) {
     for (int i = 0; i < Orders.size(); i++) {
       if (Orders.get(i).food.orderamt * Orders.get(i).food.price == payment) {
         print("Received payment of " + payment + " from " + cashier);
         Orders.remove(Orders.get(i));
         stateChanged();
       }
     }
   }
 }
 // message from waiter to market to fulfill inventory
 public void msgOrderforMarket(ItalianCook c, String choice, int amount) {
   int foodamount;
   synchronized (Foods) {
     for (int i = 0; i < Foods.size(); i++) {
       if (Foods.get(i).type.equals(choice)) {
         if (Foods.get(i).inventory - amount > 0) {
           foodamount = amount;
         } else {
           foodamount = Foods.get(i).inventory;
         }
         Orders.add(new Order(c, Foods.get(i), foodamount, Foods.get(i).inventory - foodamount));
         print("Filling order from " + c + " for " + foodamount + " more " + Foods.get(i));
         stateChanged();
       }
     }
   }
   /*
   for(int i=0; i<Orders.size();i++){
   	if(Orders.get(i).s == OrderState.pending)
   		TryRestockOrder(Orders.get(i));
   }*/
 }
Ejemplo n.º 6
0
  protected void prepareForRestaurant() {

    String choice = restaurantQueue.get(0);
    for (int i = 0; i < restaurantQueue.size(); i++) {
      choice = restaurantQueue.get(i);
      if (choice.equals("Chinese Restaurant")
          && Phonebook.getPhonebook().getChineseRestaurant().isOpen()) {
        break;
      }
      if (choice.equals("Italian Restaurant")
          && Phonebook.getPhonebook().getItalianRestaurant().isOpen()) {
        break;
      }
      if (i == restaurantQueue.size()) print("Bummer, no restaurants open");
    }

    print("Going to become a customer at " + choice);

    restaurantQueue.remove(choice);
    restaurantQueue.add(choice);

    // Moving this choice to back of queue

    gui.walk = gui.decideForBus(choice);

    if (!gui.walk) {
      if (choice.equals("American Restaurant")) {
        print(
            "Destination bus Stop: "
                + Phonebook.getPhonebook()
                    .getAmericanRestaurant()
                    .getClosestBusStop()
                    .getBusStopNumber());
        goToBusStop(
            Phonebook.getPhonebook().getAmericanRestaurant().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getAmericanRestaurant().location);
      }
      if (choice.equals("Chinese Restaurant")) {
        print(
            "Destination bus Stop: "
                + Phonebook.getPhonebook()
                    .getChineseRestaurant()
                    .getClosestBusStop()
                    .getBusStopNumber());
        goToBusStop(
            Phonebook.getPhonebook().getChineseRestaurant().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getChineseRestaurant().location);
      }
      //			if (choice.contains("Seafood")){
      //				print("Destination bus Stop: " +
      // Phonebook.getPhonebook().getSeafoodRestaurant().getClosestBusStop().getBusStopNumber());
      //
      //	goToBusStop(Phonebook.getPhonebook().getSeafoodRestaurant().getClosestBusStop().getBusStopNumber());
      //			}
      if (choice.equals("Italian Restaurant")) {
        print(
            "Destination bus Stop: "
                + Phonebook.getPhonebook()
                    .getItalianRestaurant()
                    .getClosestBusStop()
                    .getBusStopNumber());
        goToBusStop(
            Phonebook.getPhonebook().getItalianRestaurant().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getItalianRestaurant().location);
      }
      gui.command = Command.GoToRestaurant;
    }

    try {
      atCityDestination.acquire();
      //					if (!gui.walk){
      //						try {
      //							atCityDestination.acquire();
      //						} catch (InterruptedException e) {
      //							e.printStackTrace();
      //
      //						}
      //				}
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    for (Role cust1 : roles) {
      if (cust1 instanceof ChineseRestaurantCustomerRole) {
        ChineseRestaurantCustomerRole RCR = (ChineseRestaurantCustomerRole) cust1;
        if (Phonebook.getPhonebook().getChineseRestaurant().arrived(RCR)) {
          currentRoleName = "Chinese Restaurant Customer";
          cust1.setRoleActive();
          stateChanged();
        }
        return;
      }
      if (cust1 instanceof ItalianCustomerRole) {
        ItalianCustomerRole RCR = (ItalianCustomerRole) cust1;
        if (Phonebook.getPhonebook().getItalianRestaurant().arrived(RCR)) {
          currentRoleName = "Italian Restaurant Customer";
          cust1.setRoleActive();
          stateChanged();
        }
        return;
      }
      if (cust1 instanceof AmericanRestaurantCustomerRole) {
        AmericanRestaurantCustomerRole RCR = (AmericanRestaurantCustomerRole) cust1;
        if (Phonebook.getPhonebook().getAmericanRestaurant().customerArrived(RCR)) {
          currentRoleName = "American Restaurant Customer";
          cust1.setRoleActive();
          stateChanged();
        }
        return;
      }
    }
  }