Exemple #1
0
def is_first_player(room_name):
    """Returns True if we are the first player (connected first to the server).

    First we try to get from `game/<room_name>/first` mailbox. 

    If something is there, we are the second player, and need to signal to the first in `game/<room_name>/second` mailbox.

    If not, we are the first player, and put something there (to signal for the other player).
    """
    first_room = 'game/%s/first' % room_name
    value = sm.get_one(first_room)

    if value is None:
        # we are first
        sm.put(first_room, 'we-are-first')  # doesn't matter what we put
        return True
    else:
        # we are second
        sm.put('game/%s/second' % room_name, 'we-are-second')
        return False
Exemple #2
0
def send_move(room_name, box_name, move):
    """Sends a move to `game/<room_name>/move_<box_name>` mailbox"""
    sm.put('game/%s/move_%s' % (room_name, box_name), move)
Exemple #3
0
import smor.client as sm

sm.config('localhost')
sm.put('A', 1)
sm.put('A', 2)
print('got:', sm.get_one('A'))
sm.put('A', 3)
print('got:', sm.get_all('A'))
sm.put('A', 4)
print('got:', sm.get_all('A'))
print('got:', sm.get_all('A'))