-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle.py
59 lines (55 loc) · 1.8 KB
/
puzzle.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
"""
https://github.com/PHentosh/Puzzle
"""
def check_rows(board: list)-> bool:
"""
Check if in rows are the same numbers
>>> check_rows(["**** ****", "***1 ****", "** 3****", "* 4 1****", \
" 9 5 ", " 6 83 *", "3 1 **", " 8 2***", " 2 ****"])
True
"""
for i in board:
numbers = []
for j in i:
if (j != "*") and (j != ' '):
numbers.append(int(j))
for j in numbers:
numbers = numbers[1:]
if j in numbers:
return False
return True
def check_columns(board: list)-> bool:
"""
Check if in colnmns are the same numbers
>>> check_columns(["**** ****", "***1 ****", "** 3****", "* 4 1****", \
" 9 5 ", " 6 83 *", "3 1 **", " 8 2***", " 2 ****"])
False
"""
new_board = []
for i in range(len(board)):
new_board.append('')
for i in board:
for j in range(len(i)):
new_board[j] = i[j] + new_board[j]
return check_rows(new_board)
def check_colored_cells(board: list)-> bool:
"""
Check if in colored cells are the same numbers
>>> check_colored_cells(["**** ****", "***1 ****", "** 3****", "* 4 1****", \
" 9 5 ", " 6 83 *", "3 1 **", " 8 2***", " 2 ****"])
True
"""
color = ['', '', '', '', '']
for i in range(5):
for col in range(5):
color[i] = color[i] + board[8-i-col][i]
for row in range(5):
color[i] = color[i] + board[8-i][row+i]
color[i] = color[i][1:]
return check_rows(color)
def validate_board(board: list)-> bool:
"""
Check if board is ready for game
"""
return check_colored_cells(board) and \
check_columns(board) and check_rows(board)