-
Notifications
You must be signed in to change notification settings - Fork 0
/
moves_manager.py
47 lines (36 loc) · 1.7 KB
/
moves_manager.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
from adversarial_search import AdversarialSearch
from moves_helper import MoveHelper
from copy import deepcopy
from settings import Settings
import numpy
def display_options(player, options):
indice = 1
print(player.name, "Choose one option, your token is ", player.token, ":")
for opt in options:
print(f"{indice}: {Settings.letters[opt[1]]} {opt[0] + 1}")
indice += 1
def _is_out_of_bounds(col, row):
return col < 0 or row < 0 or col >= Settings.board_size or row >= Settings.board_size or col >= Settings.board_size
class MovesManager:
def __init__(self, board):
self.player1 = None
self.player2 = None
self.board = board
def get_possible_moves(self, player):
return MoveHelper.get_possible_moves(player, self.board)
def make_move(self, player, possible_moves, player_enemy, computer_turn):
unique_values, unique_opt = MoveHelper.get_unique_final_pos(possible_moves)
while True:
display_options(player, unique_opt)
if computer_turn:
option_decided = AdversarialSearch.min_max_with_depth(player, deepcopy(self.board), player_enemy, unique_values)
# option_decided = numpy.random.randint(1, len(unique_opt) + 1)
else:
# option_decided = int(input())
option_decided = numpy.random.randint(1, len(unique_opt) + 1)
# option_decided = 1
print("choice:", option_decided)
if option_decided in range(1, len(unique_opt) + 1):
break
print("Choose one of the options please!")
MoveHelper.apply_move(self.board, player, player_enemy, unique_values[option_decided-1])