-
Notifications
You must be signed in to change notification settings - Fork 0
/
Boardmaker.py
99 lines (78 loc) · 2.23 KB
/
Boardmaker.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import random
obs1 = [[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[2, 0, 1, 0],
[2, 0, 0, 0]]
obs2 = [[0, 0, 0, 2],
[0, 1, 0, 2],
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]]
obs3 = [[0, 0, 0, 0, 0, 2, 2],
[0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0],
[2, 2, 0, 0, 0, 0, 0]]
obs4 = [[2, 2, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0],
[0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 2, 2]]
obs5 = [[0, 0, 0, 2],
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]]
obs6 = [[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[2, 0, 0, 0]]
obs7 = [[0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0]]
obs8 = [[0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0],
[0, 1, 1, 1, 1, 0],
[0, 1, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0]]
obs9 = [[0, 0, 0],
[0, 1, 0],
[0, 1, 0],
[0, 1, 0],
[0, 1, 0],
[0, 0, 0]]
obstacles = [obs1, obs2, obs3, obs4, obs5, obs6, obs7, obs8, obs9]
def makeEmptyBoard(n):
board = []
for i in range(n):
board.append([2] * n)
return board
def isLegalChange(board, obs, i, j):
rows = len(obs)
cols = len(obs[0])
if (i + rows > len(board)) or (j + cols > len(board)):
return False
for row in range(rows):
for col in range(cols):
if board[i + row][j + col] != 2:
return False
return True
def makeChange(board, obs, i, j):
rows = len(obs)
cols = len(obs[0])
for row in range(rows):
for col in range(cols):
board[i + row][j + col] = obs[row][col]
def change2s(board, n):
for i in range(n):
for j in range(n):
if board[i][j] == 2:
board[i][j] = 0
def makeBoard(n, shapes):
board = makeEmptyBoard(n)
for i in range(n):
for j in range(n):
if ((i > 3) or (j > 3)) and ((i < n - 7) or (j < n - 6)):
obs = random.choice(shapes)
if isLegalChange(board, obs, i, j):
makeChange(board, obs, i, j)
change2s(board, n)
return board