-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_player_dec.py
More file actions
136 lines (104 loc) · 3.45 KB
/
4_player_dec.py
File metadata and controls
136 lines (104 loc) · 3.45 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import pyscript
import random
from js import document
def generate_board():
ores = ['ore'] * 3
woods = ['wood'] * 4
bricks = ['brick'] * 3
sheeps = ['sheep'] * 4
hays = ['hay'] * 4
deserts = ['desert'] * 1
resources = ores + woods + bricks + hays + deserts + sheeps
random.shuffle(resources)
random.shuffle(resources)
random.shuffle(resources)
random.shuffle(resources)
random.shuffle(resources)
random.shuffle(resources)
board_resources = [
['-1', '-1', ' ', '-1', '-1'],
['-1', ' ', ' ', ' ', '-1'],
[' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' '],
]
for row in range(5):
for column in range(5):
if board_resources[row][column] != '-1':
board_resources[row][column] = resources.pop()
# print("Resources:")
# for row in range(6):
# print(board_resources[row])
board_tokens=[2,3,4,5,6,8,9,10,11,12,2,3,4,5,6,8,9,10,11,12]
additional_tokens =[2,3,4,5,6,8,9,10,11,12]
random.shuffle(additional_tokens)
while len(board_tokens) < 28:
board_tokens.append(additional_tokens.pop())
board_numbers = [
['-1', '-1', ' ', '-1', '-1'],
['-1', ' ', ' ', ' ', '-1'],
[' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' '],
]
for row in range(5):
for column in range(5):
if board_numbers[row][column] != '-1':
if board_resources[row][column] != 'desert':
# print(f"Len: {len(board_tokens)} at {row} {column}")
board_numbers[row][column] = board_tokens.pop()
# print("----")
# print("Tokens:")
# for row in range(6):
# print(board_numbers[row])
return board_resources, board_numbers
def generate_row(row_num, board_resources, board_numbers):
# print(f"Numbers: {board_numbers}")
row_cards_html = ""
for i in range(len(board_resources)):
resource = board_resources[i]
number = board_numbers[i]
if resource == '-1':
continue
row_cards_html += f'<img class="tile" src="{resource}.png" alt="{resource} Tile">\n'
row_cards_html += f'<div class="text-overlay"><p class="text-overlay-text">{number}</p></div>'
# print("---")
# print(row_cards_html)
if row_num % 2 == 0:
# Even row
return f"""
<div class="row">
{row_cards_html}
</div>
"""
else:
# Odd row
return f"""
<div class="row odd-row">
{row_cards_html}
</div>
"""
def generate():
"""Generates a random board"""
# print("Generating board 123...")
output_div = document.querySelector("#output")
board_resources, board_numbers = generate_board()
new_board = ""
row = 0
for row in range(5):
row_resources = []
row_numbers = []
for x in board_resources:
row_resources.append(x[row])
for x in board_numbers:
row_numbers.append(x[row])
# print(f"Row resources: {row_numbers}")
new_board += generate_row(
row_num=row,
board_resources=row_resources,
board_numbers=row_numbers
)
row+=1
output_div.innerHTML = new_board
# pyscript.write("output", "you clicked the button")
return "Board generated"