CellSplit is a 2D multiplayer game where you play as a cell that can grow and attack other cells. This provides a great sandbox for experimenting with coding of simple bots. There are only a few rules:
The game includes a live coding environment for coding your own bots:
The main window contains the source code of the script. It is written in
FixScript language. It has
familiar C-like syntax and shouldn't be hard to pickup. Whenever you edit the code
it is instantly being run. The global variables are preserved, you can also reset it
by pressing Ctrl+R
to restart it.
On the right is the log panel, you can use it to print the content of your variables
and objects by using the log
and dump
functions. It is recommended
to use clear_log
function to clear the log for every update. You can manually
clear the log by pressing Ctrl+L
.
You can use a code completion popup by pressing Ctrl+Space
. It allows you to
complete keywords and functions as well as already existing names in your script.
To actually run the default bot code uncomment a call to set_target
at the
bottom. Otherwise you're just controlling the cells with your mouse as in a normal game.
Functions:
log(value)
- logs the value to the log panel on the rightdump(value)
- logs the structure of the value to the log panel on the rightclear_log()
- clears the logmark(pos: Vector)
- marks a position (using Vector
class)mark(x: Float, y: Float)
- marks a position (using x
and y
coordinates)mark(pos: Vector, name: String)
- marks a position with a name (using Vector
class)mark(x: Float, y: Float, name: String)
- marks a position with a name (using x
and y
coordinates)get_pellets(): [Pellet]
- returns a packed array of pelletsget_cells(): Cell[]
- returns an array of all visible cells in your fieldget_own_cells(): Cell[]
- returns an array of all your cellsget_enemy_cells(): Cell[]
- returns an array of all enemy cellsget_virus_cells(): Cell[]
- returns an array of all virus cellsget_cells_by_name(name: String): Cell[]
- returns an array of cells with given nameget_cell_by_id(id: Integer): Cell
- returns a cell with given id
or null
mass_to_size(mass: Float): Float
- converts mass to size (radius)size_to_mass(size: Float): Float
- converts size to massget_average_position(): Vector
- gets an average position of your cellsget_average_position(cells: Cell[]): Vector
- gets an average position of the provided cellsget_position_of_most_pellets(): Vector
- returns a position of the most pellets nearby your average position of your cellsget_position_of_most_pellets(pos: Vector): Vector
- returns a position of the most pellets nearby (using a different origin position)set_target(pos: Vector)
- sets the target position for your cells (if not called in an update it allows you to control the cells by your mouse)set_target(x: Float, y: Float)
- sets the target position for your cells using the coordinatesreset()
- merges your cells into a single cell with the same massreset(mass: Float)
- merges your cells into a single cell and set the given masssplit()
- splits your cellseject_mass()
- ejects mass from your cellsClasses:
Vector stores either a vector or a position as two coordinates (x & y).
It has support for these operators:
+
,
-
,
*
,
/
,
+=
,
-=
,
*=
and
/=
(between Vectors and scalars for multiplication/division). You can also use the short-hand
variants of the constructors: Vector()
and Vector(x: Float, y: Float)
.
x: Float
- the x
coordinatey: Float
- the y
coordinatecreate(): Vector
- creates an empty vectorcreate(x: Float, y: Float): Vector
- creates a vector with given coordinatesclone(): Vector
- returns a clone of the vectorset(vec: Vector)
- sets the vector to the values of another vectorset(x: Float, y: Float)
- sets the vector valuesadd(vec: Vector)
- adds another vector to this vectoradd(dx: Float, dy: Float)
- adds given values to this vectorsub(vec: Vector)
- subtracts another vector from this vectorsub(dx: Float, dy: Float)
- subtracts given values from this vectormul(value: Float)
- multiplies the vector with given valuediv(value: Float)
- dividies the vector with given valuenormalize()
- normalizes the vectorget_normalized(): Vector
- returns a normalized vector (the original vector is unchanged)length(): Float
- returns the length of the vectorlength_sqr(): Float
- returns the length of the vector squared (it is cheaper and sufficient for comparison etc.)to_string(): String
- returns a string representation of the vectorCell represents information about individual cell.
id: Integer
- unique ID of the celltype: Integer
- type of the cell (either CELL_PLAYER, CELL_VIRUS or CELL_EJECTED_MASS)x: Float
- the x
coordinate of the celly: Float
- the y
coordinate of the cellsize: Float
- the size of the cell (radius)mass: Float
- the mass of the cellcolor: Integer
- color of the cell (in RGB format using bit shifting)name: String
- name of the cell (or null
if it has no name)own: Boolean
- true
for own cellscreate(): Cell
- creates an empty cell descriptorget_position(): Vector
- returns the position as a vector
Pellet represents a single pellet. It is a structure not a class. It can be used only in a packed
array and has specific rules to work with.
You can avoid working with it by using the get_position_of_most_pellets
function.
id: Integer
- unique ID of the pelletx: Float
- the x
coordinate of the pellety: Float
- the y
coordinate of the pelletsize: Float
- the size of the pellet (radius)color: Integer
- color of the pellet (in RGB format using bit shifting)There are some common strategies:
To play you can either directly run it in a browser or download the game for Windows or Linux.
Once in the game, choose Bot Test from the main menu. Saving and loading is currently not
implemented, but it's as easy as copying the code using a clipboard. Uncomment a call to set_target
at the bottom of the script to control the cells by the code.
The support for running the bots in the browser is currently experimental, it is preferred to use the native application for the full experience.