remove calculations from snake and move it into moves
This commit is contained in:
@@ -34,9 +34,10 @@ module default {
|
|||||||
readonly := true;
|
readonly := true;
|
||||||
on source delete delete target;
|
on source delete delete target;
|
||||||
}
|
}
|
||||||
required single snake: Snake {
|
single snake: Snake {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
on source delete delete target;
|
on source delete delete target;
|
||||||
|
on target delete allow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ module default {
|
|||||||
required is_ladder: bool {
|
required is_ladder: bool {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
}
|
}
|
||||||
|
#constraint exclusive on ( (.name, .is_ladder) );
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ruleset {
|
type Ruleset {
|
||||||
@@ -59,16 +61,13 @@ module default {
|
|||||||
required settings: json {
|
required settings: json {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
}
|
}
|
||||||
|
#constraint exclusive on ( (.name, .version, .settings) );
|
||||||
}
|
}
|
||||||
|
|
||||||
type Snake {
|
type Snake {
|
||||||
required type: str {
|
required type: str {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
}
|
}
|
||||||
required multi calculations: Calculations {
|
|
||||||
readonly := true;
|
|
||||||
on source delete delete target;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Moves {
|
type Moves {
|
||||||
@@ -81,12 +80,14 @@ module default {
|
|||||||
required game_board: json {
|
required game_board: json {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
}
|
}
|
||||||
|
single calculations: Calculations {
|
||||||
|
readonly := true;
|
||||||
|
on source delete delete target;
|
||||||
|
on target delete allow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Calculations {
|
type Calculations {
|
||||||
required turn: int32 {
|
|
||||||
readonly := true;
|
|
||||||
}
|
|
||||||
required data: array<json> {
|
required data: array<json> {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-13
@@ -19,6 +19,16 @@ class EdgeDB:
|
|||||||
is_ladder=is_ladder
|
is_ladder=is_ladder
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create_moves_with_calculations(self, game_board:GameBoard):
|
||||||
|
data = []
|
||||||
|
moves = game_board.turns
|
||||||
|
snake_calulations = [[calc for calc in ele["data"]] for ele in game_board.snake_class.get_history() ]
|
||||||
|
|
||||||
|
for i in range(len(moves)):
|
||||||
|
data.append({"turn": moves[i]["turn"], "move": moves[i]["move"], "game_board": moves[i]["game_board"], "calculations": snake_calulations[i]})
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def insert(self, game_board:GameBoard):
|
def insert(self, game_board:GameBoard):
|
||||||
game_type = game_board.get_type_of_game()
|
game_type = game_board.get_type_of_game()
|
||||||
|
|
||||||
@@ -31,12 +41,17 @@ class EdgeDB:
|
|||||||
map := <str>$map,
|
map := <str>$map,
|
||||||
winner := <str>$winner,
|
winner := <str>$winner,
|
||||||
moves := (
|
moves := (
|
||||||
with input_data := <array <tuple <turn: int32, `move`: str, game_board: json>> >$moves
|
with input_data := <array <tuple <turn: int32, `move`: str, game_board: json, calculations: array<json> >>>$moves
|
||||||
for data in array_unpack(input_data)
|
for data in array_unpack(input_data)
|
||||||
insert Moves {
|
insert Moves {
|
||||||
turn := data.turn,
|
turn := data.turn,
|
||||||
snake_move := data.`move`,
|
snake_move := data.`move`,
|
||||||
game_board := data.game_board
|
game_board := data.game_board,
|
||||||
|
calculations := (
|
||||||
|
insert Calculations {
|
||||||
|
data := data.calculations
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
type := (
|
type := (
|
||||||
@@ -54,15 +69,7 @@ class EdgeDB:
|
|||||||
),
|
),
|
||||||
snake := (
|
snake := (
|
||||||
insert Snake {
|
insert Snake {
|
||||||
type := <str>$snake_type,
|
type := <str>$snake_type
|
||||||
calculations := (
|
|
||||||
with input_data := <array <tuple <turn: int32, data: array<json>>> >$calculations
|
|
||||||
for tupel_data in array_unpack(input_data)
|
|
||||||
insert Calculations {
|
|
||||||
turn := tupel_data.turn,
|
|
||||||
data := tupel_data.data
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}""",
|
}""",
|
||||||
@@ -73,7 +80,7 @@ class EdgeDB:
|
|||||||
turns=game_board.turn,
|
turns=game_board.turn,
|
||||||
map=game_board.map if game_board.map else "standard",
|
map=game_board.map if game_board.map else "standard",
|
||||||
winner=', '.join(game_board.winner_snake_names) if game_board.winner_snake_names else "",
|
winner=', '.join(game_board.winner_snake_names) if game_board.winner_snake_names else "",
|
||||||
moves=[ tuple([ele["turn"], ele["move"], json.dumps(ele["game_board"])]) for ele in game_board.turns ],
|
moves=[ tuple([x["turn"], x["move"], json.dumps(x["game_board"]), [ json.dumps(ele) for ele in x["calculations"] ] ]) for x in self.create_moves_with_calculations(game_board) ],
|
||||||
|
|
||||||
game_type=game_type["name"],
|
game_type=game_type["name"],
|
||||||
is_ladder=game_type["is_ladder"],
|
is_ladder=game_type["is_ladder"],
|
||||||
@@ -83,7 +90,6 @@ class EdgeDB:
|
|||||||
settings=json.dumps(game_board.ruleset["settings"]),
|
settings=json.dumps(game_board.ruleset["settings"]),
|
||||||
|
|
||||||
snake_type=game_board.snake_class.__class__.__name__,
|
snake_type=game_board.snake_class.__class__.__name__,
|
||||||
calculations=[ tuple([ele["turn"], [json.dumps(calc) for calc in ele["data"]]]) for ele in game_board.snake_class.get_history() ],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self, game_board:GameBoard):
|
def save(self, game_board:GameBoard):
|
||||||
|
|||||||
Reference in New Issue
Block a user