Tutorial — First Steps

Back to portal

You borrowed $50,000 from a bank to open your own restaurant. After one year you need to pay back $55,000 and since nobody is lending you more money, you need to make sure that you never spend (or try to spend) more money than you possess. So it is time to see how to make some money.

You need to write JavaScript code to run your restaurant. The only variable you get from the engine is called company and is an instance of the class Company.

All you need to do is implement 7 functions, which are getting called for:

Let's have a look how this works. First we need to set up our menu. Let's do that on the launch event.

company.launch = function() {
	company.menu.add("Kebab", ["CHICKEN_MEAT", "BREAD"], 3);
};

The company class has a menu property which can be used to add, remove or list menu entries. We add a simple Chicken Kebab with nothing but meat and bread for $3.

Available ingredients: SALAD, TOMATO, ONION, BREAD, LAMB_MEAT, CHICKEN_MEAT, BEEF_MEAT, CABBAGE, SPICES, GARLIC_SAUCE.

Next we need to rent a restaurant. Let's implement the realEstateAgent event:

company.realEstateAgent = function(realEstateProfiles) {
	if(company.establishments.size() < 1) {
		realEstateProfiles.get(0).tryLease(0);
	}
};

Since we only want to rent one restaurant, we check the establishments property. Then we get the first element from real estate offers and try to lease it. The parameter value 0 stands for "we don't want to bribe the real estate agent or the landlord", but if you do so you increase your chances if there are competing offers.

Since other players may do the same, it is not guaranteed that we get this property. The engine performs multiple rounds until all offerings are rented or bought.

Now we need employees — at least a chef and a waiter. Let's implement the humanResources' hiringProcess event:

company.humanResources.hiringProcess = function(applicationProfiles) {
	if (company.humanResources.getEmployees("WAITER").size() < 1) {
		applicationProfiles.subList("WAITER").get(0).offer(
			company.establishments.get(0));
	}
	if (company.humanResources.getEmployees("CHEF").size() < 1) {
		applicationProfiles.subList("CHEF").get(0).offer(
			company.establishments.get(0));
	}
};

We check our human resources for chefs/waiters and if we haven't hired anybody for that role, we filter the profiles, sort by salary and make an offer to the first person.

Even the simplest restaurant needs a counter to serve food. So we buy one:

company.doMonthly = function() {
	if(company.establishments.size()==1) {
		company.establishments.get(0).buyInteriorAccessoriesNotExist("COUNTER");
	}
};

Available interiors: TABLE, CHAIR, COUNTER, VERTICAL_ROTISSERIE, TOASTER, OVEN, COFFEE_MACHINE, BEVERAGE_COOLER, FRIDGE.

Since we want to serve food we need to buy ingredients. Let's implement the daily event:

company.doDaily = function(dailyStatistics) {
	company.grocer.order("CHICKEN_MEAT", 100);
	company.grocer.order("BREAD", 100);
};

We order 100 units of chicken and bread. Our Kebab uses one of each, so we could sell 100 Kebabs per day. Roughly 100 people per participating player want to eat per day. Food decays after 10 days, but you get a discount for buying in larger quantities.

As a final step we distribute our food delivery:

company.foodDelivery = function(foodDelivery) {
	foodDelivery.each(function(foodUnit) {
		foodUnit.distributeEqually();
	});
};

Now hit Save and check to verify everything runs without errors. In the next global run, your restaurant will compete!

You can use console.log("...") in your script to output debug information.

Ideas for Optimization