fix database regarding difference of no and empty color/rank clues

This commit is contained in:
Maximilian Keßler 2023-05-12 23:52:04 +02:00
parent b29b7af2b0
commit 98c9f56f36
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 26 additions and 16 deletions

View file

@ -159,8 +159,10 @@ def init_static_tables():
synesthesia = var.get('synesthesia', False)
chimneys = var.get('chimneys', False)
funnels = var.get('funnels', False)
no_color_clues = var.get('colorCluesTouchNothing', False)
no_rank_clues = var.get('rankCluesTouchNothing', False)
no_color_clues = var.get('clueColors', None) == []
no_rank_clues = var.get('clueRanks', None) == []
empty_color_clues = var.get('colorCluesTouchNothing', False)
empty_rank_clues = var.get('rankCluesTouchNothing', False)
odds_and_evens = var.get('oddsAndEvens', False)
up_or_down = var.get('upOrDown', False)
critical_fours = var.get('criticalFours', False)
@ -171,7 +173,6 @@ def init_static_tables():
special_rank_no_colors = var.get('specialNoClueColors', False)
special_rank_all_colors = var.get('specialAllClueColors', False)
special_rank = var.get('specialRank', None)
clue_ranks = var.get('clueRanks', [1, 2, 3, 4, 5])
assert(not all([special_rank_all_ranks, special_rank_no_ranks]))
assert(not all([special_rank_all_colors, special_rank_no_colors]))
@ -182,15 +183,15 @@ def init_static_tables():
cur.execute(
"INSERT INTO variants ("
"id, name, clue_starved, throw_it_in_a_hole, alternating_clues, synesthesia, chimneys, funnels,"
"no_color_clues, no_rank_clues, odds_and_evens, up_or_down, critical_fours, num_suits, special_rank,"
"special_rank_ranks, special_rank_colors"
"no_color_clues, no_rank_clues, empty_color_clues, empty_rank_clues, odds_and_evens, up_or_down,"
"critical_fours, num_suits, special_rank, special_rank_ranks, special_rank_colors"
")"
"VALUES"
"(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
"(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
(
var_id, name, clue_starved, throw_it_in_a_hole, alternating_clues, synesthesia, chimneys, funnels,
no_color_clues, no_rank_clues, odds_and_evens, up_or_down, critical_fours, num_suits, special_rank,
special_rank_ranks, special_rank_colors
no_color_clues, no_rank_clues, empty_color_clues, empty_rank_clues, odds_and_evens, up_or_down,
critical_fours, num_suits, special_rank, special_rank_ranks, special_rank_colors
)
)

View file

@ -62,6 +62,8 @@ CREATE TABLE variants (
funnels BOOLEAN NOT NULL DEFAULT FALSE,
no_color_clues BOOLEAN NOT NULL DEFAULT FALSE,
no_rank_clues BOOLEAN NOT NULL DEFAULT FALSE,
empty_color_clues BOOLEAN NOT NULL DEFAULT FALSE,
empty_rank_clues BOOLEAN NOT NULL DEFAULT FALSE,
odds_and_evens BOOLEAN NOT NULL DEFAULT FALSE,
up_or_down BOOLEAN NOT NULL DEFAULT FALSE,
critical_fours BOOLEAN NOT NULL DEFAULT FALSE,

View file

@ -1,5 +1,6 @@
import enum
from typing import List
from hanabi import DeckCard, ActionType
from database import cur
@ -76,8 +77,8 @@ class Suit:
class Variant:
def __init__(
self, name, clue_starved, throw_it_in_a_hole, alternating_clues, synesthesia, chimneys, funnels,
no_color_clues, no_rank_clues, odds_and_evens, up_or_down, critical_fours, special_rank,
special_rank_ranks, special_rank_colors, suits: List[Suit]
no_color_clues, no_rank_clues, empty_color_clues, empty_rank_clues, odds_and_evens, up_or_down,
critical_fours, special_rank, special_rank_ranks, special_rank_colors, suits: List[Suit]
):
self.name = name
self.clue_starved = clue_starved
@ -88,6 +89,8 @@ class Variant:
self.funnels = funnels
self.no_color_clues = no_color_clues
self.no_rank_clues = no_rank_clues
self.empty_color_clues = empty_color_clues
self.empty_rank_clues = empty_rank_clues
self.odds_and_evens = odds_and_evens
self.up_or_down = up_or_down
self.critical_fours = critical_fours
@ -99,20 +102,24 @@ class Variant:
self.suits = suits
self.colors = []
for suit in self.suits:
for color in suit.colors:
if color not in self.colors:
self.colors.append(color)
if not self.no_color_clues:
for suit in self.suits:
for color in suit.colors:
if color not in self.colors:
self.colors.append(color)
self.num_colors = len(self.colors)
def rank_touches(self, card: DeckCard, value: int):
pass
@staticmethod
def from_db(var_id):
cur.execute(
"SELECT "
"name, clue_starved, throw_it_in_a_hole, alternating_clues, synesthesia, chimneys, funnels, "
"no_color_clues, no_rank_clues, odds_and_evens, up_or_down, critical_fours, special_rank, "
"special_rank_ranks, special_rank_colors "
"no_color_clues, no_rank_clues, empty_color_clues, empty_rank_clues, odds_and_evens, up_or_down,"
"critical_fours, special_rank, special_rank_ranks, special_rank_colors "
"FROM variants WHERE id = %s",
(var_id,)
)