download game database
This commit is contained in:
parent
5e537423e9
commit
bbbdae0611
1 changed files with 25 additions and 5 deletions
|
@ -2,11 +2,12 @@ import requests
|
||||||
import requests_cache
|
import requests_cache
|
||||||
import json
|
import json
|
||||||
from sat import COLORS, solve
|
from sat import COLORS, solve
|
||||||
|
from database import Game, store, load, commit
|
||||||
|
|
||||||
session = requests_cache.CachedSession('hanab.live')
|
session = requests_cache.CachedSession('hanab.live')
|
||||||
|
|
||||||
def get(url):
|
def get(url):
|
||||||
print("sending request for " + url)
|
# print("sending request for " + url)
|
||||||
response = session.get("https://hanab.live/" + url)
|
response = session.get("https://hanab.live/" + url)
|
||||||
if not response.status_code == 200:
|
if not response.status_code == 200:
|
||||||
return None
|
return None
|
||||||
|
@ -22,8 +23,8 @@ def api(url):
|
||||||
link += "size=100"
|
link += "size=100"
|
||||||
return get(link)
|
return get(link)
|
||||||
|
|
||||||
#r = api("variants/0")
|
r = api("variants/0")
|
||||||
#print(json.dumps(r, indent=4))
|
print(json.dumps(r, indent=4))
|
||||||
|
|
||||||
def replay(seed):
|
def replay(seed):
|
||||||
r = api("seed/" + str(seed))
|
r = api("seed/" + str(seed))
|
||||||
|
@ -60,15 +61,34 @@ def solvable(replay):
|
||||||
return solve(deck_str, len(replay["players"]))
|
return solve(deck_str, len(replay["players"]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
num_entries = 0
|
||||||
|
for i in range(0,10000):
|
||||||
|
r = api("variants/0?page=" + str(i))
|
||||||
|
for row in r['rows']:
|
||||||
|
num_entries += 1
|
||||||
|
row.pop('users')
|
||||||
|
row.pop('datetime')
|
||||||
|
g = Game(row)
|
||||||
|
g.variant_id = 0
|
||||||
|
store(g)
|
||||||
|
|
||||||
|
print('considered {} entries'.format(num_entries))
|
||||||
|
commit()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
seeds = {2: [], 3: [], 4: [], 5: [], 6: []}
|
seeds = {2: [], 3: [], 4: [], 5: [], 6: []}
|
||||||
num_games = 0
|
num_games = 0
|
||||||
for i in range(0,1000):
|
for i in range(0,10000):
|
||||||
r = api("variants/0?page=" + str(i))
|
r = api("variants/0?page=" + str(i))
|
||||||
for row in r['rows']:
|
for row in r['rows']:
|
||||||
num_games += 1
|
num_games += 1
|
||||||
if row['seed'] not in seeds[row['num_players']]:
|
if row['seed'] not in seeds[row['num_players']]:
|
||||||
seeds[row['num_players']].append(row['seed'])
|
seeds[row['num_players']].append(row['seed'])
|
||||||
# print('found new non-max-game in 5p: ' + row['seed'])
|
# print('found new non-max-game in 5p: ' + row['seed'])
|
||||||
|
|
||||||
|
|
||||||
print('looked at {} games'.format(num_games))
|
print('looked at {} games'.format(num_games))
|
||||||
for i in range(2,7):
|
for i in range(2,7):
|
||||||
print("Found {} seeds in {}-player in database".format(len(seeds[i]), i))
|
print("Found {} seeds in {}-player in database".format(len(seeds[i]), i))
|
||||||
|
@ -88,7 +108,7 @@ for seed in hard_seeds:
|
||||||
s, sol = solvable(r)
|
s, sol = solvable(r)
|
||||||
if s:
|
if s:
|
||||||
print("Seed {} was found to be solvable".format(seed))
|
print("Seed {} was found to be solvable".format(seed))
|
||||||
print(sol)
|
# print(sol)
|
||||||
else:
|
else:
|
||||||
print("==============================")
|
print("==============================")
|
||||||
print("Found non-solvable seed {}", seed)
|
print("Found non-solvable seed {}", seed)
|
||||||
|
|
Loading…
Reference in a new issue