Skip to content

Commit

Permalink
Save current work.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Dec 28, 2023
1 parent eec88a1 commit d13ca32
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .gut_editor_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
"show_help": false,
"suffix": ".gd",
"tests": [],
"unit_test_name": "test_college_town_plan"
"unit_test_name": null
}
14 changes: 0 additions & 14 deletions goal_task_tests/domains/college_town_domain.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
158 changes: 118 additions & 40 deletions goal_task_tests/game_problems/test_magical_town_planner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
[
[
Expand All @@ -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
#]
]
)

0 comments on commit d13ca32

Please sign in to comment.