Instructions

This is an ECMAScript (JavaScript) programming assignment. Particularly, this task will assess your skills to:

Your task is to write code to let the robot chef preparing all the six orders correctly.
The robot chef must:

  1. Take the food from the refrigerating room;
  2. Place the food on the stove and cook it until ready for plating;
  3. Plate it on the benchtop table;
  4. Serve it on the serving window.
The number of plates available in the kitchen is limited to three, one of which is dirty at the start of the game. You will need to clean the dirty plates at the sink when you are out of clean ones to plate new meals.
In addition, the robot chef can only handle a maximum of five items in its inventory. Therefore, you must organise the actions to handle the time and the limited resources in a smart way.

Orders' cooking temperatures and times

Each order is a combination of a steak and a side. The steak can be cooked to reach a specific temperature to obtain the desired cooking level required by the order:

The side can be vegetables or mashed-potatoes. Each side must be cooked for a certain amount of 'game ticks' to reach the perfect cooking level:

Temperature and time sensors

The stove in the kitchen is a smart stove using a temperature sensor and a time sensor (clock) for each of the four stove's fires.
Whenever food is placed on a stove fire, the corresponding temperature and time sensors will update their values according to the current temperature reached by the food on that stove fire and the time the food has been cooking.
The values for these sensors are published on two topics every time there is a change in the sensors' values. The topics are:

The messages published on these topics are object literals with the following structure:
{'stove-1': ..., 'stove-2': ..., 'stove-3': ..., 'stove-4': ...}
For example, if on the first stove fire the food reached 30 degrees, the temperature of the food on the fourth stove reach 40 degrees, and there is no food on the rest of the stove fires, the message published on the topic 'temperature_sensor' would be: {'stove-1': 30, 'stove-2': null, 'stove-3': null, 'stove-4': 40}
And if the food on the first stove fire has been cooking for 4 game ticks and the one on the fourth stove fire has been cooking for 6 game ticks, whereas there is still no food on the other stove fires, the message published on the topic 'stove_clock' would be: {'stove-1': 4, 'stove-2': null, 'stove-3': null, 'stove-4': 6}

Weight sensor

The smart kitchen also has a weight sensor on the returning window to check if there are returned dirty plates and how many are there on the returning window.
The weight sensor publishes a message on the topic 'weight_sensor' every time the number of plates on the returning window changes. The message published on this topic is an object literal with the following structure:
{'plates-number': ...}
For example, if one plate is returned on the returning window, the message published on the topic 'weight_sensor' would be: {'plates-number': 1}
If the plate is collected by the robot chef and there are no more plates on the returning window, the next message published on the topic 'weight_sensor' would be: {'plates-number': 0}

How to complete the task

To complete this task, you must write the code for your solution in the function robotChef that you can find in the file solution/task3.js.
This function has no arguments.
This function must retrieve the list of the orders to cook (see the sample code in the list below) and use the methods available from the global variable kitchenController to control the chef and serve the orders correctly.
If you need, you can write additional code outside the function robotChef (for example for global variables or functions). However, you must write this code in the file solution/task3.js.

How to control the robot chef (game methods)

To write the code for your solution you can use any available JavaScript function.
However, to control the robot chef (and access some information about the current state of the game) you will need to use methods accessible from the global variable kitchenController. The methods can be accessed with dot notation.
Below is a list of links to JavaScript files with sample code (and instructions) that you can copy and paste in the robotChef function to understand how the different methods work.

Accessing the orders

Interacting with the kitchen and the sensors

How to test your solution

To test your solution, after you write code in the function robotChef in the file solution/task3.js, save the file, open the file index.html, click on Task 3 in the Task Menu (on the left), and click the button Run simulation in the Control panel.
This will generate a list of six random orders and invoke the function robotChef.
The simulation will end once the function robotChef completes.
If your code generates errors, the execution of the function robotChef will terminate and the error will be logged in red in the Log panel.
At the end of the simulation, the left Control panel will display your current success rate in preparing the correct meals according to the orders list.

Logging

If you want to log messages you can use the JavaScript console.log method to log messages in the browser's debug console or you can use the global function log provided for you to log your text message in the right Log console panel of the game interface.
For example, if you want to log the string 'Hello world' in the Log panel with the global function log you can write in your code:
log('Hello world')
If you want to log the string 'Hello world' in the browser's debug console instead, you can write in your code:
console.log('Hello world')

Hints

Go though all the sample codes listed above before starting this task. Copy and paste each sample code in the function robotChef and see what happens.
Each sample code includes comments to provide an explanation of each set of instructions. Read them carefully.
Once you tried out all the sample codes, try to re-use them in your code by adapting them so to complete the task.

Marking criteria:

Category Weighting Result
Orders successfully served (success rate) 3 marks The final mark for this category is computed using the following formula:
3 * (success rate / 100)
Quality of the code 0.5 marks 0 marks. No order was correctly served or the code does not use the publish / subscribe methods to correctly read and use all sensors' values (temperature, clock and weight sensors). 0.5 marks. At least one correct order was served and the code makes a correct use of the publish / subscribe methods to correctly read and use all the sensors' values (temperature, clock and weight sensors).