day 6
This commit is contained in:
parent
82f8e11ae4
commit
e7bd950ce3
1 changed files with 20 additions and 37 deletions
|
@ -28,45 +28,28 @@ def is_row_valid(row, called):
|
||||||
to_cmp = list(map(lambda x: x in called, row))
|
to_cmp = list(map(lambda x: x in called, row))
|
||||||
return to_cmp == len(row)*[True]
|
return to_cmp == len(row)*[True]
|
||||||
|
|
||||||
def board_do_win(deb, board, calling):
|
def get_wins():
|
||||||
|
wins = []
|
||||||
|
for i in range(len(to_be_called)):
|
||||||
|
calling = to_be_called[0:(i+1)]
|
||||||
|
for board_index,board in enumerate(boards):
|
||||||
|
if len(list(filter(lambda x: x[0] == board_index, wins))) > 0:
|
||||||
|
continue
|
||||||
for row in board:
|
for row in board:
|
||||||
if is_row_valid(row, calling):
|
if is_row_valid(row, calling):
|
||||||
return True
|
wins.append(board_index, calling, board)
|
||||||
|
|
||||||
# generate columns
|
# generate columns
|
||||||
columns = []
|
columns = []
|
||||||
for column_index in range(len(board[0])):
|
for column_index in range(len(board[0])):
|
||||||
current_c = []
|
current_c = []
|
||||||
for row_index in range(len(board)):
|
for row_index in range(len(board)):
|
||||||
current_c.append(board[row_index][column_index])
|
current_c.append(board[row_index][column_index])
|
||||||
columns.append(current_c)
|
|
||||||
# if deb:
|
|
||||||
# print(f'{columns=}')
|
|
||||||
|
|
||||||
for column in columns:
|
for column in columns:
|
||||||
if is_row_valid(column, calling):
|
if is_row_valid(column, calling):
|
||||||
return True
|
wins.append(board_index, calling, board)
|
||||||
return False
|
|
||||||
|
|
||||||
def get_wins():
|
return False
|
||||||
wins = []
|
|
||||||
index_to_wins = []
|
|
||||||
for i in range(len(to_be_called)):
|
|
||||||
calling = to_be_called[0:(i+1)]
|
|
||||||
for board_index,board in enumerate(boards):
|
|
||||||
if board_index in index_to_wins:
|
|
||||||
continue
|
|
||||||
deb = False
|
|
||||||
if calling == [7, 4, 9, 5, 11, 17, 23, 2, 0, 14, 21, 24, 10, 16, 13]:
|
|
||||||
print('DEBUG==')
|
|
||||||
deb = True
|
|
||||||
res = board_do_win(deb, board, calling)
|
|
||||||
if deb:
|
|
||||||
print(res, board)
|
|
||||||
if res:
|
|
||||||
wins.append((board_index, calling.copy(), board))
|
|
||||||
index_to_wins.append(board_index)
|
|
||||||
return wins, index_to_wins
|
|
||||||
|
|
||||||
def get_score_from_board(board, calling):
|
def get_score_from_board(board, calling):
|
||||||
sum_unmarked = 0
|
sum_unmarked = 0
|
||||||
|
@ -77,10 +60,10 @@ def get_score_from_board(board, calling):
|
||||||
return sum_unmarked * calling[-1]
|
return sum_unmarked * calling[-1]
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
wins, index_to_wins = get_wins()
|
wins = get_wins()
|
||||||
pprint.pprint(wins)
|
pprint.pprint(wins)
|
||||||
print(f'{index_to_wins=}')
|
calling, winner = wins[0]
|
||||||
i, calling, winner = wins[-1]
|
if winner:
|
||||||
score = get_score_from_board(winner, calling)
|
score = get_score_from_board(winner, calling)
|
||||||
|
|
||||||
pprint.pprint(winner)
|
pprint.pprint(winner)
|
||||||
|
|
Loading…
Reference in a new issue