You are on page 1of 19

Waiter Agent Messages public void msgSitCustomerAtTable (CustomerAgent customer, int tableNum) { MyCustomer c = new MyCustomer(customer, tableNum); c.

state = CustomerState.NEED_SEATED; customers.add(c); stateChanged(); } Host sends this to give the waiter a new customer, which the waiter will add to its list of customers public void msgImReadyToOrder(CustomerAgent customer) { if ( Customer c in customers c.equals(customer)) { c.state = CustomerState.READY_TO_ORDER; stateChanged(); return; } } Customer sends this when they are ready, which will make the waiter change the customers state for that customer public void msgIWantToReorder(CustomerAgent customer) { if ( Customer c in customers c.equals(customer)) { c.state = CustomerState.READY_TO_ORDER; stateChanged(); return; } } public void msgHereIsMyChoice(CustomerAgent customer, String choice, boolean reordering) { if ( Customer c in customers c.equals(customer)) { c.choice = choice; if (!reordering) { c.state = CustomerState.ORDER_PENDING; } else { c.state = CustomerState.REORDERING; } stateChanged(); return; } }

Customer sends this to let the waiter know its choice, which the waiter will keep track of for the customer

public void msgOrderIsReady(int tableNum, Food f) { if ( Customer c in customers c.tableNum == tableNum) { c.state = CustomerState.ORDER_READY; c.food = f; stateChanged(); return; } } Cook sends this to let the waiter know that food has been prepared public void msgDoneEating (CustomerAgent customer) { if ( Customer c in customers c.tableNum == tableNum) { c.state = CustomerState.IS_DONE; stateChanged(); return; } } Customer sends this when they are done eating public void msgTheseItemsAreOut (List<String> foodList, order) { order.customer.state = CustomerState.NEED_TO_REORDER; for ( String s in foodList) { order.unavailable.add(s); } stateChanged(); return; } Cook sends this when an order cannot be cooked due to shortage public void msgTooLateToChangeOrder(Order order) { if ( Customer c in customers order.table == c.tableNum) { c.state = Customer.ORDER_PENDING; } } Cook sends this when an order was already being cooked and unable to be changed public void msgOrderChanged(Order order) { if ( Customer c in customers order.table == c.tableNum) { c.state = Customer.ORDER_PENDING; } } Cook sends this when an order was able to be changed

Scheduling if(!customers.isEmpty()) { if ( Customer c in customers c.state == CustomerState.ORDER_READY) { giveFoodToCustomer(c); return true; } o Gives food to the customer if an order is ready if ( Customer c in customers c.state == CustomerState.NEED_TO_REORDER) { retakeOrder(c); return true; } o Retakes the order for a customer who ordered a short item if ( Customer c in customers c.state == CustomerState.IS_DONE) { clearTable(c); return true; } o Clears the table if a customer is done if ( Customer c in customers c.state == CustomerState.NEED_SEATED) { seatCustomer(c); return true; } o Seats a customer if a customer is ready to be seated if ( Customer c in customers c.state == CustomerState.ORDER_PENDING) { giveOrderToCook(c); return true; } o Gives the an order to the cook if a customer has ordered if ( Customer c in customers c.state == CustomerState.REORDERING) { giveReorderToCook(c); return true; } o Lets the cook now that a customer wants to reorder if ( Customer c in customers c.state == CustomerState.READY_TO_ORDER) { takeOrder(c); return true; } o Takes an order from a customer if he/she is ready to order

} return false; Return false when there is nothing to do Actions private void seatCustomer (MyCustomer customer) { DoSeatCustomer(customer); customer.state = CustomerState.NO_ACTION; customer.cmr.msgFollowMeToTable(this, new Menu()); stateChanged(); } Seats a customer at a table private void takeOrder(MyCustomer customer) { DoTakeOrder(customer); customer.state = CustomerState.NO_ACTION; customer.cmr.msgWhatWouldYouLike(); stateChanged(); } Takes an order from a customer private void retakeOrder(MyCustomer customer) { DoTakeOrder(customer); customer.state = CustomerState.NO_ACTION; Menu menu = new Menu(); menu.remove(order.unavailable); customer.cmr.msgPleaseReorder(menu); stateChanged(); } Retakes an order from a customer with a lessened menu private void giveOrderToCook(MyCustomer customer) { customer.state = CustomerState.NO_ACTION; cook.msgHereIsAnOrder(this, customer.tableNum, customer.choice); stateChanged(); } The waiter gives the cook a pending order private void giveReorderToCook (MyCustomer customer) { customer.state = CustomerState.NO_ACTION; cook.msgCanYouChangeOrders(customer, customer.choice); stateChanged(); }

