-
Notifications
You must be signed in to change notification settings - Fork 0
/
GO.py
64 lines (50 loc) · 1.73 KB
/
GO.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from copy import deepcopy
from GoPoint import Point
from GoBoard import Board
from GoMove import Move
class Go:
def __init__(self, n):
self.size = n
self.board = Board(self.size)
def apply_move(self, move):
# move = Move(self.board, point)
# if not move.is_valid_move():
# return False
if not move.isValid:
return False
new_board:Board = deepcopy(self.board)
if move.is_play:
new_board.place_stone(move)
return new_board
def get_legal_moves(self):
moves = []
for i in range(0, self.board.board_size):
for j in range(0, self.board.board_size):
point = Point(i, j)
move = Move(self.board, point)
if move.is_valid_move():
moves.append(move)
pass_move = Move(self.board, None)
moves.append(pass_move)
return moves
def is_point_eye(self, point:Point):
if not self.board.coord_is_empty(point):
return False
if not self.board.point_on_grid(point):
return False
for neighbor in point.get_neighbors():
if self.board.point_on_grid(neighbor):
if self.board.get_point_color(neighbor) != self.board.player:
return False
diag_stones = point.get_diagonals()
opp_diags = 0
for stone in diag_stones:
if not self.board.point_on_grid(stone):
opp_diags += 1
break
for stone in diag_stones:
if self.board.get_point_color(stone) == 3-self.board.player:
opp_diags += 1
if opp_diags > 1:
return False
return True