From af9900a365e6575aa6610b974be0cb6bd64b45df Mon Sep 17 00:00:00 2001 From: smessie Date: Tue, 10 Nov 2020 20:10:09 +0100 Subject: [PATCH 1/2] Some tweaks --- game/agent.py | 4 ---- game/player.py | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/game/agent.py b/game/agent.py index c2402f0..de510c5 100644 --- a/game/agent.py +++ b/game/agent.py @@ -20,12 +20,8 @@ def make_move(self, table: Table) -> None: """ pass - def receive_event(self, move, event) -> None: - pass - def get_preferred_card_order(self, table: Table) -> List[Card]: """ Function used by President to exchange cards at the beginning of a round. Most wanted card should be in front. - """ return sorted(table.deck.card_stack, reverse=True) diff --git a/game/player.py b/game/player.py index 2d3eee0..bf4a9f3 100644 --- a/game/player.py +++ b/game/player.py @@ -16,8 +16,8 @@ def __init__(self): self.player_id: int = Player._player_id Player._player_id += 1 - def get_all_possible_moves(self, table: Table) -> [[Card]]: - possible_moves = [] + def get_all_possible_moves(self, table: Table) -> List[List[Card]]: + possible_moves = [[]] for amount_of_cards in range(len(table.last_move()[0]) if table.last_move() else 1, len(self.hand) + 1): for potential_move in combinations(self.hand, amount_of_cards): if table.game.valid_move(list(potential_move)): From e368735dbd34135c24890ebf0b930ac7cfeed85e Mon Sep 17 00:00:00 2001 From: smessie Date: Tue, 10 Nov 2020 20:20:22 +0100 Subject: [PATCH 2/2] Implement a RandomAgent --- agents/random_agent.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 agents/random_agent.py diff --git a/agents/random_agent.py b/agents/random_agent.py new file mode 100644 index 0000000..5057eab --- /dev/null +++ b/agents/random_agent.py @@ -0,0 +1,29 @@ +import random + +from game.agent import Agent +from game.table import Table +from game.player import Player +from typing import List, TYPE_CHECKING + +if TYPE_CHECKING: + from game.card import Card + + +class RandomAgent(Agent): + def __init__(self): + super().__init__(Player()) + + def make_move(self, table: Table) -> None: + """ + Let the agent make a random move from all possible moves in his state. + """ + possible_moves: List[List[Card]] = self.player.get_all_possible_moves(table) + table.try_move(self, random.choice(possible_moves)) + + def get_preferred_card_order(self, table: Table) -> List[Card]: + """ + Returns the preferred cards to exchange in the beginning of a round in random order. + """ + possible_cards = list(set(table.deck.card_stack) - set(self.player.hand)) + random.shuffle(possible_cards) + return possible_cards