The waiter gives the cook an account of the order to be changed

private void giveFoodToCustomer(MyCustomer customer) { DoGiveFoodToCustomer(customer); customer.state = CustomerState.NO_ACTION; customer.cmr.msgHereIsYourFood(customer.choice); stateChanged(); } The waiter gives food to the customer private void clearTable(MyCustomer customer) { DoClearingTable(customer); customer.state = CustomerState.NO_ACTION; stateChanged(); } Data private boolean onBreak Whether the waiter is on break or not private String name Name of the waiter private List<MyCustomer> customers All the customers that the waiter is serving private HostAgent host; The host of the restaurant private CookAgent cook; The cook of the restaurant Host Agent Messages public void msgIWantToEat(CustomerAgent customer) { waitlist.add(customer); stateChanged(); } Customer sends this message to be added to the wait list for eating public void msgTableIsFree(int tableNum) { tables[tableNum].occupied = false;

stateChanged(); Waiter sends this message to let the host know a table is open

public void msgIWillLeave(CustomerAgent customer) { if ( CustomerAgent c in waitlist c.equals(customer)) waitlist.remove(c); } stateChanged(); } Customer sends this message to tell the host that it will leave public void msgIWillStay(CustomerAgent customer) { if ( CustomerAgent c in waitlist c.equals(customer)) c.state = CustomerState.WAITING_FOR_OPENING; } stateChanged(); } Customer sends this message to let the host know that it is staying Scheduling if(!waitList.isEmpty() && !waiters.isEmpty()){ if ( Table t in tables t.occuplied == false) { tellWaiterToSitCustomerAtTable(waiters.get(nextWaiter), waitlist.get(0), t); return true; } o If there is an unoccupied table, have the next waiter sit a customer down at that table else if ( CustomerAgent customer in waitlist customer.state != CustomerState.WAITING_FOR_OPENING)) { tellCustomerRestaurantIsFull(waitlist.get(0)); return true; } o If the restaurant is full and some customers dont know, then tell the customer so } return false; Returns false when there are no waiters or no waiting customers Actions private void tellWaiterToSitCustomerAtTable(MyWaiter waiter, CustomerAgent customer, int tableNum) {

waiter.wtr.msgSitCustomerAtTable(customer, tableNum); tables[tableNum].occupied = true; waitlist.remove(customer); nextWaiter = (nextWaiter+1)%waiters.size(); stateChanged(); Has a waiter send a customer to a table, revises the waitlist and table list, and advances a waiter in the list

private void tellCustomerRestaurantIsFull(CustomerAgent customer) { customer.msgRestaurantCurrentlyFull(); stateChanged(); } Data private List<CustomerAgent> waitlist List of customers waiting for a table private List<MyWaiter> waiters List of all waiters int nTables Number of tables private Table tables[]; Array of all the tables private String name; Name of the host Customer Agent Messages public void setHungry() { events.add(AgentEvent.gotHungry); isHungry = true; stateChanged(); } The GUI sends this to force the customer to being hungry public void setReorder() { events.add(AgentEvent.wantToReorder) stateChanged();

Forces the customer to want to reorder

public void msgFollowMeToTable(WaiterAgent waiter, Menu menu) { this.menu = menu; this.waiter = waiter; events.add(AgentEvent.beingSeated); stateChanged(); } Waiter sends this have the customer follow to be seated public void msgDecide() { events.add(AgentEvent.decidedChoice); stateChanged(); } Message sent to self to let the customer know that its decided public void msgWhatWOuldYouLike() { events.add(AgentEvent.waiterToTakeOrder); stateChanged() } Waiter sends this message to take the customers order public void msgPleaseReorder(Menu menu) { this.menu = menu; events.add(AgentEvent.waiterToTakeOrder); stateChanged(); } public void msgHereIsYourFood(String choice) { events.add(AgentEvent.foodDelivered); stateChanged(); } Waiter sends this when the food is ready and to be delivered public void msgDoneEating() { events.add(AgentEvent.doneEating); stateChanged(); } Message sent to self to let the customer know that its done eating public void msgGoToCashier(CashierAgent c, Bill b) { this.cashier = c; this.bill = b; events.add(AgentEvent.receivedBill);

stateChanged(); Message from the waiter to go to the cashier

public void msgYouStillOweMoneyAndMustWork(int amount) { this.moneyOwed = amount; events.add(AgentEvent.owesMoney); stateChanged(); } Cashier sends this to let customer know that it did not pay enough public void msgYouCanLeave() { events.add(AgentEvents.donePaying); stateChanged(); } Cashier sends this to let the customer know it can leave public void msgRestaurantCurrentlyFull() { events.add(AgentEvents.restaurantFull); stateChanged(); } Host sends this to let the customer know the restaurant is full Actions private void goingToRestauruant() { host.msgIWantToEat(this); stateChanged() } Goes the restaurant when the customer becomes hungry private void makeMenuChoice() { timer.delay(); msgDecided(); stateChanged(); } Takes time for the customer to make a decision private void callWaiter() { waiter.msgImReadyToOrder(this); stateChanged(); } Calls the waiter to let it know the customers ready private void callWaiterForReorder() {

waiter.msgIWantToReorder(this); stateChanged(); Calls the waiter for a reorder

private void orderFood() { String choice = menu.choice(random); waiter.msgHereIsMyChoice(this, choice, reordering); stateChanged(); } Customer makes a random choice of food private void eatFood() { timer.delay(); msgDoneEating(); stateChanged(); } Has the customer eat food and message itself when finished private void tellWaiterDone() { waiter.msgDoneEating(this); stateChanged(); } Has the customer lets the waiter know its done eating private void leaveRestaurant() { guiCustomer.leave(); waiter.msgDoneEating(this); stateChanged(); gui.setCustomerEnabled(this); } Customer leaves the restaurant private void becomeHungryInAWhile() { timer.delay(); setHungry(); } Hack to make the customer hungry after a period of time private void giveCashierPayment() { int payment=0; if (bill.cost > money) payment = money; else payment = bill.cost;

cashier.msgHereIsPayment(Bill bill, payment, this); stateChanged(); Gives the cashier the payment that it can afford

private void workForMoney() { while (money < moneyOwed) { timer.delay(); money++; } cashier.msgHereIsPayment(Bill bill, moneyOwed, this); stateChanged() } Works until enough money is made to pay the rest of the meal private void restaurantFullChoice() { if (random(1)==1) { host.msgIWillWait(this); } else { host.msgIWillLeave(this); guiCustomer.leave(); } stateChanged(); } Decides what to do when the restaurant is full Scheduling if (events.isEmpty()) { return false; } If there were no events, do nothing AgentEvent event = events.remove(0); Pop the first event if (state == AgentState.DoingNothing) { if (event == AgentEvent.gotHungry) { goingToRestraunt(); state = AgentState.WaitingInRestraunt; return true; } } If the customer is doing nothing and is hungry, it goes to the restaurant if (state == AgentState.WaitingInRestaurant) { if (event == AgentEvent.beingSeated){ makeMenuChoice();

state = AgentState.SeatedWithMenu; return true;

} if (state == AgentState.SeatedWithMenu) { if (event == AgentEvent.decidedChoice){ callWaiter(); state = AgentState.WaiterCalled; return true; } } If the customer is seated with a menu and finished deciding, it calls the waiter if (state == AgentState.WaiterCalled) { if (event == AgentEvent.waiterToTakeOrder){ orderFood(); state = AgentState.WaitingForFood; return true; } } If the customer has called the waiter and the waiter is taking the order, it orders if (state == AgentState.WaitingForFood) { if (event == AgentEvent.foodDelivered){ eatFood(); state = AgentState.Eating; return true; } o If the customer is waiting for food and it is delivered, it eats if (event == AgenteEvent.wantToReorder) { callWaiterForReorder(); state = AgentState.WaiterCalledForReorder; return true; } o If the customer is waiting and wants to reorder, it reorders } if (state == AgentState.Eating) { if (event == AgentEvent.doneEating){ tellWaiterDone(); state = AgentState.WaitingForBill;

o If the customer is in the restaurant and being seated, it makes a choice if (event == AgentEvent.restaurantFull) { restaurantFullChoice(); state = AgentState.restaurantFull; return true; } o If the customer is in the restaurant and is told its full, it makes a choice

return true;

If the customer is eating and finishes, it leaves the restaurant if (state == AgentState.WaitingForBill) { if (event == AgentEvent.receivedBill) { giveCashierPayment(); state = AgentState.PayingForBill; return true; } } If the customer is waiting for the bill and gets it, it pays the cashier if (state == AgentState.PayingForBill) { if (event == AgentEvent.owesMoney) { workForMoney(); state = AgentState.DoingNothing; } } If the customer is paying for bill and doesnt have enough money, it needs to work if (state == AgentState.PayingForBill) { if (event == AgentEvent.donePaying) { leaveRestaurant() state = AgentState.DoingNothing; return true; } } If the customer is able to pay the bill, it will leave the restaurant Data private String name Name of the customer private int hungerLevel How hungry the customer is, determines length of meal private CashierAgent cashier The cashier of the restaurant private Bill bill The customers bill private HostAgent host The host of the restaurant

private WaiterAgent waiter The waiter assigned to the customer Restaurant restaurant The restaurant private Menu menu The menu with the choice for the customer private boolean isHungry Hack for making the customer hungry private AgentState state State of the customer List<AgentEvent> events List of events for the customer private int money Amount of money that the customer has private int moneyOwed Amount of money owed private boolean reordering Whether or not a customer is reordering Cook Agent Messages public void msgHereIsAnOrder(WaiterAgent waiter, int tableNum, String choice) { orders.add(new Order(waiter, tableNum, choice)); stateChanged(); } Waiter sends this to give the cook an order public void msgCanYouCangeOrders(WaiterAgent waiter, int tableNum, String choice) { if ( Order o in orders o.choice.matches(choice) { o.changeChoice = choice; } stateChanged(); } Waiter sends this to ask the cook to change orders public void msgOrderFulfilled(FoodOrder fo) {

for ( FoodData fd in inventory FoodData fd2 in fo fd.name.matches(fd2.name) { fd.amount += fd2.amount; } foodOrders.remove(fo); } Market sends this to let the cook know that an order has been fulfilled public void msgUnableToFulfillOrder(FoodOrder fo) { fo.market++; foodOrders.add(fo); } Market sends this to let the cook know that an order could not be fulfilled Actions private void cookOrder(Order order) { if ( FoodData fd in inventory fd.amount != 0 && fd.name.matches(order.name)) { DoCooking(order); order.status = status.cooking; } else { List<String> = new List<String> (); for ( FoodData fd in inventory fd.amount == 0) { foodList.add(fd.name); } order.waiter.msgTheseItemsAreOut(foodList, order); } } Cooks an order, if there is no more ingredient, tell the waiter private void placeOrder(Order order) { DoPlacement(order); order.waiter.msgOrderIsReady(order.tableNum.order.food); orders.remove(order); } Places an order, messages the cook about it, and removes the order from its list private void changeOrder(Order order) { if (order.status == Status.pending) { order.choice == order.changeChoice; order.waiter.msgOrderChanged(order); } else { order.waiter.msgTooLateToChangeOrder(order); }

} private void initialOrderFromMarket() { FoodOrder fo = new FoodOrder(); for ( FoodData fd in inventory fd.amount < sufficientLimit) { fo.addItem(fd.food, sufficientLimit - fd.amount); fd.amountOrdered += sufficientLimit - fd.amount; } markets.get(fo.market).msgHereIsOrder(fo); } Places an order for food from the favorite selected market private void repeatedOrderFromMarket(FoodOrder fo) { markets.get(fo.market).msgHereIsOrder(fo); } Places an order from other markets, to be called if the first failed Scheduling if ( FoodData fd in inventory fd.amountOrdered < lowLimit) { initialOrderFromMarket(); return true; } If a food item is below the low limit and an order has not been sent, order from the market if (!foodOrders.isEmpty()) { repeatedOrderFromMarket(foodOrders.remove(0)); return true; } If an order was unable to be fulfilled by one market, try other markets if ( Order o in orders o.status == Status.done) { placeOrder(o); return true; } If there is an order that is done, place it if ( Order o in orders o.changeChoice != o.choice) { changeOrder(o); return true; } If there is an order thats been requested to be changed, change it if ( Order o in orders o.status == Status.pending) { cookOrder(o); return true; }

If there is an order that is pending cook it return false; Data private List<Order> orders List of all the orders private Map<String, FoodData> inventory Map that holds the amount of food left private String name Name of the cook private int lowLimit The limit of food before needing to order more private int sufficientLimit The limit of food when it is unnecessary to order more private list<Market> markets List of markets private list<FoodOrder> foodOrders List of orders sent back from the market Cashier Agent Messages private void msgHereIsPayment(Bill bill, int payment, CustomerAgent customer) { if ( Bill b in bills b.customer.equals(customer)) { b.payment = payment; } } Customer calls this to give a payment to the cashier Actions private void calculate(MyBill bill) { if (bill.payment < bill.cost) { bill.customer.msgYouStillOweMoneyAndMustWork(amount); bill.cost -= bill.payment; } else { bill.customer.msgYouCanLeave();

} stateChanged(); }

bills.remove(bill);

Cashier calculates a payment and responds to the customer

Scheduling if (!bills.isEmpty()) { if ( Bill b in bills b.payment != 0) { calculateBill(b); return true; } o Cashier calculates a bill if there is a bill that has a payment } Data private List<MyBill> bills List of bills that the cashier is keeping track of Market Agent Messages public void msgHereIsOrder(FoodOrder fo) { pendingOrders.add(fo); stateChanged(); } Cook sends this to order from the market Actions private void respondToOrder(FoodOrder fo) { if ( FoodData fd in fo fo.amount < inventory.get(fd.name).amount) { cook.msgOrderFulfilled(fo); for ( FoodData fd in fo) { inventory.get(fd.name).amount -= fo.amount; } } else { cook.msgUnableToFulfillOrder(fo); } stateChanged(); }

Check the inventory to see if there is enough food to fulfill the order, and respond

Scheduling if (!pendingOrders.isEmpty()) { respondToOrder(pendingOrders.get(0)); return true; } If there is an order, reply to it return false; Data private CookAgent cook The cook agent of the restaurant private List<FoodOrder> pendingOrders List of orders to be completed for the chef private Map<String, FoodData> inventory Map that holds the amount of food left

You might also like