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).
This can be erased by the module Constants to modify the global verbosity of this module
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.
The simpliest conversion from a state (Board.State) to a string.
Warning
Take care of the space between pseudo and the first ;.
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.
Sent message by a new player to annouce his color. Currently, not used by the server.
Can be unpack with ParseMessageIn.newplayer_of_str.
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.
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.
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.
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.