Ejemplo n.º 1
0
def test_is_valid_play(student):
    hands = game.deal()
    prev = random.choice(common.generate_plays(hands[0]))
    retval = []
    t_pass = True
    retval.append("prev = {0}".format(sorted(prev)))
    for play in common.generate_plays(hands[1]):
        x = check.compare_solutions(common.is_valid_play, student, t_args=[prev, play])
        t_pass = t_pass and x[0]
        retval.append(["play = {0}".format(sorted(play)), checkresult2list(x)])
    return t_pass, (retval)
Ejemplo n.º 2
0
def test_is_valid_play(student):
    hands = game.deal()
    prev = random.choice(common.generate_plays(hands[0]))
    retval = []
    t_pass = True
    retval.append('prev = {0}'.format(sorted(prev)))
    for play in common.generate_plays(hands[1]):
        x = check.compare_solutions(common.is_valid_play,
                                    student,
                                    t_args=[prev, play])
        t_pass = t_pass and x[0]
        retval.append(['play = {0}'.format(sorted(play)), checkresult2list(x)])
    return t_pass, (retval)
Ejemplo n.º 3
0
def test_generate_plays(student):
    hands = game.deal()
    retval = []
    t_pass = True
    for hand in hands:
        hand = list(hand)
        x = check.compare_solutions(common.generate_plays, student, t_args=[hand], transform=list2frozenset)
        t_pass = t_pass and x[0]
        retval.append("hand = {0}".format(hand))
        retval.append("sorted(hand) = {0}".format(sorted(hand)))
        # convert away from frozenset so that doesn't get displayed
        y = x[0], map(list, x[1]), map(list, x[2])
        retval.append(checkresult2list(y))
    return t_pass, (retval)
Ejemplo n.º 4
0
def test_get_valid_plays(student):
    hands = game.deal()
    retval = []
    t_pass = True
    for prev in common.generate_plays(hands[0]):
        retval.append("prev = {0}".format(sorted(prev)))
        for hand in hands[1:]:
            x = check.compare_solutions(
                common.get_valid_plays,
                student,
                t_args=[prev, list(hand)],
                t_kwargs=dict(generate=common.generate_plays, is_valid=common.is_valid_play),
                transform=list2frozenset,
            )
            t_pass = t_pass and x[0]
            retval.append(["hand = {0}".format(sorted(hand)), checkresult2list(x)])
    return t_pass, (retval)
Ejemplo n.º 5
0
def test_generate_plays(student):
    hands = game.deal()
    retval = []
    t_pass = True
    for hand in hands:
        hand = list(hand)
        x = check.compare_solutions(common.generate_plays,
                                    student,
                                    t_args=[hand],
                                    transform=list2frozenset)
        t_pass = t_pass and x[0]
        retval.append("hand = {0}".format(hand))
        retval.append("sorted(hand) = {0}".format(sorted(hand)))
        # convert away from frozenset so that doesn't get displayed
        y = x[0], map(list, x[1]), map(list, x[2])
        retval.append(checkresult2list(y))
    return t_pass, (retval)
Ejemplo n.º 6
0
def test_play(student):
    hands = game.deal()
    players = (student, student, student, student)
    discard = []
    lp = 0
    game_over = False

    retval = []
    round = 0
    t_pass = True

    while not game_over:
        round += 1
        retval.append('Round {0}'.format(round))
        retval.append([
            'HANDS',
            [
                'player{0}: {1}'.format(i, sorted(h))
                for i, h in enumerate(hands)
            ]
        ])
        prev_hands = copy.deepcopy(hands)
        prev_lp = lp
        try:
            hands, lp, game_over, discard = game.play_round(
                hands, players, discard, lp, 'raise')
        except game.InvalidAction, e:
            retval.append(['INVALID ACTION', [e, e.call]])
            t_pass = False
            break
        retval.append([
            'PLAYS',
            [
                'player{0}: {1}'.format((prev_lp + i) % len(players), str(p))
                for i, p in enumerate(discard[-1])
            ]
        ])

        if prev_hands == hands:
            # Nobody played, so we break out or we would be stuck
            game_over = True
            retval.append("GAME OVER: Nobody played")

        else:
            retval.append(['WINNER', ['player{0}'.format(lp)]])
Ejemplo n.º 7
0
def test_get_valid_plays(student):
    hands = game.deal()
    retval = []
    t_pass = True
    for prev in common.generate_plays(hands[0]):
        retval.append('prev = {0}'.format(sorted(prev)))
        for hand in hands[1:]:
            x = check.compare_solutions(common.get_valid_plays,
                                        student,
                                        t_args=[prev, list(hand)],
                                        t_kwargs=dict(
                                            generate=common.generate_plays,
                                            is_valid=common.is_valid_play),
                                        transform=list2frozenset)
            t_pass = t_pass and x[0]
            retval.append(
                ['hand = {0}'.format(sorted(hand)),
                 checkresult2list(x)])
    return t_pass, (retval)
Ejemplo n.º 8
0
def test_play(student):
    hands = game.deal()
    players = (student, student, student, student)
    discard = []
    lp = 0
    game_over = False

    retval = []
    round = 0
    t_pass = True

    while not game_over:
        round += 1
        retval.append("Round {0}".format(round))
        retval.append(["HANDS", ["player{0}: {1}".format(i, sorted(h)) for i, h in enumerate(hands)]])
        prev_hands = copy.deepcopy(hands)
        prev_lp = lp
        try:
            hands, lp, game_over, discard = game.play_round(hands, players, discard, lp, "raise")
        except game.InvalidAction, e:
            retval.append(["INVALID ACTION", [e, e.call]])
            t_pass = False
            break
        retval.append(
            [
                "PLAYS",
                ["player{0}: {1}".format((prev_lp + i) % len(players), str(p)) for i, p in enumerate(discard[-1])],
            ]
        )

        if prev_hands == hands:
            # Nobody played, so we break out or we would be stuck
            game_over = True
            retval.append("GAME OVER: Nobody played")

        else:
            retval.append(["WINNER", ["player{0}".format(lp)]])
Ejemplo n.º 9
0
 def deal(self, ncards):
     game = self.get_cur_game()
     if game is not None:
         game.deal(ncards)
     return ''