2024-05-22 06:45:43 +00:00
|
|
|
extends AIController2D
|
|
|
|
|
|
|
|
# meta-name: AI Controller Logic
|
|
|
|
# meta-description: Methods that need implementing for AI controllers
|
|
|
|
# meta-default: true
|
|
|
|
|
|
|
|
#-- Methods that need implementing using the "extend script" option in Godot --#
|
|
|
|
|
|
|
|
@onready var player = $".."
|
|
|
|
@onready var bamboos = $"../../../Bamboos"
|
|
|
|
@onready var move: int
|
|
|
|
|
|
|
|
func get_obs() -> Dictionary:
|
2024-06-13 16:44:02 +00:00
|
|
|
var dict = {"obs":[
|
|
|
|
player.position.x,
|
|
|
|
player.position.y,
|
|
|
|
player.health,
|
|
|
|
player.experience,
|
|
|
|
]}
|
|
|
|
for bamboo in bamboos.get_children():
|
|
|
|
dict["obs"].append(bamboo.position.x)
|
|
|
|
dict["obs"].append(bamboo.position.y)
|
|
|
|
dict["obs"].append(bamboo.health)
|
|
|
|
dict["obs"].append(bamboo.position.direction_to(player.position).x)
|
|
|
|
dict["obs"].append(bamboo.position.direction_to(player.position).y)
|
|
|
|
return dict
|
2024-05-22 06:45:43 +00:00
|
|
|
|
|
|
|
func get_reward() -> float:
|
2024-06-13 16:44:02 +00:00
|
|
|
return reward
|
|
|
|
|
2024-05-22 06:45:43 +00:00
|
|
|
func get_action_space() -> Dictionary:
|
2024-06-13 16:44:02 +00:00
|
|
|
return {
|
|
|
|
"move" : {
|
|
|
|
"size": 5,
|
|
|
|
"action_type": "discrete"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-22 06:45:43 +00:00
|
|
|
func set_action(action) -> void:
|
2024-06-13 16:44:02 +00:00
|
|
|
move = action["move"]
|
2024-05-22 06:45:43 +00:00
|
|
|
# -----------------------------------------------------------------------------#
|
|
|
|
|
|
|
|
#-- Methods that can be overridden if needed --#
|
|
|
|
|
|
|
|
#func get_obs_space() -> Dictionary:
|
|
|
|
# May need overriding if the obs space is complex
|
|
|
|
# var obs = get_obs()
|
|
|
|
# return {
|
|
|
|
# "obs": {
|
|
|
|
# "size": [len(obs["obs"])],
|
|
|
|
# "space": "box"
|
|
|
|
# },
|
|
|
|
# }
|