MarioAI 0.4 API

This page lists the classes, fields and methods you may use to write a MarioAI agent.

All fields and methods below are public unless otherwise specified.

== package agents.controllers ==

abstract class MarioAIBase

All AI agent classes extend this base class, including the MyAgent class in the default package.

protected MarioEntity mario;
Information about Mario himself.
protected MarioInput lastInput;
The actions that were returned by actionSelectionAI() on the previous tick. You can use this field to determine whether a button is currently held down.
protected Entities entities;
Information about entities (moving objects) around Mario.
protected Tiles tiles;
Information about tiles around Mario.
abstract MarioInput actionSelectionAI()
The game calls this method on each tick to find out what action(s) Mario should take.
void debugDraw(VisualizationComponent vis, LevelScene level, IEnvironment env, Graphics g)
Draw debugging information. If you override this method, you should call super.debugDraw() to draw the default debugging information that appears when you press 'e'. You can then draw your own debugging information as you like.

== package engine.core ==

class Entities

An Entities object provides information about entities around Mario.

In methods in this class, parameters named (relMapX, relMapY) represent tile coordinates that are relative to Mario. In these coordinates, (0, 0) is Mario's position. The corners of the receptive field at at (-8, -8) and (8, 8).

List<Entity> allEntities;
A list of all entities within Mario's receptive field.
List<Entity> allAt(int relMapX, int relMapY)
Return a list of all entities at (relMapX, relMapY).
EntityType entityType(int relMapX, int relMapY)
Return the most dangerous entity type at (relMapX, relMapY).
boolean anything(int relMapX, int relMapY)
True if there is any entity at (relMapX, relMapY).
boolean nothing(int relMapX, int relMapY)
True if there is no entity at (relMapX, relMapY).
boolean danger(int relMapX, int relMapY)
True if there is anything dangerous at (relMapX, relMapY).
boolean dangerIn(int x1, int y1, int x2, int y2)
Return true if anything dangerous overlaps the given bounding box, which is in pixel coordinates relative to Mario's current position.

class Entity

An Entity is something that moves, such as an enemy monster. Mario himself is also an Entity.

EntityType type;
Type of the entity.
int dTX, dTY;
Position relative to Mario, in tiles.
float dX, dY;
Position relative to Mario, in pixels.
Speed speed;
Current speed vector in pixels per tick.
Sprite sprite;
A Sprite object containing this Entity's absolute position.

enum EntityType

A type of Entity. Values (with their grid codes) include

class MarioEntity extends Entity

An object representing Mario himself.

MarioMode mode;
Mario's current form: small, super (large), or fire.
boolean mayJump;
True if Mario may currently jump. Note that if you press the JUMP key while this field is false, Mario won't jump and will be unable to jump until the key is released!
boolean mayShoot;
True if Mario may currently shoot: he is in fire mode and there are not already 2 fireballs on the screen.
boolean onGround;
True if Mario is on the ground; false if he is in the air.
boolean carrying;
True if Mario is carrying a shell.
int timeLeft;
Remaining time in marioseconds.
int timeSpent;
Elapsed time in marioseconds.
int inTileX, inTileY;
X- and Y-positions of Mario within his tile.
boolean isJumping()
True if Mario is currently jumping (moving UP). If you keep holding down the JUMP button while Mario is in this state, he will jump higher.
boolean isFalling()
True if Mario is currently falling (moving DOWN).

class Speed

A speed vector in pixels per tick.

float x, y;

enum Tile

A type of Tile. Values (with their grid codes) include

class Tiles

An Tiles object provides information about tiles around Mario.

In methods in this class, parameters named (relMapX, relMapY) represent tile coordinates that are relative to Mario. In these coordinates, (0, 0) is Mario's position. The corners of the receptive field at at (-8, -8) and (8, 8).

Tile tile(int relMapX, int relMapY)
Return the tile at (relMapX, relMapY) .
boolean anyTile(int relMapX, int relMapY)
Return true if there is any tile at (relMapX, relMapY).
boolean emptyTile(int relMapX, int relMapY)
Return true if there is no tile at (relMapX, relMapY).
boolean brick(int relMapX, int relMapY)
Return true if (relMapX, relMapY) contains a brick or tube.
boolean brickIn(int x1, int y1, int x2, int y2)
Return true if any brick overlaps the bounding box with corners at (x1, y1) and (x2, y2), with x1 ≤ x2 and y1 ≤ y2.. These are pixel coordinates relative to Mario's current position.

== package engine.graphics ==

class VisualizationComponent

The user interface.

void drawLine(Graphics g, int x1, int y1, int x2, int y2, Color color)
Draw a line from (x1, y1) to (x2, y2), which are in pixel coordinates that are relative to Mario's current position. Color is a Java color such as Color.BLACK.
void drawRect(Graphics g, int x1, int y1, int x2, int y2, Color color)
Draw a rectangle with corners at (x1, y1) and (x2, y2), with x1 ≤ x2 and y1 ≤ y2. These are pixel coordinates that are relative to Mario's current position. Color is a Java color such as Color.BLACK.
static void drawString(Graphics g, String text, int x, int y, int color)
Draw a string at (x, y), which are absolute screen coordinates in tile units (i.e. units of 16 x 16 pixels). The upper-left coordinate is (0, 0). color is an index into a set of built-in colors: 0 = black, 1 = red, 2 = green, 3 = blue, 4 = yellow, 5 = magenta, 6 = cyan.
static void drawStringDropShadow(Graphics g, String text, int x, int y, int color)
Like drawString(), but draws a drop shadow around the text.

== package engine.input ==

class MarioInput

A set of input keys.

MarioInput()
Create an empty set of keys.
void press(MarioKey key)
Press a key in this set.

class MarioKey

Keys that can be pressed. Note that the SPEED key both sprints and shoots. If you want to shoot while sprinting, you must release the key for one tick and then press it again.

static final MarioKEY LEFT, RIGHT, DOWN, JUMP, SPEED;

== package engine.sprites ==

enum MarioMode

An enumeration of Mario's possible forms: small, super (large), or fire. Values include SMALL, LARGE, and FIRE_LARGE.

class Sprite

A Sprite holds positional information about an Entity.

float x;
Absolute X-position of the sprite's horizontal center, in pixel coordinates.
float y;
Absolute Y-position of the bottom of the sprite, in pixel coordinates.
float xOld, yOld;
The values of x and y on the previous tick.