-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComputerAI.py
47 lines (31 loc) · 1.16 KB
/
ComputerAI.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
import random
from BaseAI import BaseAI
import numpy as np
from Grid import Grid
class ComputerAI(BaseAI):
def __init__(self, initial_position = None) -> None:
super().__init__()
self.pos = initial_position
self.player_num = None
def setPosition(self, new_pos: tuple):
self.pos = new_pos
def getPosition(self):
return self.pos
def getPlayerNum(self):
return self.player_num
def setPlayerNum(self, num):
self.player_num = num
def getMove(self, grid):
""" Returns a random, valid move """
# find all available moves
available_moves = grid.get_neighbors(self.pos, only_available = True)
# make random move
new_pos = random.choice(available_moves) if available_moves else None
return new_pos
def getTrap(self, grid : Grid):
"""Get the *intended* trap move of the player"""
# find all available cells in the grid
available_cells = grid.getAvailableCells()
# find all available cells
trap = random.choice(available_cells) if available_cells else None
return trap