-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
47 lines (35 loc) · 1.13 KB
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
__author__ = 'Camtr0n'
from enum import Enum
import ai
class PlayerType(Enum):
Human = 1
Computer = 2
class Symbol(Enum):
X = 1
O = 2
E = 3
def opposite_symbol(symbol):
return Symbol(2).name if symbol is Symbol(1).name else Symbol(1).name
class Player:
def __init__(self, player_type, player_number):
self._number = player_number
self._type = PlayerType(player_type)
self._symbol = Symbol(player_number)
@property
def symbol(self):
return self._symbol.name
@property
def player_type(self):
return self._type.name
@property
def number(self):
return self._number
def get_next_board(self, game):
if self.player_type == PlayerType(1).name:
choice = game.presenter.get_choice(self, game.board)
move = game.board.map_to_move(choice)
else:
game.presenter.notify_turn(game.active_player.number)
game.presenter.notify_thinking(game.active_player.player_type)
move = ai.negamax(game.board, self.symbol, self.symbol).move
return game.board.apply_move(move, self.symbol)