rework variants file: use DB-based access to variants information
This commit is contained in:
parent
550df72a28
commit
a85d1e5f9a
1 changed files with 66 additions and 57 deletions
123
variants.py
123
variants.py
|
@ -1,70 +1,79 @@
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import networkx as nx
|
||||||
|
from collections import OrderedDict
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
from database import cur
|
||||||
|
|
||||||
|
|
||||||
# Some setup for conversion between variant id and name
|
def variant_id(name):
|
||||||
with open("variants.json", 'r') as f:
|
cur.execute(
|
||||||
VARIANTS = json.loads(f.read())
|
"SELECT id FROM variants WHERE name = %s",
|
||||||
|
(name,)
|
||||||
def variant_id(variant_name):
|
)
|
||||||
return next(var['id'] for var in VARIANTS if var['name'] == variant_name)
|
return cur.fetchone()[0]
|
||||||
|
|
||||||
def variant_name(variant_id):
|
|
||||||
return next(var['name'] for var in VARIANTS if var['id'] == variant_id)
|
|
||||||
|
|
||||||
def num_suits(variant_id):
|
|
||||||
return next(len(var['suits']) for var in VARIANTS if var['id'] == variant_id)
|
|
||||||
|
|
||||||
def properties(variant_id):
|
|
||||||
return next(var for var in VARIANTS if var['id'] == variant_id)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def variant_name(var_id):
|
||||||
x = set()
|
cur.execute(
|
||||||
c = set()
|
"SELECT name FROM variants WHERE id = %s",
|
||||||
for var in VARIANTS:
|
(var_id,)
|
||||||
for k in var.keys():
|
)
|
||||||
x.add(k)
|
return cur.fetchone()[0]
|
||||||
for s in var['suits']:
|
|
||||||
c.add(s)
|
|
||||||
for y in x:
|
|
||||||
print(y)
|
|
||||||
|
|
||||||
for s in c:
|
|
||||||
print(s)
|
|
||||||
|
|
||||||
# need: suit name -> colors
|
def num_suits(var_id):
|
||||||
|
cur.execute(
|
||||||
|
"SELECT num_suits FROM variants WHERE id = %s",
|
||||||
|
(var_id,)
|
||||||
|
)
|
||||||
|
return cur.fetchone()[0]
|
||||||
|
|
||||||
"""
|
|
||||||
# actual changes of theoretical instance
|
|
||||||
clueStarved
|
|
||||||
throwItInHole (no clues for fives)
|
|
||||||
|
|
||||||
# general restrictions on what clues are allowed
|
class Variant:
|
||||||
alternatingClues
|
def __init__(
|
||||||
clueColors
|
self, name, clue_starved, throw_it_in_a_hole, alternating_clues, synesthesia, chimneys, funnels,
|
||||||
clueRanks
|
no_color_clues, no_rank_clues, odds_and_evens, up_or_down, critical_fours, num_suits, special_rank,
|
||||||
synesthesia (no rank clused, but color touches rank as well)
|
special_rank_ranks, special_rank_colors, suits
|
||||||
|
):
|
||||||
|
self.name = name
|
||||||
|
self.clue_starved = clue_starved
|
||||||
|
self.throw_it_in_a_hole = throw_it_in_a_hole
|
||||||
|
self.alternating_clues = alternating_clues
|
||||||
|
self.synesthesia = synesthesia
|
||||||
|
self.chimneys = chimneys
|
||||||
|
self.funnels = funnels
|
||||||
|
self.no_color_clues = no_color_clues
|
||||||
|
self.no_rank_clues = no_rank_clues
|
||||||
|
self.odds_and_evens = odds_and_evens
|
||||||
|
self.up_or_down = up_or_down
|
||||||
|
self.critical_fours = critical_fours
|
||||||
|
self.num_suits = num_suits
|
||||||
|
self.special_rank = special_rank
|
||||||
|
self.special_rank_ranks = special_rank_ranks
|
||||||
|
self.special_rank_colors = special_rank_colors
|
||||||
|
|
||||||
# can be ignored
|
self.suits = suits
|
||||||
cowPig
|
|
||||||
duck
|
|
||||||
|
|
||||||
# -> use oracle?
|
@staticmethod
|
||||||
# clue touch changed
|
def from_db(var_id):
|
||||||
chimneys
|
cur.execute(
|
||||||
funnels
|
"SELECT "
|
||||||
colorCluesTouchNothing
|
"name, clue_starved, throw_it_in_a_hole, alternating_clues, synesthesia, chimneys, funnels, "
|
||||||
rankCluesTouchNothing
|
"no_color_clues, no_rank_clues, odds_and_evens, up_or_down, critical_fours, num_suits, special_rank, "
|
||||||
oddsAndEvens (ranks touch ranks of same parity)
|
"special_rank_ranks, special_rank_colors "
|
||||||
|
"FROM variants WHERE id = %s",
|
||||||
|
(var_id,)
|
||||||
|
)
|
||||||
|
var_properties = cur.fetchone()
|
||||||
|
|
||||||
# changes behaviour of ones or fives
|
cur.execute(
|
||||||
specialAllClueColors
|
"SELECT suit_id FROM variant_suits "
|
||||||
specialAllClueRanks
|
"WHERE variant_id = %s "
|
||||||
specialNoClueColors
|
"ORDER BY index",
|
||||||
specialNoClueRanks
|
(var_id,)
|
||||||
specialDeceptive
|
)
|
||||||
specialRank
|
var_suits = list(map(lambda x: x[0], cur.fetchall()))
|
||||||
|
|
||||||
upOrDown
|
return Variant(*var_properties, var_suits)
|
||||||
criticalFours
|
|
||||||
"""
|
|
||||||
|
|
Loading…
Reference in a new issue