mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-01-31 05:33:44 +00:00
Create player.py
This commit is contained in:
parent
00f8d464a8
commit
75956545ba
38
scripts/MiniMaxAlgo/player.py
Normal file
38
scripts/MiniMaxAlgo/player.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import math
|
||||
import random
|
||||
|
||||
|
||||
class Player:
|
||||
def __init__(self, letter):
|
||||
self.letter = letter
|
||||
|
||||
def get_move(self, game):
|
||||
pass
|
||||
|
||||
|
||||
class HumanPlayer(Player):
|
||||
def __init__(self, letter):
|
||||
super().__init__(letter)
|
||||
|
||||
def get_move(self, game):
|
||||
valid_square = False
|
||||
val = None
|
||||
while not valid_square:
|
||||
square = input(self.letter + '\'s turn. Input move (0-9): ')
|
||||
try:
|
||||
val = int(square)
|
||||
if val not in game.available_moves():
|
||||
raise ValueError
|
||||
valid_square = True
|
||||
except ValueError:
|
||||
print('Invalid square. Try again.')
|
||||
return val
|
||||
|
||||
|
||||
class RandomComputerPlayer(Player):
|
||||
def __init__(self, letter):
|
||||
super().__init__(letter)
|
||||
|
||||
def get_move(self, game):
|
||||
square = random.choice(game.available_moves())
|
||||
return square
|
Loading…
Reference in New Issue
Block a user