def test_dealer_does_not_deal_if_all_players_have_not_placed_ante(self): sut = table() player1 = player("one") player2 = player("two") sut.add_player(player1) sut.add_player(player2) player1.ante(1) sut.deal() self.assertFalse(sut.dealer.ready_to_deal) self.assertEqual(0, len(player1.current_hand)) self.assertEqual(0, len(player2.current_hand))
def test_table_dealer_ready_only_once_all_players_have_ante_wager(self): sut = table() player1 = player("one") player2 = player("two") sut.add_player(player1) sut.add_player(player2) self.assertFalse(sut.dealer.ready_to_deal) player1.ante(1) self.assertFalse(sut.dealer.ready_to_deal) player2.ante(1) self.assertTrue(sut.dealer.ready_to_deal)
def test_dealer_not_ready_to_show_hand_until_all_players_have_play_wager_or_fold(self): sut = table() player1 = player("one") player2 = player("two") sut.add_player(player1) sut.add_player(player2) player1.ante(1) player2.ante(1) sut.deal() self.assertFalse(sut.dealer.ready_to_show_hand) player1.play(1) self.assertFalse(sut.dealer.ready_to_show_hand) player2.fold() self.assertTrue(sut.dealer.ready_to_show_hand)
def rungame(): print "----- ---- THREE CARD POKER ---- ---- ----" game_table = table() player_count = "" while not player_count.isdigit(): player_count = raw_input("Enter number of players: ") if player_count.isdigit(): if int(player_count) > 7: print "Maximum of 7 players." player_count = "" continue for i in range(1, int(player_count) + 1): player_name = raw_input("Enter player #%d name: " % i) new_player = player(player_name) game_table.add_player(new_player) for p in game_table.players: ante = "" while not ante.isdigit(): ante = raw_input("Enter ante wager amount for %r: " % p.name) if not ante.isdigit(): print "Enter a number for ante wager amount." else: p.ante(int(ante)) game_table.deal() for p in game_table.players: p.play(p.current_ante_wager) for result in game_table.show_hands(): print result
def test_added_players_current_table_matches_game_table(self): sut = player("test") tbl = table() tbl.add_player(sut) self.assertIsNotNone(sut.current_table) self.assertEqual(1, len(tbl.players)) self.assertEqual(1, len(sut.current_table.players))
def test_table_dealer_deals_itself_when_player_ready(self): sut = table() player1 = player("one") sut.add_player(player1) player1.ante(1) sut.deal() self.assertIsNotNone(sut.dealer.current_hand) self.assertEqual(3, len(sut.dealer.current_hand))
def test_table_show_hands_will_evaluate_player_hand(self): sut = table() player1 = player("one") sut.add_player(player1) player1.ante(1) sut.deal() player1.play(1) sut.show_hands() self.assertTrue(sut.dealer.hand_shown) self.assertTrue(player1.hand_shown) self.assertIsNotNone(player1.hand_result)
def run(self, conn, pkt): name = pkt.name password = pkt.password print "login", name, password import network pkt_back = network.packet.packet(network.events.MSG_SC_LOGIN, status = 0, err = "") if not name in users: print "no such user", name pkt_back.err = "no such user" conn.send_packet(pkt_back) return if users[name] != password: print "password error", password, users[name] pkt_back.err = "password error" conn.send_packet(pkt_back) return import game.controller gcontroller = game.controller.gcontroller if name in gcontroller.Players: print "already login", name pkt_back.err = "already login" conn.send_packet(pkt_back) return # build data import player_data.player_data d = player_data.player_data.load(name) d.name = name import game.player as player ply = player.player(d, conn) # save in gcontroller.Players gcontroller.Players[name] = ply # send back success pkt_back.status = 1 conn.send_packet(pkt_back)
def test_placing_ante_wager_at_table_notifies_dealer(self): sut = table() test_player = player("test") sut.add_player(test_player) test_player.ante(1) self.assertTrue(sut.dealer.ready_to_deal)
def test_adding_players_to_the_table(self): sut = table() sut.add_player(player("one")) sut.add_player(player("two")) self.assertEqual(2, len(sut.players))