Skip to content

Commit

Permalink
Reimplement get_all_possible_moves function
Browse files Browse the repository at this point in the history
  • Loading branch information
smessie committed Nov 9, 2020
1 parent 10a52ff commit ad3a4bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion game/player.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from typing import List, Optional, TYPE_CHECKING
from itertools import combinations
from typing import List, TYPE_CHECKING

if TYPE_CHECKING:
from game.card import Card
from game.table import Table


class Player:
Expand All @@ -13,3 +15,11 @@ def __init__(self):
self.hand: List[Card] = []
self.player_id: int = Player._player_id
Player._player_id += 1

def get_all_possible_moves(self, table: Table) -> [[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)):
possible_moves.append(list(potential_move))
return possible_moves
4 changes: 2 additions & 2 deletions game/president.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def on_move(self, agent: Agent, cards: List[Card]) -> Tuple[int, bool]:
return -5, False # TODO fix reward

# Previous value should be lower
if self._valid_move(cards):
if self.valid_move(cards):
self.table.do_move(agent, cards)
return 10, False # TODO fix reward
else:
return -10, False # TODO fix reward

def _valid_move(self, cards: List[Card]) -> bool:
def valid_move(self, cards: List[Card]) -> bool:
last_move: Tuple[List[Card], Agent] = self.table.last_move()

# If multiple cards are played length should be at least the same.
Expand Down

0 comments on commit ad3a4bf

Please sign in to comment.