ParseMessageOut Module

This module implement a simple wrapper for output messages (send by clients or server). It respect the semantics about the communications (this document is available here specification_slides).

Basically, it a collection of mini pretty-printer.

It also provides the function try_pickling, to save datas from binary files (load them with ParseMessageIn.try_unpickling).

ParseMessageOut.PRINT_ALL_PARSEOUT = False

This can be erased by the module Constants to modify the global verbosity of this module

ParseMessageOut.try_pickling(data, info='(no info about the pickling was given)', verb=True, fn='savegame.ess')[source]

Save the datas data to the file fn.

This file will be erase if present, so be cautious. The file fn can then be load with ParseMessageOut.try_pickling.

The goal of info is to say what variables are picked (see the examples below).

If verb is here, this function print a log saying from which file datas are being read.

This function doesn’t handle exception, so be prudent with it.

Example:
>>> from ParseMessageIn import try_unpickling
>>> a, b, c = 0, 2.0, u"ok !" # Make a tuple.
>>> try_pickling((a,b,c)) # Save the tuple, in the default file (.datas_saved_by_picked_python.pkl).
>>> aa, bb, cc = try_unpickling(info="aa, bb, cc") # Load the tuple from the default file, and save it to (aa, bb, cc).

Warning:

Warning

All datas cannot be picked and upicked. Fore more details, see directly the documentation of the pickle module.

ParseMessageOut.str_of_state(state) → '0', '1', or '2'.[source]

The simpliest conversion from a state (Board.State) to a string.

Returned values:
  • ‘0’ for an empty spot.
  • ‘1’ for a destructible wall.
  • ‘2’ for a undestructible wall.
ParseMessageOut.str_of_players(board, pl) → ";p.pseudo ,p.x,p.y" sequence[source]
Simply return a string representing the list of Player.Player associated with their position.
All found players have to be in the list [pl].

Warning

Take care of the space between pseudo and the first ;.

ParseMessageOut.str_of_newplayer(player) → "NEW_PLAYER(player.pseudo)"[source]

Sent message by a new player when he try to connect to the server. Contains the pseudo of the player.

Can be unpack with ParseMessageIn.newplayer_of_str.

ParseMessageOut.str_of_newcolor(player) → "color=player.color"[source]

Sent message by a new player to annouce his color. Currently, not used by the server.

Can be unpack with ParseMessageIn.newplayer_of_str.

ParseMessageOut.str_of_move(move_to_send)[source]

Return a string representing an action (a move or dropping a bomb). The move_to_send string is one of ‘BOMB’, ‘LEFT’, ‘RIGHT’, ‘UP’, ‘DOWN’. From the client to the server.

Returned value :
  • PLANT_BOMB.
  • MOVE_LEFT.
  • MOVE_RIGHT.
  • MOVE_UP.
  • MOVE_DOWN.
ParseMessageOut.str_of_board_and_player(board, pl)[source]

Convert a game state (composed of a board [board], instance of Board.Board; and a list of players [pl], of Player.Player.). Of course, positions of players in [pl] have to be concording with states (State.State) of the board.

FIXME:
if lx and ly are not sent, they are constants. not very awesome isn’t it ?
ParseMessageOut.str_of_gameover(player) → "GAME_OVER(player.id)"[source]

Sent message by the server to announce the winner of the game, by refering to his [id]. For the player who have the same id is the winner, and the other lost.

Can be unpack with ParseMessageIn.gameover_of_str.

ParseMessageOut.str_of_posplantbomb(i, j) → "PLANT_BOMB(i,j)"[source]

Sent message by the server to announce that a bomb have been planted in the spot (i,j).

Can be unpack with ParseMessageIn.posplantbomb_of_str.

ParseMessageOut.str_of_blowbomb(i, j, radius) → "BLOW_BOMB(i,j,radius)"[source]

Sent message by the server to announce that a bomb have blowed up in the spot (i,j), with the radius [radius].

Can be unpack with ParseMessageIn.blowbomb_of_str.

ParseMessageOut.str_of_moveplayer(player) → "MOVE_PLAYER(player.id,player.x,player.y)"[source]

Sent message by the server to announce that a player have moved.

Can be unpack with ParseMessageIn.moveplayer_of_str.

Previous topic

ParseMessageIn Module

Next topic

ParseCommandArgs Module

This Page