def setUpGame(self): self.game = Game() self.game.markup = xterm_markup() for p in players: self.game.add_player(p) for c in self.game.deck: c.markup = xterm_markup() self.game.start_game(players[0]) self.game.turn_order = list(players)
def test_handmgt(self): p = Player(players[0]) p.hand = [Card('red', i, b) for i, b in zip(xrange(1,6), uppercase[:5])] for c in p.hand: c.markup = xterm_markup() self.assertEqual('ABCDE', self.getBacks(p.hand)) print p.swap_cards('A', 'E') self.assertEqual('EBCDA', self.getBacks(p.hand))
def test_rainbow_display(self): p = Player(players[0]) p.hand = [Card('rainbow', i, b) for i, b in zip(xrange(1,6), uppercase[:5])] m = xterm_markup() print m.color('hello world', xterm_markup.RAINBOW) self.game = Game() self.game.markup = m for p in players: self.game.add_player(p) for c in self.game.deck: c.markup = xterm_markup() self.game.start_game(players[0], opts={'rainbow_10': True}) self.game.turn_order = list(players) for n, l in [(1, 'A'), (2, 'B'), (3, 'C')]: c = Card(text_markup_base.RAINBOW, n, l) c.markup = self.game.markup self.game._players[self.game.player_turn()].hand[n-1] = c self.game.play_card(self.game.player_turn(), 'A') self.game.play_card(self.game.player_turn(), 'A') print self.game.play_card(self.game.player_turn(), 'B')
def test_unsolvable_rainbow_5(self): game = Game() game.markup = xterm_markup() for p in players: game.add_player(p) for c in game.deck: c.markup = xterm_markup() opts = {'rainbow_5': True} game.options['solvable_rainbow_5'] = True bad_card = Card('rainbow', 1) bad_card.markup = xterm_markup() game.deck[len(game.deck)-1] = bad_card last_card = game.deck[len(game.deck)-1] print '\nlast card before: %s' % last_card game.start_game(players[0], opts) last_card = game.deck[len(game.deck)-1] print 'last card after: %s' % last_card self.assertFalse(last_card.color == 'rainbow' and last_card.number in [1,2,3,4])
def test_lastround(self): # Make the deck have one card, let a player discard. # Then make sure each player (inc. initial one) gets one # more turn. self.setUpGame() self.game.deck = [Card('red', 1, 'A')] self.game.options['repeat_backs']['value'] = True for c in self.game.deck: c.markup = xterm_markup() self.game.discard_card(self.game.player_turn(), 'A') for i in xrange(len(players)): self.assertFalse(self.game.game_over()) print self.game.discard_card(self.game.player_turn(), 'A') self.assertTrue(self.game.game_over())
#!/usr/bin/env python """ Just test for simple syntax and edge case errors by running through a few scenarios. """ import os import sys sys.path.insert(0, os.path.join(sys.path[0], "..")) from string import uppercase from hanabi import Game, Player, Card from text_markup import xterm_markup # tell the cards to color for xterm Card.markup = xterm_markup() def display(gr): print "------------------" if not gr: print "Response invalid." else: for message in gr.public: print "channel: %s" % message for nick, messages in gr.private.iteritems(): for message in messages: print "%s: %s" % (nick, message)