Beispiel #1
0
    def handle_new(self, args, event):
        """ Create a new game. """
        log.debug("got new game event")

        if len(args) == 1:
            chan = args[0] if args[0][0] == "#" else "#" + args[0]
            self.connection.join(chan)
            self._to_chan(event, "Hanabot joined channel %s. /join %s and !new " "to begin game there." % (chan, chan))
            return

        if not self._check_args(args, 0, [], event, "new"):
            return

        nick = event.source.nick
        if event.target in self.games:
            self._to_nick(event, "There is already an active game in the channel.")
            return

        log.info("Starting new game.")
        self.games[event.target] = Game()
        self._display(GameResponse("New game started by %s. Accepting joins." % nick), event, notice=True)

        m = irc_markup()
        name = ""
        for i, c in enumerate("Hanabi"):
            name += m.color(c, m.Colors[i % len(m.Colors)])

        msg = "New game of %s starting in channel %s." % (name, event.target)
        for chan in self.home_channels:
            log.debug("game notification sent to %s: %s", event.target, msg)
            self.connection.notice(chan, msg)
Beispiel #2
0
    def __init__(self):
        '''
            Later may take variants as args so something.
        '''
        self.colors = ['red', 'white', 'blue', 'green', 'yellow'] 
        self._players = defaultdict(str)
        self._watchers = list()   # list of nicks
        # turn_order[0] is always current player's name
        self.turn_order = []
        self.max_players = 5

        # hist history for playback.
        self._hints = defaultdict(list)

        self.options = {
            'repeat_backs': { 'value': False, 'help': 'Toggle between using '
                             'A-E and A-Z for card backs.' },
            'solvable_rainbow_5': {'value': True, 'help': 'If True, do not '
                                   'allow the rainbow 1, 2, 3, or 4 to be on '
                                   'the bottom of the deck.'}
        }

        self.notes_up, self.notes_down = ('w', 'b')
        self.notes = [self.notes_up for i in range(8)]
        self.storms_up, self.storms_down = ('X', 'O')
        self.storms = [self.storms_down for i in range(3)]
        
        self.markup = irc_markup()

        # The deck is Cards with color and count distributions shown, shuffled.
        self.deck = [Card(c, n) for c in self.colors
                     for n in self.card_distribution]
        random.shuffle(self.deck)

        self._playing = False
        self._game_over = False
        self._rainbow_game = False  # True if using rainbow (multicolor) cards.

        self._game_type = 'standard'  # different if rainbow. set in start_game()

        # table is a dict of lists of cards, indexed by color. 
        self.table = defaultdict(list)

        # discards is just a set of numbers (1-5) indexed by color.
        self.discards = defaultdict(list)

        # last_round set to 0 when deck is empty and incremented each turn
        # when last_round == num players, the game is over.
        self.last_round = None
Beispiel #3
0
 def __init__(self, color, number, mark=None):
     self.color = color
     self.number = number
     self.mark = mark
     self.markup = irc_markup()