/** 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 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)); }*/ }
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; } } }