Skip to content

Commit

Permalink
Added option to generate without game balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
wcolding committed Jan 16, 2024
1 parent 294194f commit 399e903
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
3 changes: 2 additions & 1 deletion App.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def generate():
data_string = request.form.get('checksJSON')
data = json.loads(data_string)
include_game_names = request.form.get('includeGameName')
balancing = request.form.get('balanceGames')
game_data = data['games']
print(game_data)

board = GenerateBoard(game_data, 25, include_game_names)
board = GenerateBoard(game_data, 25, include_game_names, balancing)
return render_template('App.html', games = games, presets = presets, generated = board, last_setting = data_string)

if __name__ == '__main__':
Expand Down
35 changes: 30 additions & 5 deletions src/Bingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
print(f'Preset found: "{preset_name}"')
presets.append(contents)

def GetCheck(selected_game, check_name) -> dict | None:
for entry in games:
if entry['game'] == selected_game:
for check in entry['checks']:
if check['name'] == check_name:
return check

def GetNextCheck(game_json: dict) -> dict | None:
next_json = game_json['checks'].pop()
selected_game = game_json['game']
Expand All @@ -39,7 +46,7 @@ def GetNextCheck(game_json: dict) -> dict | None:
for check in entry['checks']:
if check['name'] == next_json:
return check

def CheckObjectiveUsed(game_name: str, check: dict, collection: list) -> bool:
obj_type_str = str(check['obj_type'])
obj_string = f'{game_name}:{obj_type_str}'
Expand Down Expand Up @@ -68,6 +75,16 @@ def GenerateBoard(data: list, target: int, include_game_name = False, balancing
for game in data:
random.shuffle(game['checks'])

if not balancing:
new_data = []
for game in data:
new_data_checks = game['checks']
for check_name in new_data_checks:
check = GetCheck(game['game'], check_name)
check['game'] = game['game']
new_data.append(check)
random.shuffle(new_data)

while (generating):
if balancing:
for game in data:
Expand All @@ -85,11 +102,19 @@ def GenerateBoard(data: list, target: int, include_game_name = False, balancing

new_check['name'] = name
board.append(new_check)
else:
pass
#print(f'Game: {game_name} is out of checks!')
else:
pass # todo: make one new big list from which to generate
next_check = new_data.pop()
name = next_check['name']
game_name = next_check['game']

if not CheckSharedObjectiveUsed(game_name, next_check, used_objectives):
new_check = {}

if include_game_name:
name = f'[{game_name}] {name}'

new_check['name'] = name
board.append(new_check)

if len(board) >= target:
generating = False
Expand Down
10 changes: 9 additions & 1 deletion static/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ body {

.bigButton {
padding: 10px;
font-size: large;
}

.generateSection {
margin-top: 10px;
margin-bottom: 10px;
font-size: large;
}

.checksCount {
Expand Down Expand Up @@ -79,4 +82,9 @@ body {
.presetLoad {
display: inline-block;
font-size: large;
}

.optionsSection {
display: inline-block;
vertical-align: middle;
}
13 changes: 11 additions & 2 deletions templates/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@
<div class="objsCounter">Exclusive Checks: 0</div>
<form method="post" action="/generate">
<input type="hidden" id="checksJSONData" name="checksJSON" value="">
<input class="bigButton" id="generateButton" type="submit" value="Generate" disabled>
<input type="checkbox" name="includeGameName">Include game name in squares
<div class="generateSection">
<input class="bigButton" id="generateButton" type="submit" value="Generate" disabled>
<div class="optionsSection">
<input type="checkbox" name="balanceGames" id="balanceGamesBox" checked="true">
<label for="balanceGamesBox">Balance games</label>
<br>
<input type="checkbox" name="includeGameName" id="includeGameNameBox">
<label for="includeGameNameBox">Include game name in squares</label>
</div>
</div>

</form>
<button class="bigButton" onclick="copyBoard()" {% if generated == '' %}disabled{% endif %}>Copy to Clipboard</button>
<button onclick="copySelectedAsPreset()">Copy selected as Preset</button>
Expand Down

0 comments on commit 399e903

Please sign in to comment.