Exemple #1
0
def test_lead(state: DoubleMatchaState):
    card = state.state.player.hand[0]
    card_data = card.to_data()

    state.lead(card_data)

    assert (state.state.state_name == 'follow')
    assert (state.state.player == state.players[1])
Exemple #2
0
def state():
    s = DoubleMatchaState(
        {'players': [{
            'name': 'piestastedgood'
        }, {
            'name': 'tripswithtires'
        }]})
    s.initialize()
    return s
Exemple #3
0
def test_initialize():
    state = DoubleMatchaState(
        {'players': [{
            'name': 'piestastedgood'
        }, {
            'name': 'tripswithtires'
        }]})
    state.initialize()
    assert len(state.players[0].hand) == 10
    assert len(state.players[1].hand) == 10
Exemple #4
0
def test_from_data():
    data = {
        'players': [{
            'name': 'piestastedgood',
            'hand': [{
                'suit': 3,
                'rank': 3
            }]
        }, {
            'name': 'tripswithtires',
            'hand': [{
                'suit': 1,
                'rank': 11
            }]
        }],
        'state': {
            'player': 'tripswithtires',
            'state': 'foreplace',
            'game_id': 0
        }
    }
    state = DoubleMatchaState.from_data(data)

    assert (len(state.players) == 2)
    assert (state.state.player.name == 'tripswithtires')
    assert (state.state.state_name == data['state']['state'])
    assert (state.state.game_id == data['state']['game_id'])

    assert (len(state.players[0].hand) == len(data['players'][0]['hand']))
    assert (type(state.players[0].hand[0]) == Card)
Exemple #5
0
def test_to_data_state_players(state: DoubleMatchaState):
    data = state.to_data()

    assert len(data['players']) == 2
    for player in data['players']:
        assert 'name' in player
        assert 'hand' in player
        assert 'tableau' in player
Exemple #6
0
def test_follow_lower_card(state: DoubleMatchaState):
    lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING)
    follow_card = Card(Card.Suit.CLUBS, Card.Rank.QUEEN)

    starting_player = state.current_player()

    state.current_player().hand[0] = lead_card
    state.next_player().hand[0] = follow_card

    # player[0] leads ♣K
    state.lead(lead_card.to_data())

    # player[1] follows ♣Q
    state.follow(follow_card.to_data())

    assert (state.state.state_name == 'lead')
    assert (state.state.player == starting_player)

    assert (follow_card not in state.next_player().hand)
    assert (follow_card in state.next_player().tableau)
Exemple #7
0
def test_end_second_game(state: DoubleMatchaState):
    lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING)
    follow_card = Card(Card.Suit.HEARTS, Card.Rank.KING)

    second_player = state.next_player()
    state.state.game_id = 1

    state.current_player().hand = [lead_card]
    state.next_player().hand = [follow_card]

    state.lead(lead_card.to_data())
    state.follow(follow_card.to_data())

    assert (state.state.state_name == "foreplace")
Exemple #8
0
def test_follow_same_card(state: DoubleMatchaState):
    lead_card = Card(Card.Suit.DIAMONDS, Card.Rank.ACE)
    follow_card = Card(Card.Suit.DIAMONDS, Card.Rank.ACE)

    leading_player = state.current_player()

    state.current_player().hand[0] = lead_card
    state.next_player().hand[0] = follow_card

    state.lead(lead_card.to_data())
    state.follow(follow_card.to_data())

    assert (state.state.state_name == 'lead')
    assert (state.state.player == leading_player)
Exemple #9
0
def test_follow_higher_card(state: DoubleMatchaState):
    lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING)
    follow_card = Card(Card.Suit.CLUBS, Card.Rank.TEN)

    following_player = state.next_player()

    state.current_player().hand[0] = lead_card
    state.next_player().hand[0] = follow_card

    state.lead(lead_card.to_data())
    state.follow(follow_card.to_data())

    assert (state.state.state_name == 'lead')
    assert (state.state.player == following_player)
Exemple #10
0
def test_valid_follow_rank(state: DoubleMatchaState):
    lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING)
    follow_card = Card(Card.Suit.HEARTS, Card.Rank.KING)

    state.current_player().hand = [lead_card]
    state.next_player().hand = [follow_card]
    hand = state.next_player().hand

    state.lead(lead_card.to_data())

    assert (state.valid_follow(lead_card, follow_card, hand) == True)
Exemple #11
0
def test_next_player(state: DoubleMatchaState):
    assert (state.next_player() == state.players[1])
Exemple #12
0
def test_to_data_state(state: DoubleMatchaState):
    data = state.to_data()

    assert 'state' in data['state']
    assert 'player' in data['state']
    assert type(data['state']['player']) == str
Exemple #13
0
def test_to_data(state: DoubleMatchaState):
    data = state.to_data()

    assert 'players' in data
    assert 'state' in data
Exemple #14
0
def test_skip_foreplace(state: DoubleMatchaState):
    state.skip_foreplace()

    assert (len(state.players[0].foreplace) == 0)
    assert (state.state.state_name == 'foreplace')
    assert (state.state.player == state.players[1])
Exemple #15
0
def test_to_data_twice(state: DoubleMatchaState):
    state.to_data()
    state.to_data()
Exemple #16
0
def test_end_game(state: DoubleMatchaState):
    lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING)
    follow_card = Card(Card.Suit.HEARTS, Card.Rank.KING)

    second_player = state.next_player()

    state.current_player().hand = [lead_card]
    state.next_player().hand = [follow_card]

    state.lead(lead_card.to_data())
    state.follow(follow_card.to_data())

    assert (state.state.state_name == 'foreplace')
    assert (state.current_player() == second_player)
    assert (state.current_player().hand == [lead_card])
    assert (state.next_player().hand == [follow_card])
    assert (len(state.current_player().tableau) == 0)
    assert (len(state.current_player().foreplace) == 0)

    state.skip_foreplace()

    assert (state.state.state_name == 'foreplace')