Skip to content

Commit

Permalink
Add a game test.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Feb 19, 2024
1 parent 1dd7dd7 commit 6c85acf
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gut_editor_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"post_run_script": "",
"pre_run_script": "",
"prefix": "test_",
"selected": "test_construction.gd",
"selected": "test_game.gd",
"should_exit": true,
"should_exit_on_success": false,
"should_maximize": false,
Expand Down
2 changes: 1 addition & 1 deletion goal_task_tests/core_problems/test_construction.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2023-present. This file is part of V-Sekai https://v-sekai.org/.
# K. S. Ernest (Ilyes) Lee & Contributors (see .all-contributorsrc).
# K. S. Ernest (Fire) Lee & Contributors (see .all-contributorsrc).
# test_construction_project.gd
# SPDX-License-Identifier: MIT

Expand Down
131 changes: 131 additions & 0 deletions goal_task_tests/core_problems/test_game.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Copyright (c) 2023-present. This file is part of V-Sekai https://v-sekai.org/.
# K. S. Ernest (Fire) Lee & Contributors (see .all-contributorsrc).
# test_vr_community.gd
# SPDX-License-Identifier: MIT

extends GutTest
"""
A simplified example using the task_goal plugin framework for Godot
demonstrating the planning of activities involved in running a VR social
network like V-Sekai.
"""

var domain_name = "vr_community_management"
var the_domain = preload("res://addons/task_goal/core/domain.gd").new(domain_name)

var planner = preload("res://addons/task_goal/core/plan.gd").new()

# Types used for validation if necessary
@export var types = {
"activity": [
"initialize_virtual_environment",
"design_avatar_customization_options",
"implement_communication_systems",
"create_social_gathering_areas",
"develop_mini_games",
"set_up_event_scheduling",
"integrate_user_content_sharing",
"establish_community_guidelines",
"launch_public_beta_test",
"collect_beta_feedback",
"improve_based_on_feedback",
"finalize_platform_polishing",
"prepare_marketing_campaign",
"launch_full_platform",
"monitor_platform_stability",
"update_with_new_features",
"finish"
]
}

# Dependency graph for the activities
@export var dependencies: Dictionary = {
"initialize_virtual_environment": [],
"design_avatar_customization_options": ["initialize_virtual_environment"],
"implement_communication_systems": ["initialize_virtual_environment"],
"create_social_gathering_areas": ["implement_communication_systems"],
"develop_mini_games": ["create_social_gathering_areas", "design_avatar_customization_options"],
"set_up_event_scheduling": ["create_social_gathering_areas"],
"integrate_user_content_sharing": ["implement_communication_systems"],
"establish_community_guidelines": ["initialize_virtual_environment"],
"launch_public_beta_test": ["develop_mini_games", "establish_community_guidelines"],
"collect_beta_feedback": ["launch_public_beta_test"],
"improve_based_on_feedback": ["collect_beta_feedback"],
"finalize_platform_polishing": ["improve_based_on_feedback"],
"prepare_marketing_campaign": ["finalize_platform_polishing"],
"launch_full_platform": ["prepare_marketing_campaign"],
"monitor_platform_stability": ["launch_full_platform"],
"update_with_new_features": ["monitor_platform_stability"],
"finish": [
"update_with_new_features",
"launch_full_platform"
]
}

# Prototypical initial state, can include current progress, resources etc.
var state0: Dictionary = {
# Example state properties
"completed_activities": [],
"pending_activities": types["activity"] # Initial list from 'types'
}

# Helper functions:

func set_as_completed(state, activity_name):
if activity_name in state.pending_activities:
state.pending_activities.erase(activity_name)
state.completed_activities.append(activity_name)
return state


## Actions:

func complete_activity(state, activity) -> Variant:
if activity in state.pending_activities:
return set_as_completed(state, activity)
return false


## Methods:

func schedule_activity(state: Dictionary, activity: String) -> Array:
var actions = []

if not activity in state["pending_activities"]:
return []

for predecessor in dependencies[activity]:
if not predecessor in state["completed_activities"]:
actions.push_back(["schedule_activity", predecessor])

actions.append(["complete_activity", activity])

return actions


func _ready() -> void:
planner.domains.push_back(the_domain)
planner.current_domain = the_domain
planner.declare_actions([Callable(self, "complete_activity")])
planner.declare_task_methods(
"schedule_activity",
[
Callable(self, "schedule_activity"),
]
)

func test_vr_community_planning() -> void:
planner.current_domain = the_domain

# Example: Executing a single activity
var state1 = state0.duplicate(true)
var goals = [["schedule_activity", "finish"]]
var plan: Variant = planner.find_plan(state1, goals)

# Assert that plan is not false and has a positive size
assert_true( not plan is bool and plan.size() > 0)

gut.p("Plan to finish:")
if typeof(plan) == TYPE_ARRAY:
for action in plan:
gut.p("- %s" % str(action))

0 comments on commit 6c85acf

Please sign in to comment.