57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
# board = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 2, 0, 0, 0], [0, 2, 1, 2, 0, 0, 0]]
|
|
board = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1, 2], [1, 0, 0, 0, 1, 2, 1], [1, 2, 2, 1, 2, 2, 2]]
|
|
|
|
import main
|
|
|
|
g = main.Game()
|
|
g.board = board
|
|
g.draw_board()
|
|
|
|
|
|
def is_board_won(board):
|
|
def _verticle_win(board):
|
|
for x in range(7):
|
|
instances = [0,0]
|
|
for y in range(6):
|
|
if board[y][x] == 1:
|
|
instances[0] += 1
|
|
elif board[y][x] == 2:
|
|
instances[1] += 1
|
|
|
|
if instances[0] == 4:
|
|
return 1
|
|
elif instances[1] == 4:
|
|
return 2
|
|
|
|
return 0
|
|
|
|
def _horizontal_win(board):
|
|
for x in range(6):
|
|
for y in range(7):
|
|
f = board[x][y]
|
|
if board[x][y] != 0:
|
|
try:
|
|
if board[x][y + 1] == board[x][y] and board[x][y + 2] == board[x][y] and board[x][y + 3] == board[x][y]:
|
|
return board[x][y]
|
|
except IndexError:
|
|
# We hit the bounds of the board so we don't care
|
|
pass
|
|
return 0
|
|
|
|
def _diagonal_win(board):
|
|
return 0
|
|
|
|
|
|
hor = _horizontal_win(board)
|
|
ver = _verticle_win(board)
|
|
diag = _diagonal_win(board)
|
|
|
|
if hor != 0:
|
|
return hor
|
|
if ver != 0:
|
|
return ver
|
|
if diag != 0:
|
|
return diag
|
|
|
|
is_board_won(board)
|