Board Module

This module implement a class (Board.Board) for Bomberman board, which is basically a matrix of states, represented with the class Board.State.

Specials states:

  • empty – an empty spot, with NOTHING on it.
  • dmur – a destructible wall, with JUST the wall on it.
  • umur – an undestructible wall, with JUST the wall on it.
  • expl – an empty spot, with JUST an explosion tag on it.

Warning:

Warning

Use those constants state only with copy.copy(..).
overwise it will work with references over those constants.

Example :

>>> for i, j, spot in board:
>>>  spot=Board.empty

All spots of [board] are now the same, so all modification like

>>> board[i,j].explosion=True
will be done on ALL spot of [board].
And that’s not what we want to.
Board.UTFSupported = True

Try to know if the encoding is UTF-8 supported.

class Board.State(wall=True, destr=False, bomb=None, players=[], explosion=False, bonus=None)[source]

A Class for the element of the board.

Attributes:
  • wall – True if the case is a wall, false if it is empty (ie : can be occupyed by a player, or/and a bomb, or/and a bonus).
  • destr – True or False, if the case can be destroy (CONVENTION: a piece of wall is destroid in one explosion).
  • bomb – A Bomb.Bomb instance (no need for more than 1).
  • players – List of Player.noPlayer if there is a player, a Player.Player instance if there is one.
  • explosion – A boolean for a visual effect of an explosion !
  • bonus – None if there is no bonus, or a Bonus.Bonus instance if there is one (only one bonus in a state).

This class can be used both by the client and the server. But, for the server each players in the attribute players are instances of Player.PlayerServer; and for the client, the client’s player is a Player.Player instance, and all other players are Player.Player.

__init__(wall=True, destr=False, bomb=None, players=[], explosion=False, bonus=None)[source]

Simple constructor of state, assigned with default value (an undestructible piece of wall). Each parameters can be directly assigned.

For example, myState=State(wall=False, players=[myself]) return a State initializing as containing the player [myself].

wall = None

True if the case is a wall, false if it is empty (ie : can be occupyed by a player, or/and a bomb, or/and a bonus).

destr = None

True or False, if the case can be destroy (CONVENTION: a piece of wall is destroid in one explosion).

bomb = None

A Bomb.Bomb instance (no need for more than 1).

players = None

List of Player.noPlayer if there is a player, a Player.Player instance if there is one.

explosion = None

A boolean for a visual effect of an explosion !

bonus = None

None if there is no bonus, or a Bonus.Bonus instance if there is one (only one bonus in a state).

to_send()[source]

This method is imported from ParseMessageOut.

is_free() → True|False[source]

Determine if a player can be placed in the spot self.

strNoUtf()[source]

Simple transformation of a state to a universal (no UTF, only ASCII) string of 3 caraters.

strUtf()[source]

Simple transformation of a state to a non ASCII (i.e. with UTF caracters) string of 3 caraters. For a wall, 3 grey blocks if it can be brocken, or 3 black blocks. For an explosion, a little sun is used.

If those caracters do not seems pretty, try to change the encoding used here to UTF-8.

Sorry, I didn’t succeed in putting those caracters here in this docstring, because pyDoc doesn’t have compatibility with UTF8.
And I like pyDoc. I really do :) By the way, I wrote the script makePydoc.sh. Take a look !
__str__(self) <=> str(self) → 'str'[source]

Generic conversion to a string, choose an UTF8 representation if it is available.

__repr__()[source]

Toplevel representation of [self], is str(self).

__eq__(s)[source]

self.__eq__(s) <==> s == self

hit(ingury=1)[source]

Destroy the element in case [self] with [ingury] damages.

Cases:
  • If it’s a destructible wall, break it, return SIGNAL_WALL_BREAKE=2.

  • If it’s a undestructible wall, break it, return SIGNAL_WALL_NOT_BREAKE=4.

  • If it’s a bomb, destroy it, return SIGNAL_BOMB_HURT.

  • If it’s a player, hurt it with [ingury] ingury(ies), return SIGNAL_PLAYER_HURT=3.

    The player in this case can die, raising Player.PlayerDeath.

Board.empty = wall=False; destr=False; bomb=None; players=[]; bonus=None; explosion=False

An empty spot, with NOTHING on it.

Board.dmur = wall=True; destr=True; bomb=None; players=[]; bonus=None; explosion=False

A destructible wall, with JUST the wall on it.

Board.umur = wall=True; destr=False; bomb=None; players=[]; bonus=None; explosion=False

An undestructible wall, with JUST the wall on it.

Board.expl = wall=False; destr=False; bomb=None; players=[]; bonus=None; explosion=True

An empty spot, with JUST an explosion tag on it.

class Board.Board(state=wall=True; destr=False; bomb=None; players=[]; bonus=None; explosion=False, lx=19, ly=19, nb=8, maxStr=3, utf=True)[source]

A Class to define a Bomberman board.

Attributes:
  • lx – his dimension over horizontal axe x.
  • ly – his dimension over vertical axe y.
  • nb – max number of player, (for usual boards, it’s 4).
  • mat – the map of State instances, coded as a matrix.
For call convention, take a look at [Matrix] module. [mat.box] will be used for printing, so it can be modified by other stuff.

This class can be used both by the client and the server.

__init__(state=wall=True; destr=False; bomb=None; players=[]; bonus=None; explosion=False, lx=19, ly=19, nb=8, maxStr=3, utf=True)[source]

Simple constructor of an empty board. Contains a [map] attribute initialized with all elements equal to a copy of [state]. The board is a rectangle, of length [lx] over [ly]. [maxStr] is passed throw the underlying matrix, and will be used for printing (see Matrix.tostr). [utf] is true to use non ASCII caracters for printing the matrix, false otherwise.

lx = None

his dimension over horizontal axe x.

ly = None

his dimension over vertical axe y.

nb = None

max number of player, (for usual boards, it’s 4).

mat = None

the map of State instances, coding as a matrix (ie. Matrix.Matrix instance).

bombs()[source]

Simply return a list of Bomb.Bomb associated with their position. Example : [(0,1,<bomb>), (1,3,<bomb>)]

FIXME: it shall be useless now.

players()[source]

Simply return a list of Player.Player associated with their position.

str_of_players(pl)[source]

This method is imported from ParseMessageOut.

__str__()[source]

Transformation to a string, using Matrix.Matrix.__str__ method.

__repr__()[source]

Toplevel representation of a Board, to a string.

__getitem__((i, j))[source]

A shortcut to self.mat[i,j]. Allow self[i,j].

__setitem__((i, j), val)[source]

A shortcut to self.mat[i,j]=val Allow self[i,j] = v.

__contains__(u)[source]

self.__contains__(u) <==> u in self

__eq__(b)[source]

self.__eq__(b) <==> b == self

fill(val)[source]

Set all state of the board to [val].

destroy_bomb(i, j, toc=1, radius=4, print_on_all=None, str_of_blowbomb=None, list_clients=None, origin=None, FORCE=False, verb=False)[source]

Just decrease the timer of the bomb in the board[i,j], [toc] is the time spent during ticking.

FIXME: make sure it spreads from the spot, in the right direction. Seems ok.

FORCE is here to allow the destruction of a bomb even if its timer is not ok...

Warning

This function is quite long, make sure it works correctly !

tic(toc=1, MAKE_DESTROY=True, verb=False, FORCE=False, print_on_all=None, str_of_blowbomb=None, list_clients=None, origin=None)[source]

Just decrease the timer of all bombs in the board, [toc] is the time spent during ticking. MAKE_DESTROY is here to allow ticking the board without triggering any explosion.

Because for the client, timers are just for priting.

Call destroy_bomb whenever it is needed (i.e. when a timer is going non positive (<= 0).)

__iter__()[source]

Special method to allow an iteration with a board.

Warning

This seems to be wrong, use board[i,j] and not spot, if you want to modify board[i,j].
Example:
>>> for i,j,spot in board:
>>>  spot.destr=False; spot.wall=False; spot.explosion=True
>>>  print "Spot at place (%i, %i)" % (i,j)
The map is explored from (0,0) to (self.lx - 1, self.ly - 1),
LINE by LINE (x loop first) then COLUMN by COLUMN (then y loop).
class Board.IterBoard(board)[source]

A class for build an iterator for Board.

It’s mainly done here to learn about iterator. This workaround allow the following shortcut :

Example:
>>> for i,j,spot in board:
>>>  spot.destr=False; spot.wall=False; spot.explosion=True
>>>  print "Spot at place (%i, %i)" % (i,j)
This is useful, to avoid double loop with i, j.
And moreover, this is interesting from the user : write ‘for spot in board’ is intuitive.
__init__(board)[source]

A wrapper around Board.Board class to build an iteratoir for a map.

board = None

the board used for iteration

i = None

current value of i (over axis x)

j = None

current value of j (over axis y)

next()[source]

Iterator for Board.Board !

Table Of Contents

Previous topic

Player Module

Next topic

KeyBinding Module

This Page