-
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 #4 from smessie/basic-agent
Implement a BasicAgent
- Loading branch information
Showing
6 changed files
with
58 additions
and
4 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,38 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List, Optional, TYPE_CHECKING | ||
|
||
from game.agent import Agent | ||
from util.cards import get_played_value | ||
from game.table import Table | ||
from game.player import Player | ||
|
||
if TYPE_CHECKING: | ||
from game.card import Card | ||
|
||
|
||
class BasicAgent(Agent): | ||
def __init__(self): | ||
super().__init__(Player()) | ||
|
||
def make_move(self, table: Table) -> None: | ||
""" | ||
Agent makes a move based on the fact that the hand played has the lowest possible value. | ||
""" | ||
possible_moves: List[List[Card]] = self.player.get_all_possible_moves(table) | ||
|
||
smallest_move = possible_moves[0] | ||
smallest_move_value: Optional[int] = get_played_value(smallest_move) | ||
for move in possible_moves: | ||
move_value: Optional[int] = get_played_value(move) | ||
if move_value and (not smallest_move_value or move_value > smallest_move_value): | ||
smallest_move_value = move_value | ||
smallest_move = move | ||
table.try_move(self, smallest_move) | ||
|
||
def get_preferred_card_order(self, table: Table) -> List[Card]: | ||
""" | ||
Returns the preferred cards to exchange in the beginning of a round in descending value order. | ||
""" | ||
possible_cards = list(set(table.deck.card_stack) - set(self.player.hand)) | ||
return sorted(possible_cards, reverse=True) |
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
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
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