From 81ac7610e781b7f17a153bf3ab22afaaefa777ad Mon Sep 17 00:00:00 2001 From: InCogNiTo124 Date: Sun, 25 Apr 2021 18:50:18 +0200 Subject: [PATCH] Make flake8 happy --- belabot/engine/belot.py | 7 +++---- belabot/engine/player.py | 9 +++++---- belabot/engine/util.py | 2 +- tests/test_declarations.py | 6 +++--- tests/test_util.py | 3 +-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/belabot/engine/belot.py b/belabot/engine/belot.py index 8edf5e9..62ef59d 100644 --- a/belabot/engine/belot.py +++ b/belabot/engine/belot.py @@ -7,7 +7,6 @@ import os import random import sys -from functools import reduce from typing import List, Tuple, Sequence, Dict import more_itertools as mit @@ -45,7 +44,7 @@ def play(self) -> None: return def round(self, dealer_index: int) -> Tuple[int, int]: - ### BIDDING PHASE + # BIDDING PHASE first_6, talons = self.shuffle() self.deal_cards(first_6) adut, adut_caller_index = self.get_adut(dealer_index) @@ -66,7 +65,7 @@ def round(self, dealer_index: int) -> Tuple[int, int]: self.notify_pregame(all_declarations, adut, adut_caller_index) - ### MAIN PHASE + # MAIN PHASE # mi_points = random_gen.randint(0, 162) mi_points, vi_points = 0, 0 # next player starts first @@ -122,7 +121,7 @@ def notify_played(self, player: Player, card: Card) -> None: if other_player == player: player.card_accepted(card) else: - other_player.notify_played(card) + other_player.notify_played(player, card) return def notify_turn_points(self, mi_points: int, vi_points: int) -> None: diff --git a/belabot/engine/player.py b/belabot/engine/player.py index 0467379..53424fe 100644 --- a/belabot/engine/player.py +++ b/belabot/engine/player.py @@ -2,12 +2,12 @@ from .declarations import Declaration from .util import get_valid_moves from typing import List, Optional, Dict +from collections import defaultdict import abc import random import sys import os import logging -import random log = logging.getLogger(__name__) log.addHandler(logging.StreamHandler(sys.stdout)) @@ -18,7 +18,7 @@ class Player(abc.ABC): def __init__(self, name: Optional[str]) -> None: self.name: Optional[str] = name self.cards: List[Card] = [] - self.played: List[Card] = [] + self.played: Dict[Player, List[Card]] = defaultdict(list) self.points: List[int] = [] self.turn_declarations: Dict[int, List[Declaration]] = dict() return @@ -34,8 +34,8 @@ def clear_cards(self) -> None: self.cards.clear() return - def notify_played(self, card: Card) -> None: - self.played.append(card) + def notify_played(self, player: 'Player', card: Card) -> None: + self.played[player].append(card) self.card_played(card) return @@ -52,6 +52,7 @@ def notify_pregame( def card_accepted(self, card: Card) -> None: self.cards.remove(card) + self.notify_played(self, card) return def card_played(self, card: Card) -> None: diff --git a/belabot/engine/util.py b/belabot/engine/util.py index 0c3e864..8e01dff 100644 --- a/belabot/engine/util.py +++ b/belabot/engine/util.py @@ -1,4 +1,4 @@ -from typing import Tuple, List, Iterable, Callable, Optional +from typing import Tuple, List, Callable from .card import Card, Suit from functools import cmp_to_key diff --git a/tests/test_declarations.py b/tests/test_declarations.py index bbe04ac..e5176f4 100644 --- a/tests/test_declarations.py +++ b/tests/test_declarations.py @@ -164,9 +164,9 @@ def test_declaration_order_rank(): def test_declaration_order_suit(): for length1 in range(3, 8 + 1): - ranks1 = list(Rank)[length1 - 1 :] + ranks1 = list(Rank)[length1-1:] for length2 in range(3, 8 + 1): - ranks2 = list(Rank)[length2 - 1 :] + ranks2 = list(Rank)[length2-1:] for (rank1, rank2) in it.product(ranks1, ranks2): for (suit1, suit2) in it.product(Suit, Suit): decl1 = SuitDeclaration(rank1, suit1, length1) @@ -179,7 +179,7 @@ def test_declaration_order_suit(): def test_declarations_order_both(): for suit_length in range(3, 8 + 1): - suit_ranks = list(Rank)[suit_length - 1 :] + suit_ranks = list(Rank)[suit_length-1:] for rank_rank in VALUES_RANK: rank_decl = RankDeclaration(rank_rank) for suit_rank in suit_ranks: diff --git a/tests/test_util.py b/tests/test_util.py index 2502d61..ddc2a0e 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,6 +1,5 @@ from belabot.engine.util import calculate_points, get_valid_moves, get_winner from belabot.engine.card import Card, Suit, Rank -from functools import cmp_to_key def test_calculate_points_no_decl(): @@ -100,7 +99,7 @@ def test_valid_moves(): == player_cards ) - ### two cards + # two cards # uber cards without adut for adut_suit in [Suit.DIAMONDS, Suit.SPADES, Suit.CLUBS]: assert (