Last active
June 3, 2020 15:30
-
-
Save cashlo/a63c47c586be2d7fad1b7daca7683ac3 to your computer and use it in GitHub Desktop.
Check end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_board(self, test=False): | |
if self.last_move is None: | |
return Gomoku.IN_PROGRESS | |
x = self.last_move%self.size | |
y = self.last_move//self.size | |
cell = self.board[self.last_move] | |
min_x = max(0, x-4) | |
min_y = max(0, y-4) | |
max_x = min(self.size-1, x+4) | |
max_y = min(self.size-1, y+4) | |
main_diagonal_start = self.last_move - (self.size+1)*min(y-min_y, x-min_x) | |
main_diagonal_end = self.last_move + (self.size+1)*min(max_y-y, max_x-x) | |
anti_diagonal_start = self.last_move - (self.size-1)*min(y-min_y, max_x-x) | |
anti_diagonal_end = self.last_move + (self.size-1)*min(max_y-y, x-min_x) | |
move_line_list = [ | |
(self.size*y+min_x, self.size*y+max_x+1, 1), | |
(self.size*min_y+x, self.size*max_y+x+1, self.size), | |
(main_diagonal_start, main_diagonal_end+1, self.size+1), | |
(anti_diagonal_start, anti_diagonal_end+1, self.size-1), | |
] | |
if test: | |
for line in move_line_list: | |
for m in range(line[0],line[1],line[2]): | |
self.board[m] = Gomoku.WHITE | |
return 0 | |
for line in move_line_list: | |
count = 0 | |
for p in self.board[line[0]:line[1]:line[2]]: | |
if p == cell: | |
count += 1 | |
else: | |
count = 0 | |
if count == Gomoku.LINE_LENGTH: | |
return cell | |
if self.total_moves == self.size*self.size: | |
return Gomoku.DRAW | |
return Gomoku.IN_PROGRESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment