def test_playable_to_tableau(self): field = rb.Field(1) initial_card = rb.Card(13, 2, True) final_card = rb.Card() self.assertTrue(field.playable_to_tableau(initial_card, final_card), msg='Disallows valid move') suit_pairs = [[0, 1], [0, 3], [1, 2]] for pair in suit_pairs: initial_card = rb.Card(10, pair[0], True) final_card = rb.Card(11, pair[1], False) self.assertTrue(field.playable_to_tableau(initial_card, final_card), msg='Disallows valid move') suit_pairs = [[0, 0], [0, 2], [1, 1], [1, 3], [2, 2], [3, 3]] for pair in suit_pairs: initial_card = rb.Card(10, pair[0], True) final_card = rb.Card(11, pair[1], False) self.assertFalse(field.playable_to_tableau(initial_card, final_card), msg='Allows invalid move') initial_card = rb.Card(5, 0, False) final_card = rb.Card(8, 1, False) self.assertFalse(field.playable_to_tableau(initial_card, final_card), msg='Allows invalid move')
def test_errors(self): field = rb.Field(1) self.assertEqual(field.move_card(12, 12, 0), 1, msg='Allows move to same position') self.assertEqual(field.move_card(-1, 12, 0), 2, msg='Allows positions out of range') self.assertEqual(field.move_card(20, 12, 0), 2, msg='Allows positions out of range') self.assertEqual(field.move_card(12, -1, 0), 2, msg='Allows positions out of range') self.assertEqual(field.move_card(12, 20, 0), 2, msg='Allows positions out of range') self.assertEqual(field.move_card(5, 12, 0), 3, msg='Allows banks as initial position') self.assertEqual(field.move_card(12, 1, 0), 3, msg="Allows move to player's decks") initial_card = 12 field.pop_card(initial_card, 0) field.pop_card(initial_card + 1, 0) self.assertEqual(field.move_card(initial_card, initial_card + 1, 0), 4, msg='Allows empty initial card') field.push_card(initial_card, 0, rb.Card(5, 0, True)) field.push_card(initial_card + 1, 0, rb.Card(6, 0, True)) self.assertEqual(field.move_card(initial_card, initial_card + 1, 0), 5, msg='Allows illegal move')
def test_playable_to_player(self): field = rb.Field(1) initial_card = rb.Card(6, 1, False) final_card = rb.Card(5, 1, True) self.assertTrue(field.playable_to_player(initial_card, final_card), msg='Disallows valid move') initial_card = rb.Card(5, 1, False) final_card = rb.Card(6, 1, True) self.assertTrue(field.playable_to_player(initial_card, final_card), msg='Disallows valid move') initial_card = rb.Card(4, 3, False) final_card = rb.Card() self.assertFalse(field.playable_to_player(initial_card, final_card), msg='Allows invalid move') initial_card = rb.Card(5, 1, False) final_card = rb.Card(6, 2, True) self.assertFalse(field.playable_to_player(initial_card, final_card), msg='Allows invalid move') initial_card = rb.Card(4, 3, False) final_card = rb.Card(6, 3, False) self.assertFalse(field.playable_to_player(initial_card, final_card), msg='Allows invalid move')
def test_playable_to_bank(self): field = rb.Field(1) initial_card = rb.Card(1, 0, False) final_card = rb.Card() self.assertTrue(field.playable_to_bank(initial_card, final_card), msg='Disallows valid move') initial_card = rb.Card(2, 0, True) final_card = rb.Card(1, 0, False) self.assertTrue(field.playable_to_bank(initial_card, final_card), msg='Disallows valid move') initial_card = rb.Card(2, 0, False) final_card = rb.Card() self.assertFalse(field.playable_to_bank(initial_card, final_card), msg='Allows invalid move') initial_card = rb.Card(3, 0, False) final_card = rb.Card(1, 0, True) self.assertFalse(field.playable_to_bank(initial_card, final_card), msg='Allows invalid move') initial_card = rb.Card(2, 1, False) final_card = rb.Card(3, 1, True) self.assertFalse(field.playable_to_bank(initial_card, final_card), msg='Allows invalid move') initial_card = rb.Card(5, 2, True) final_card = rb.Card(4, 1, True) self.assertFalse(field.playable_to_bank(initial_card, final_card), msg='Allows invalid move')
def test_to_waste(self): field = rb.Field(1) initial_card = 12 final_card = 3 field.push_card(final_card, 0, rb.Card(5, 0, True)) field.push_card(initial_card, 0, rb.Card(6, 0, False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 0, msg='Cannot move to waste') field.push_card(initial_card, 0, rb.Card(5, 0, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 0, msg='Cannot move to waste') field.push_card(initial_card, 0, rb.Card(1, 0, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to waste') field.push_card(initial_card, 0, rb.Card(4, 1, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to waste')
def test_to_stock(self): field = rb.Field(1) initial_card = 12 final_card = 2 field.push_card(final_card, 0, rb.Card(5, 0, True)) field.push_card(initial_card, 0, rb.Card(6, 0, False)) field.push_card(initial_card + 1, 0, rb.Card(5, 0, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 0, msg='Cannot move to stock') self.assertEqual(field.move_card(initial_card + 1, final_card, 0), 0, msg='Cannot move to stock')
def main(): field = rb.Field(random.randint(1, 1000000)) # First player player = 0 if random.random() < 0.5: player = 1 single_player = False while True: value = input("How many players? (1 or 2) ") if value == "1": single_player = True break elif value == "2": break else: print("Invalid input") print("\n" * 55) robot = rb.Player(field) is_shown = False while True: check_game_done(field) display(field, 2) if not single_player or player == 0: while True: value, player, is_shown = get_move(field, player, is_shown) if value: robot.start_turn() break else: robot.set_field(field) value = robot.move() field = robot.get_field() status = 2 if robot.is_hand_in_hand(): status = 1 display(field, status) sys.stdout.write("\x1b7\x1b[15;0f") sys.stdout.flush() input("Player 1's move: {0}".format(value)) sys.stdout.write( "\x1b7\x1b[15;0f ") sys.stdout.flush() if robot.end(): player = 0
def test_to_tableau(self): field = rb.Field(1) initial_card = 12 final_card = 13 cards = [[12, 1], [11, 2], [10, 3], [9, 0]] field.push_card(final_card, 0, rb.Card(13, 0, True)) for i in range(len(cards)): field.push_card(initial_card, 0, rb.Card(cards[i][0], cards[i][1], False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 0, msg='Cannot move to tableau') initial_card = 12 final_card = 14 field.pop_card(final_card, 0) field.push_card(initial_card, 0, rb.Card(2, 0, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 0, msg='Cannot move to tableau') initial_card = 14 final_card = 15 card_suits = [[0, [0, 2]], [1, [1, 3]]] for i in range(2): field.push_card(final_card, 0, rb.Card(13, card_suits[i][0], True)) for j in range(len(card_suits[i][1])): field.push_card(initial_card, 0, rb.Card(12, card_suits[i][1][j], False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to tableau') initial_card = 16 final_card = 17 field.push_card(final_card, 0, rb.Card(7, 1, False)) field.push_card(initial_card, 0, rb.Card(5, 0, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to tableau') field.push_card(initial_card, 0, rb.Card(7, 0, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to tableau') field.push_card(initial_card, 0, rb.Card(8, 0, True)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to tableau')
def test_to_bank(self): field = rb.Field(1) initial_card = 12 final_card = 7 field.push_card(initial_card, 0, rb.Card(1, 0, False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 0, msg='Cannot move to bank') field.push_card(initial_card, 0, rb.Card(2, 0, False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 0, msg='Cannot move to bank') field.push_card(initial_card, 0, rb.Card(5, 0, False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to bank') field.push_card(initial_card, 0, rb.Card(3, 1, False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to bank') field.push_card(initial_card, 0, rb.Card(2, 0, False)) self.assertEqual(field.move_card(initial_card, final_card - 1, 0), 5, msg='Allows illegal move to bank') final_card = 11 field.push_card(initial_card, 0, rb.Card(5, 0, False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to bank') field.push_card(initial_card, 0, rb.Card(3, 1, False)) self.assertEqual(field.move_card(initial_card, final_card, 0), 5, msg='Allows illegal move to bank') field.push_card(initial_card, 0, rb.Card(2, 0, False)) self.assertEqual(field.move_card(initial_card, final_card - 1, 0), 5, msg='Allows illegal move to bank')
def setUp(self): self.field = rb.Field(1)
def test_shuffle(self): self.assertNotEqual(self.field, rb.Field(3), msg='Shuffling not working')
def main(): field = rb.Field(0) display(field, 2)
def main(): field = rb.Field(1) field.moveCard(19, 15, 0) field.exposeStockCard(0) field.moveCard(0, 19, 0) field.exposeStockCard(0) field.discard(0) field.moveCard(16, 2, 1) field.moveCard(13, 3, 1) field.exposeStockCard(1) field.moveCard(0, 14, 1) field.exposeStockCard(1) field.moveCard(0, 13, 1) field.exposeStockCard(1) field.moveCard(0, 16, 1) field.exposeStockCard(1) field.discard(1) field.discard(0) field.moveCard(12, 3, 1) field.moveCard(0, 12, 1) field.exposeStockCard(1) field.moveCard(0, 4, 1) field.moveCard(16, 4, 1) field.exposeStockCard(1) field.moveCard(0, 19, 1) field.exposeStockCard(1) field.moveCard(0, 16, 1) field.exposeStockCard(1) field.moveCard(1, 13, 1) field.moveCard(1, 15, 1) field.moveCard(1, 19, 1) field.discard(1) field.discard(0) field.moveCard(14, 3, 1) field.discard(1) field.moveCard(1, 16, 0) field.discard(0) field.discard(1) field.moveCard(1, 17, 0) field.moveCard(0, 16, 0) field.moveCard(0, 17, 0) field.moveCard(18, 17, 0) field.exposeStockCard(0) field.moveCard(0, 18, 0) field.exposeStockCard(0) field.moveCard(0, 8, 0) field.exposeStockCard(0) field.moveCard(0, 4, 0) field.exposeStockCard(0) field.moveCard(0, 13, 0) field.exposeStockCard(0) field.moveCard(0, 4, 0) field.exposeStockCard(0) field.discard(0) field.moveCard(14, 3, 1) field.moveCard(0, 14, 1) field.exposeStockCard(1) field.discard(1) field.moveCard(1, 5, 0) field.discard(0) field.discard(1) field.discard(0) field.discard(1) field.discard(0) field.moveCard(12, 3, 1) field.moveCard(0, 12, 1) field.exposeStockCard(1) field.moveCard(1, 19, 1) field.discard(1) field.moveCard(12, 2, 0) field.moveCard(0, 12, 0) field.exposeStockCard(0) field.moveCard(0, 15, 0) field.exposeStockCard(0) field.moveCard(1, 2, 0) field.moveCard(1, 15, 0) field.discard(0) field.moveCard(14, 3, 1) field.moveCard(1, 14, 1) field.discard(1) field.moveCard(0, 14, 0) field.moveCard(12, 14, 0) field.exposeStockCard(0) field.moveCard(0, 12, 0) field.exposeStockCard(0) field.moveCard(1, 8, 0) field.discard(0) field.discard(1) field.moveCard(19, 3, 0) field.moveCard(14, 3, 0) field.discard(0) field.moveCard(1, 19, 1) field.moveCard(1, 6, 1) field.moveCard(18, 6, 1) field.moveCard(17, 18, 1) field.moveCard(17, 6, 1) field.moveCard(16, 6, 1) field.moveCard(14, 6, 1) field.moveCard(1, 17, 1) field.moveCard(18, 17, 1) field.moveCard(16, 18, 1) field.moveCard(16, 6, 1) field.moveCard(1, 16, 1) field.moveCard(1, 5, 1) field.discard(1) field.moveCard(1, 12, 0) field.moveCard(1, 7, 0) field.moveCard(17, 7, 0) field.moveCard(1, 13, 0) field.discard(0) field.moveCard(1, 7, 1) field.moveCard(1, 8, 1) field.discard(1) field.moveCard(1, 6, 0) field.moveCard(12, 6, 0) field.moveCard(1, 5, 0) field.discard(0) field.moveCard(1, 8, 1) field.discard(1) field.moveCard(1, 10, 0) field.discard(0) field.moveCard(1, 11, 1) field.moveCard(1, 19, 1) field.moveCard(14, 19, 1) field.moveCard(17, 14, 1) field.moveCard(17, 7, 1) field.moveCard(17, 4, 1) field.moveCard(1, 5, 1) field.moveCard(18, 5, 1) field.moveCard(19, 5, 1) field.moveCard(1, 17, 1) field.moveCard(1, 4, 1) field.moveCard(1, 6, 1) field.moveCard(1, 10, 1) field.moveCard(14, 10, 1) field.moveCard(1, 14, 1) field.moveCard(1, 3, 1) field.moveCard(1, 13, 1) field.bigJosh(1) field.moveCard(1, 3, 1) field.moveCard(1, 18, 1) field.moveCard(1, 15, 1) field.moveCard(14, 15, 1) field.moveCard(1, 14, 1) field.moveCard(0, 14, 1) field.moveCard(1, 17, 1) field.moveCard(1, 4, 1) field.moveCard(1, 4, 1) field.moveCard(1, 14, 1) field.moveCard(1, 7, 1) field.discard(1) field.moveCard(1, 3, 0) field.discard(0) field.discard(1) field.moveCard(18, 3, 0) field.moveCard(0, 18, 0) field.discard(0) field.discard(1) field.moveCard(1, 15, 0) field.moveCard(1, 7, 0) field.moveCard(1, 5, 0) field.moveCard(13, 5, 0) field.moveCard(13, 4, 0) field.moveCard(1, 8, 0) field.moveCard(15, 8, 0) field.moveCard(15, 7, 0) field.moveCard(15, 12, 0) field.moveCard(15, 5, 0) field.moveCard(15, 4, 0) field.discard(0) field.moveCard(1, 6, 1) field.discard(1) field.moveCard(1, 7, 0) field.moveCard(16, 7, 0) field.moveCard(13, 7, 0) field.moveCard(13, 4, 0) field.moveCard(15, 7, 0) field.moveCard(14, 15, 0) field.moveCard(14, 4, 0) field.moveCard(13, 18, 0) field.moveCard(19, 16, 0) field.moveCard(19, 13, 0) field.moveCard(16, 13, 0) field.moveCard(19, 16, 0) field.moveCard(19, 5, 0) field.moveCard(19, 6, 0) field.moveCard(15, 5, 0) field.moveCard(19, 5, 0) field.moveCard(14, 5, 0) field.moveCard(15, 6, 0) field.moveCard(18, 19, 0) field.moveCard(18, 6, 0) field.moveCard(13, 14, 0) field.moveCard(13, 16, 0) field.moveCard(14, 16, 0) field.moveCard(1, 13, 0) field.moveCard(16, 18, 0) field.moveCard(16, 14, 0) field.moveCard(16, 13, 0) field.moveCard(14, 13, 0) field.moveCard(18, 13, 0) field.bigJosh(0) field.moveCard(1, 14, 0) field.moveCard(12, 16, 0) field.moveCard(12, 14, 0) field.moveCard(16, 14, 0) field.moveCard(1, 12, 0) field.moveCard(1, 16, 0) field.moveCard(1, 11, 0) field.moveCard(16, 11, 0) field.moveCard(17, 11, 0) field.moveCard(1, 12, 0) field.moveCard(1, 14, 0) field.moveCard(1, 19, 0) field.moveCard(13, 16, 0) field.moveCard(13, 18, 0) field.moveCard(16, 18, 0) field.moveCard(13, 16, 0) field.moveCard(13, 19, 0) field.moveCard(16, 19, 0) field.moveCard(18, 16, 0) field.moveCard(18, 19, 0) field.moveCard(16, 19, 0) field.moveCard(1, 8, 0) field.moveCard(1, 8, 0) field.moveCard(19, 16, 0) field.moveCard(19, 18, 0) field.moveCard(19, 8, 0) field.moveCard(12, 13, 0) field.moveCard(12, 19, 0) field.moveCard(13, 19, 0) field.moveCard(16, 19, 0) field.moveCard(1, 12, 0) field.moveCard(1, 13, 0) field.moveCard(1, 11, 0) field.moveCard(1, 11, 0) field.moveCard(1, 15, 0) field.moveCard(1, 16, 0) field.moveCard(1, 11, 0) field.moveCard(18, 11, 0) field.moveCard(1, 10, 0) field.moveCard(17, 10, 0) field.moveCard(14, 17, 0) field.moveCard(14, 18, 0) field.moveCard(14, 11, 0) field.moveCard(17, 18, 0) field.moveCard(1, 7, 0) field.moveCard(13, 7, 0) field.moveCard(1, 10, 0) field.moveCard(19, 10, 0) field.moveCard(18, 17, 0) field.moveCard(18, 10, 0) field.moveCard(19, 18, 0) field.moveCard(19, 10, 0) field.moveCard(14, 10, 0) field.moveCard(12, 10, 0) field.moveCard(15, 10, 0) field.moveCard(16, 10, 0) field.moveCard(1, 12, 0) field.moveCard(1, 13, 0) field.moveCard(1, 14, 0) field.moveCard(1, 4, 0) field.moveCard(1, 16, 0) field.discard(0) field.bigJosh(1) field.discard(1) field.bigJosh(0) field.discard(0) field.discard(1) field.moveCard(17, 3, 0) field.bigJosh(0) field.moveCard(1, 17, 0) rb.core.display.display(field, 2) num_stock = len(field.getExposedStocks(1)) + len(field.getHiddenStocks(1)) num_hand = len(field.getHands(1)) + len(field.getWastes(1)) print("{0} cards left in the stock".format(num_stock)) print("{0} cards left in the hand".format(num_hand)) print("{0} points".format(num_stock + num_hand + 30))