Code Page
BOTWORLD
Cooperative Agent Project

People

Dan Ashlock
Julie Dickerson

Contents


Code links(top)

You will need all eight of the above files to compile the demos JDherb?.cpp.

The compile for the GNU compiler is:


g++ -lm -O3 -0 demo.exe JDherb1.cpp inttree.cpp intGPA.cpp botworld.cpp


Explaination(top)

Botworld is a rectangular grid with a wall at its boundaries. Each grid square may be empty, contain a box, or contain an agent (called a dozer). The agents are numbered 0 through (n-1) and the number of agents must be established when a botworld is created.

Methods permit the user to print the world, move agents, place boxes, and score the performance of agents. Methods take the index number of the agent they are to operate on. Collision detection and resolution is handled by permitting the user to only move one agent at a time (you want syncronous agents, you write the code).


Fields and Methods(top)

Constructors and Destructors (Up)

board()

This is the default constructor that creates a 0x0 world with no agents. This constructor is used in partnership with the Allocate method to create arrays of boards. Single boards are better created with the parameterized constructor, below.

board(int w,int h,int k)

This constructor creates a width w height h world with k agents. This constructor calls the Allocate method.

~board()

This destructor deallocates the space for the grid and the vectors of agent positions and headings. Typically it will be invoked automatically.

Board manipulation. (Up)

void board.Alloc(int w,int h, int k)

This method causes allocation to take place in an empy board, creating a width w height h world with k agents. Do not use it to create a world that has already been created because what you will create is a memory leak. You cannot, currently, change a world to a new size.

void board.Copy(board &bd)

This method copies the contents (grid, boxes, agents) from its argument to its owner. This requires both boards be the same size with the same number of agents. Copy does no allocation.

void board.Clear()

The Clear method removes all boxes from the board. It does not affect the placement or heading of the agents.

void board.MakeHerb(int bx)

The MakeHerb method places the agents in a random position and heading on the board and places bx boxes on the board as well in random starting positions. This is a valid herbivore problem starting board.

void board.MakeTar(int bx)

The MakeTar method places the agents in a random position and heading on the board and places bx boxes on the board as well in random starting positions. These boxes contain no close groups of four and start away from the walls. This is a valid Tartarus problem starting board.

void board.MakeNorth()

The MakeNorth method places the agent (there should be only one) and a single box int he starting configuration for the North Wall builder problem.

Input/Output, well, output (Up)

void board.print(ostream &aus)

The print method dumps a character representation of the board to an output stream. "B.print(cout);" will send an image of the board to the standard output.

Sensors (Up)

void board.LoadSensor(int *s,int dx)

The LoadSensor method assumes that s is an array of eight real numbers. It loads the eight sensor values for agent number dx into s. The sensors report 0 for empty space, 1 for a box, and 2 for a wall. The sensors are arranged clockwise around the dozer:
            7 0 1
            6 ^ 2
            5 4 3
The sensor positions are relative to the dozer's heading.

void board.LoadSensorRP(int *s,int dx)

The LoadSensorRP method assumes that s is an array of ten real numbers. It may only be used if there are two agents present. It loads the eight sensor values for agent number dx into the first eight locations of s. The sensors report 0 for empty space, 1 for a box, and 2 for a wall. The sensors are arranged clockwise around the dozer:
            7 0 1
            6 ^ 2
            5 4 3
The sensor positions are relative to the dozer's heading. The last two sensors are loaded with the relative position of the other agent. These sensors report the relative position of the other agent as follows:
       
             left    in front     right
sensor 8:      0        1            2
             ahead   beside       behind
sensor 9:      0        1            2
void LoadSensorRP(int *s,int dx); //load a sensor array for agent dx

Moving the agents. (Up)

int board.LoadSensorRP(int mv,int ai)

The move method causes agent ai to make move mv. The moves are:
0 - turn left
1 - turn right
2 - attempt to move forward
3 - attempt to eat the box in front of the dozer
Turning is always possible. Moving forward is possible unless there is a wall or two consecutive boxes in front of the dozer. Eating either does nothing (if the square in front of the dozer is empty) or causes a box in front of the dozer to vanish. The integer value returned by the move method is the number of boxes eaten curing the move attempted, either 0 or 1. Summing the value of move during agent testing computes the herbivore problem score.

Scoring (Up)

int board.ScoreTar()

The ScoreTar method returns the tartarus score of a board. This is one point per box side against a wall.

int board.ScoreNorth()

The ScoreNorth method returns the north wall builder score of a board. This is one point per grid square with a box on it or north of it.