-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from smessie/random-agent
Implement a RandomAgent
- Loading branch information
Showing
3 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters