-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement player subclass that takes human input
- Loading branch information
1 parent
410f409
commit 153dbfa
Showing
2 changed files
with
39 additions
and
0 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,33 @@ | ||
"""An example player implementation that also serves as a dummy for testing.""" | ||
|
||
from typing import Iterable | ||
|
||
from royal_game.modules.board import Board | ||
from royal_game.modules.move import Move | ||
from royal_game.modules.player import Player | ||
|
||
|
||
class Human(Player): | ||
"""You must implement the select_move method!""" # noqa: D400 | ||
|
||
def __init__(self, name: str): | ||
"""Initialize the human player with a name.""" | ||
super().__init__(name) | ||
|
||
def select_move( | ||
self, board: Board, available_moves: Iterable[Move], white_turn: bool | ||
) -> Move: | ||
"""Print available moves and take player input.""" | ||
for i, move in enumerate(available_moves): | ||
print(f"{i+1}: {move.__repr__()}") | ||
|
||
while True: | ||
player_selection = input("Please select a move: ") | ||
try: | ||
player_selection = int(player_selection) | ||
except ValueError: | ||
# catch non-int input strings | ||
continue | ||
|
||
if 1 <= player_selection <= len(available_moves): | ||
return available_moves[player_selection - 1] |
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 |
---|---|---|
@@ -1 +1,7 @@ | ||
"""CLI for benchmarking player agents against each other.""" | ||
|
||
from royal_game.modules.game import Game | ||
from royal_game.players.dummy import Dummy | ||
|
||
game = Game(Dummy(), Dummy()) | ||
game.play() |