-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_json.py
72 lines (60 loc) · 2.07 KB
/
parse_json.py
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
'''
File: parse_json.py
Authors: Joeri Bes, Haischel Dabian, Jim Buissink, Sebastiaan Joustra and
Wietze Slagman
Date: 16/06/2016
Python version: 3.x
Created for the Bomberbot coorporation
---------------------------------------------
File description:
This file contains functions in order to parse the json files from
the puzzles.
'''
import json
def get_tiles(filename):
'''Returns the tiles of the json file.'''
with open(filename) as data_file:
data = json.load(data_file)
return data["tiles"]
def get_dimensions(filename):
'''Returns the dimensions of the grid.'''
with open(filename) as data_file:
data = json.load(data_file)
return [data["dimension"]["cols"], data["dimension"]["rows"]]
def get_pos_player(filename):
'''Returns the start location of the user.'''
with open(filename) as data_file:
data = json.load(data_file)
return [data["posPlayer"]["x"], data["posPlayer"]["y"]]
def get_best_solutions(filename):
'''Returns the best solution as an integer.'''
with open(filename) as data_file:
data = json.load(data_file)
return data["solutions"]["best"]
def get_dir_player(filename):
'''Returns the start direction of the user, if there's no
start direction given, the direction is downwards.
'''
with open(filename) as data_file:
data = json.load(data_file)
try:
return data["dirPlayer"]
except KeyError:
return "down"
def get_demo(mission,level):
'''Returns a string of moves from the demo'''
with open("Json/demo.json") as data_file:
data = json.load(data_file)
try:
return [data[str(mission)][str(level)]["moveList"], \
data[str(mission)][str(level)]["goalsCollected"]]
except KeyError:
return None
def has_hammer(filename):
'''Returns if the user has the possibility of using a hammer.'''
with open(filename) as data_file:
data = json.load(data_file)
try:
return data["hammer"]
except KeyError:
return False