Sims Tutorial

From Scalable Game Design wiki
Jump to: navigation, search
Sims-like game of a shoe salesperson described in the tutorial

The purpose of this tutorial is to help you create a Sims-style simulation of a shoe salesperson's day at work. You will need to define the salesperson's hierarchy of needs based on research and collaboration.

The finished simulation can be found in the Scalable Game Design Arcade here.

Design Process

The document created in order to properly plan for the creation of this simulation is located here.


How to Read This Tutorial

This Tutorial uses "collapsible boxes":

Getting Started

New Project: First, you should open a new project and give it a relevant name.  For this simulation, the project was named "Shoe Salesperson."  This tutorial was also created using 32 x 32 sized agents.

Agents: This project will require 7 agents to be created with some having multiple depictions.  These are shown below.

Worksheet:  The worksheet created for this simulation is shown below.  There are two rooms, one at the storefront where the customers will be, and a back room for storing inventory. ShoeSalespersonWorksheet.gif


Programming diffusion for spreading the presence of targets

In order for the salesperson to know where to go to satisfy their needs, diffusion and hill climbing techniques will need to be used so that the salesperson can reach certain items in the store. Target agents that the salesperson will need to locate are the customer, the inventory shelves, and the register. To allow for the salesperson agent to track these items (using hill climbing), the floor agents will be used to diffuse the presence of the target agents.

Below is an image of how the diffusion may look when a Customer arrives to the store. Please note that this is just a visualization technique to show diffusion values, but the user will not see this while the simulation is running. ShoeSalespersonDiffusion.jpg

Here is the code necessary for each agent that will need to be located. This is the only code that will be located in the "While running" behavior of the agents.

Customer:

ShoeSalespersonCustomerDiffusion.jpg


Register:

ShoeSalespersonRegisterDiffusion.jpg


Inventory:

ShoeSalespersonInventoryDiffusion.jpg


Floor:

The code to diffuse these "presence" values of the various target agents will be placed in the floor agents. The simple form of diffusing one such value is essentially the average of the values from the four neighbors:

Set value to 0.25 * ( value[left] + value[right] + value[up] + value[down] )

ShoeSalespersonFloorDiffusion.jpg

In this case c represents the value that the Customer is sending out, r represents the Register, and i represents the Inventory.

Programming the Salesperson

The Salesperson must constantly keep track of what needs to be done based on a hierarchy representing the priority of these tasks. This means that the Salesperson needs to keep track of how long it's been since the store has been cleaned, how long it's been since inventory was done, and also whether or not a customer needs to be helped.


All of the code for this will be located within the behavior of the Salesperson, but the only code that will be in the "While running" portion of the behavior will be the checking of time, moving, and completing a task. This code is shown below.

ShoeSalespersonSalespersonWhileRunning.jpg

Here, the Salesperson first calls updateHierarchy, which is a method that increments the counters for tasks that will need to be completed after a certain period of time. These include cleaning the store and doing inventory.


Next, the Salesperson calls a method that will move in a direction that will allow them to complete a task. If there are no tasks to be completed at the time, the Salesperson will just move randomly.


The third method the Salesperson calls will be the satisfyHierarchy method.  This method will have the Salesperson work on completing a task if it has been reached.  This may include just cleaning wherever the Salesperson is standing, doing inventory, helping a Customer, or getting shoes from the Register if the Customer wants shoes.



Customer and Register Methods

There are many methods that the Salesperson needs in order to serve a Customer.  Most of these involve properly simulating communication between the Bench/Customer Generator, the Customer, and the Register.

The first of these is the method that the Bench/Customer Generator broadcasts to the the Salesperson to tell it to make serving the Customer a priority. This can be done by having the method set the customer variable to 1. Basically, this would be the same as hearing a door beep when a Customer enters which triggers the Salesperson's need to help them.


Another necessary method tells the Salesperson that the Customer is leaving. For this to have meaning to the Salesperson agent, a method must set the customer variable to 0.


A third communication method that is used has the Salesperson handle a request by the Customer to buy shoes.


The final method used where other agents are communicating with the Salesperson is the holdShoebox method. This method simply changes the depiction of the Salesperson to holding a shoebox and lets other rules handle the Salesperson's movement back to the customer.


Inventory Method

The doInventory method is called when the Salesperson is next to any Inventory agents and enough time has passed that doing inventory is necessary for the Salesperson.  In this case, inventory needs to be done every 50 seconds.  Since the simulation doesn't require any communication between the Salesperson and the Inventory, this method only needs to keep track of how long inventory has been done, stop after 10 seconds, and reset the counter for the next time inventory needs to be completed.


Cleaning Method

The cleaning method, like the inventory method, also doesn't require any communication to occur with the Salesperson agent.  So it is very similar in that it changes depiction, keeps track of how long cleaning has been done, stops cleaning after 10 seconds, and then resets the counter for the next time cleaning needs to be completed.



Moving Towards Tasks

The final set of methods that are needed for the Salesperson agent are methods that tell the Salesperson where to move to satisfy a task.  These methods are called from the move method and use the diffusion discussed earlier in the tutorial.

The code for each method checks which direction the values of either c, i, or r (depending on the task needed to be completed) of the floor is the strongest and then moves in that direction.  The general pseudo-code for this is as follows:

If variable[right]>variable[up] and variable[right]>variable[down] and variable[right]>variable[left] then move right.

If variable[left]>variable[up] and variable[left]>variable[right] and variable[left]>variable[down] then move left.

If variable[up]>variable[right] and variable[up]>variable[down] and variable[up]>variable[left] then move up.

If variable[down]>variable[right] and variable[down]>variable[up] and variable[down]>variable[left] then move down.


Portions of this code are shown below for each method: toCustomer, toRegister, and toInventory.


Note: The variables used here were set in the while running method for each agent.

Programming the Bench/Customer Generator

The purpose of the Bench agent is to randomly generate a Customer agent every 20 seconds with 50% probability.  This agent also broadcasts to the Salesperson that a Customer has been generated, just like a bell going off at the door to the store.

Programming the Customer

Besides the while running method that sets the c variable and allows for the Salesperson to hill climb towards the Customer, there is a method that the has the customer respond to help and a method to respond to having shoes sold to them.  Examples of each with pseudo-code can be seen below.



Programming the Register

The register only has one method besides the while running that sets the variable used for hill climbing.  This method is the sale method and it tells the Salesperson to hold a shoebox and return to the Customer to give it to them.  Examples of the methods are shown below.