Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Remote control

Nguyễn Gia Phong edited this page Mar 5, 2018 · 14 revisions

Brutal Maze provides a INET (i.e. IPv4), STREAM (i.e. TCP) socket server which can be enabled in the config file or by adding the --server CLI flag. After binding to the given host and port, it will wait for a client to connect. Then, in each cycle of the loop, the server will send current details of each object (hero, walls, enemies and bullets), wait for the client to process the data and return instruction for the hero to follow. Since there is no EOT (End of Transfer) on a socket, messages sent and received between server and client must must be strictly formated as explained below.

Server output

First, the game will export its data to a byte sequence (which in this case, is simply a ASCII string without null-termination) of the length n. Before sending the data to the client, the server would send the number n padded to 8 digits.

Below is the meta structure of the data:

<Map height (nh)> <Number of enemies (ne)> <Number of bullets (nb)> <Score>
<nh lines describing visible part of the maze>
<One line describing the hero>
<ne lines describing ne enemies>
<nb lines describing nb bullets>

The maze

Visible part of the maze with the width nw and the height nh will be exported as a bit (0 and 1) map of nh lines and nw columns. For example, the bit map and the picture below show the same part of a maze:

000000000000000011111000000
000000000000000011111000000
000000000000000011111000000
100000111111111111111111111
100000111111111111111111111
100000111111111111111111111
100000111111111111111111111
100000111111111111111111111
100000000000000000000000001
100000000000000000000000001
100000000000000000000000001
100000000000000000000000001
100000000000000000000000001
100000111110000011111000001
100000111110000011111000001
100000111110000011111000001
100000111110000011111000001
100000111110000011111000001
100000111110000011111000001
100000111110000011111000001
100000111110000011111000001

Blank map exmple

To avoid floating point number in later description of other objects, each cell represent by a number 0 or 1 will have the width (and height) of 100, which means the top left corner of the top left cell will have the coordinates of (0, 0), and the bottom right vertex of the bottom right cell will have the coordinates of (nw*100 - 1, nh*100 - 1).

The hero

6 properties of the hero are exported in one line, separated by 1 space, in the following order:

  • Hero's color indicating the current HP of the hero, as shown in in the later section.
  • X-coordinate, which will be in the range [0, nw * 100], casted to an integer.
  • Y-coordinate, which will be in the range [0, nh * 100], casted to an integer. Note that the y-axis points up-side-down instead of pointing upward.
  • Angle of the direction the hero is pointing to in degrees, casted to a nonnegative integer (from 0 to 360). Same note as above (the unit circle figure might help you understand this easier).
  • Flag showing if the hero can strike an attack, 0 for no and 1 for yes.
  • Flag showing if the hero can heal, 0 for no and 1 for yes.

Unit circle

The enemies

Each enemy exports these properties:

  • Color indicating the current HP of the enemy, as shown in the table below.
  • X-coordinate, which will be in the range [0, nw * 100], casted to an integer.
  • Y-coordinate, which will be in the range [0, nh * 100], casted to an integer.
  • Angle of the direction the hero is pointing to in degrees, casted to a nonnegative integer (from 0 to 360).

To shorten the data, each color (in the Tango palette) is encoded to a lowercase letter or number 0. Different shades of a same color indicating different HP of the characters.

| HP | 5 | 4 | 3 | 2 | 1 | 0 | | Butter | | | a | b | c | 0 | | Orange | | | d | e | f | 0 | | Chocolate | | | h | i | j | 0 | | Chameleon | | | j | k | l | 0 | | Sky Blue | | | m | n | o | 0 | | Plum | | | p | q | r | 0 | | Scarlet Red | | | s | t | u | 0 | | Aluminium | v | w | x | y | z | 0 |

Flying bullets

  • Color indicating the potential damage of the bullet, encoded similarly to characters', except hero's bullets only have 4 colors vwx0.
  • X-coordinate, which will be in the range [0, nw * 100], casted to an integer.
  • Y-coordinate, which will be in the range [0, nh * 100], casted to an integer.
  • Angle of the bullet's flying direction in degrees, casted to a nonnegative integer (from 0 to 360).
Clone this wiki locally