From d13ca3234ec6c52c4071374b4fcc4925ac6da0bb Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Thu, 28 Dec 2023 00:56:34 -0800 Subject: [PATCH] Save current work. --- .gut_editor_config.json | 2 +- .../domains/college_town_domain.gd | 14 -- .../test_magical_town_planner.gd | 158 +++++++++++++----- 3 files changed, 119 insertions(+), 55 deletions(-) diff --git a/.gut_editor_config.json b/.gut_editor_config.json index cbc1ded..018583a 100644 --- a/.gut_editor_config.json +++ b/.gut_editor_config.json @@ -41,5 +41,5 @@ "show_help": false, "suffix": ".gd", "tests": [], - "unit_test_name": "test_college_town_plan" + "unit_test_name": null } \ No newline at end of file diff --git a/goal_task_tests/domains/college_town_domain.gd b/goal_task_tests/domains/college_town_domain.gd index 8c17132..eb9f7a2 100644 --- a/goal_task_tests/domains/college_town_domain.gd +++ b/goal_task_tests/domains/college_town_domain.gd @@ -88,17 +88,3 @@ func distance_to(x: String, y: String) -> float: if result > 0: return result return INF - - -func create_room(room_name: String, size: String, style: String, purpose: String) -> Variant: - return [] - - -func place_furniture( - furniture: String, room_name: String, wall: String, direction: String, position: Dictionary -) -> Variant: - return [] - - -func change_layout() -> Variant: - return [] diff --git a/goal_task_tests/game_problems/test_magical_town_planner.gd b/goal_task_tests/game_problems/test_magical_town_planner.gd index e38e27f..98f6135 100644 --- a/goal_task_tests/game_problems/test_magical_town_planner.gd +++ b/goal_task_tests/game_problems/test_magical_town_planner.gd @@ -10,46 +10,124 @@ var the_domain = preload("res://goal_task_tests/domains/college_town_domain.gd") var planner = null +func create_room( + state: Dictionary, + room_name: String, + size: String, + style: String, + purpose: String, + pivot_dict: Dictionary, + footprint_dict: Dictionary, + time: int +) -> Dictionary: + var room = { + "size": size, + "style": style, + "purpose": purpose, + } + var furniture = [] + var footprint = {"pivot": Vector3i(footprint_dict["pivot"]), "footprint": Vector3i(footprint_dict["footprint"])} + + if not state.has("rooms"): + state["rooms"] = {} + if not state.has("furniture"): + state["furniture"] = {} + + state["rooms"][room_name] = "rooms_" + room_name + state["rooms_" + room_name] = room + state["furniture"][room_name] = "furniture_" + room_name + state["furniture_" + room_name] = furniture + state["footprints_" + room_name] = footprint + state["pivots_" + room_name] = Vector3i(pivot_dict["pivot"]) + + return state + + +func place_furniture( + state, + furniture: String, + room_name: String, + wall: String, + direction: String, + position: Dictionary +) -> Variant: + var furniture_item = { + "item": furniture, + "wall": wall, + "direction": direction, + "position": position, + } + + state["rooms"][room_name]["furniture"].append(furniture_item) + + return state + + +func task_design_room( + state: Dictionary, room_name: String, size: String, style: String, purpose: String +) -> Array: + return [ + [ + "create_room", + room_name, + size, + style, + purpose, + Vector3i(0, 0, 0), + Vector3i(5, 5, 3), + 10 + ], + ] + + +func task_change_layout(state, new_layout: Dictionary) -> Variant: + state["layout"] = new_layout + + return state + + func before_each(): planner = preload("res://addons/task_goal/core/plan.gd").new() - planner.verbose = 0 + planner.verbose = 3 var new_domain = the_domain.duplicate(true) planner.domains.push_back(new_domain) planner.current_domain = new_domain new_domain.simple_temporal_networks = {"Mia": SimpleTemporalNetwork.new()} - new_domain.types = {"character": ["Mia"], "room": ["bedroom1", "bedroom2"]} - planner.declare_actions( [ - Callable(planner.current_domain, "create_room"), - Callable(planner.current_domain, "place_furniture"), - Callable(planner.current_domain, "change_layout") + Callable(self, "create_room"), + Callable(self, "place_furniture"), + Callable(self, "change_layout") ] ) + planner.declare_task_methods("design_room", [Callable(self, "task_design_room")]) planner.declare_task_methods( - "design_room", - [ - Callable(planner.current_domain, "create_room"), - Callable(planner.current_domain, "place_furniture") - ] - ) - planner.declare_task_methods( - "redesign_apartment", [Callable(planner.current_domain, "change_layout")] + "redesign_apartment", [Callable(planner.current_domain, "task_change_layout")] ) func test_college_town_plan(): planner.verbose = 3 - var town_state: Dictionary = {} # TODO - var result = planner.find_plan( - town_state.duplicate(true), - [ - ["design_room", "bedroom1", "medium", "modern", "sleep"], - ["design_room", "bedroom2", "small", "vintage", "study"] - ] + var town_state: Dictionary = {} + + planner.current_domain.types = { + "rooms": ["rooms_bedroom1", "rooms_bedroom2"], + "furniture": ["furniture_bedroom1", "furniture_bedroom2"], + "footprints": ["footprints_bedroom1", "footprints_bedroom2"], + "pivots": ["pivots_bedroom1", "pivots_bedroom2"], + } + + var result = ( + planner + . find_plan(town_state, + [ + ["design_room", "bedroom1", "medium", "modern", "sleep"], + #["design_room", "bedroom2", "small", "vintage", "study"] + ] + ) ) - assert_ne_deep( + assert_eq_deep( result, [ [ @@ -70,23 +148,23 @@ func test_college_town_plan(): {"pivot": [2, 2, 0], "footprint": [3, 2, 1]}, 15 ], - [ - "create_room", - "bedroom2", - "small", - "vintage", - "study", - {"pivot": [6, 0, 0], "footprint": [4, 4, 3]}, - 30 - ], - [ - "place_furniture", - "desk", - "bedroom2", - "west-wall", - "facing-east", - {"pivot": [7, 2, 0], "footprint": [2, 1, 1]}, - 35 - ] + #[ + #"create_room", + #"bedroom2", + #"small", + #"vintage", + #"study", + #{"pivot": [6, 0, 0], "footprint": [4, 4, 3]}, + #30 + #], + #[ + #"place_furniture", + #"desk", + #"bedroom2", + #"west-wall", + #"facing-east", + #{"pivot": [7, 2, 0], "footprint": [2, 1, 1]}, + #35 + #] ] )