A9: Lambda Code Runner

Changelog

Overview

Red Robot

In this assignment, you will use the RML language you implemented in A8 to create artificial intelligence for a simple treasure finding game called Lambda Code Runner.

Because we are at the end of the semester, this assignment is much simpler than previous assignments. After reading this document and understanding the starter code, it should be possible to complete good or satisfactory scope in just a few hours, and excellent scope with just a bit more work. It is designed to be a lightweight and fun assignment, and we think you might have fun if you pair program your solution with your teammate(s). Having said that, if you are enjoying the game and want a challenge, there are numerous possibilities for exploring more sophisticated solutions.

In addition, we are providing you with reference solutions for A8, in the form of binaries for OS X and Linux (if you are on windows, we suggest using the CS 3110 VM.)

Table of Contents

Step 1: Team Maintenance

Your A9 team will be the same as your A8 team. Briefly check in with your teammate(s) to see how things are going, and make a plan for how you will complete this assignment, and for how you will celebrate finishing the course on Slope Day.

Step 2: Explore the Starter Code

The starter code includes:

The template contains detailed comments to explain what each line does, but at a high level, it spawns all of your team’s robots and sets up handles for pair-wise communication between them, initializes global variables that contain details about the game board (width, height, vision_rad, etc.), and provides event handlers for processing messages from the server (listen_server) and other robots (listen_bot). You are free to change any of this code, but in principle you should only have to fill in the bodies of the event handlers.

Step 3: Program Your Robot!

The Game

In Lambda Code Runner (inspired by the classic Brøderbund game), two teams of robots compete to see who can collect the most gold on a rectangular grid. Robots can implement arbitrary RML computations includinng communicating with each other using the send and recv primitives. Theyq manipulate the game state (moving around, picking up gold, sensing, etc.) through the server, which processes actions as described below. The objective of the game is to collect and return as much gold as possible to the base. The game runs for a pre-determined number of steps—after the time limit has been reached, the game ends and the robot team that has returned the most gold to its base wins.

Here is how the game works in more detail.

Grid

The grid has width by height square tiles. Each tile is one of the following elements:

Actions

Robots can perform one of several actions by sending one of the following message to the server.

[((1,1), ("Path", [])),
 ((0,0), ("Gold", [2])),
 ((1,0), ("Path", [])),
 ((2,0), ("Path", [])),
 ((0,1), ("Base", [1])),
 ((0,2), ("Path", [])),
 ((1,2), ("Path", [])),
 ((2,1), ("Path", [])),
 ((2,2), ("Gold", [4]))]

Note that the first element of this list is always the current position, but the other elements may appear in any order.

To perform one of these actions, you will need to send a request to the server using a send expression. The syntax for doing so is as follows:

The server will wait for a small delay before processing to move and take commands, but it responds immediately to look, info, and inv commands.

Your task is to write a function that utilizes all of these actions and possibly other asynchronous expressions to gather and return to base as much gold as possible before the game ends.

Hints

Because your robots will be implemented as event handlers, when building more complicated robots, you you may find it helpful to think in terms of simple state machines. For example, your robot might start out in “Explore” state until it finds gold and then transition to the “Return” state. You might represent the state as strings stored in a global reference, and pattern match on the state at the start of the listen_server function to determine which code to execute. Then, to transition to a new state, you could simply assign a new string to the state reference.

Here are some common bugs in RML to watch out for:

Step 4: Test Your Robots!

Red Robot

We have provided several sample maps (see maps/), as well as a GUI for visualizing and replaying matches between teams of robots. You should use these during development to make sure your robots are behaving as expected.

To run your robots, use the following commands:

To visualize a game using the GUI, point your browser at https://bluefire2.github.io/lambda-code-runner/ and add the replay.json file that is generated when you play a game on the command line.

Scope

This assignment is designed to be fun. So our expectations for scope are fairly conservative. You should be able to complete a basic working solution that gets a good grade in just a few hours.

In order to develop these features incrementally, we recommend that you make a working satisfactory version first, then refine the searching methods of single robots working as individuals, and finally make the robots able to communicate with one another and share their respective knowledge about the grid with each other.

In addition, because it is the end of the semester, the time for this assignment is short, and the final exam is coming up quickly, we recommend stopping at “Satisfactory” or “Good” scope if you are feeling pressed for time. Nobody should have to miss out on Slope Day or compromise their plans for studying for finals because they were hacking on robots. We will take the short duration of this assignment into consideration when weighting assignments in the final grade calculation.

Submission

Name your file robot.rml and construct a ZIP file containing this file and any other .rmx files (including the staff-provided libraries) you are using. Note that the robot.rml file should be at the top-level directory of the ZIP file. Any ill-formed ZIP files will receive a penalty of 20 points. The size of the files is limited in CMS to 1 MB. Please stay within the size allotted, and make sure that any dependencies between RML files are included in the ZIP file (i.e., if you include any RML files in your submission code, they should also be in your ZIP file). If these dependencies are not closed under the ZIP file, we will not be able to run your submission.