-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEndScene.gd
117 lines (100 loc) · 4.44 KB
/
EndScene.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
extends Node2D
var world_prob_array = Globals.final_world_prob_array
# https://www.reddit.com/r/godot/comments/b6wn9j/creating_a_gradient_instance_in_a_script/
var colors = Globals.colors
var colors_array = Globals.colors_array
onready var treasureLabel = $TreasureLabel
onready var AILabel = $AIDetails
var observed_estimated_label = ""
# Called when the node enters the scene tree for the first time.
func _ready():
if Globals.play_mode == "manual":
observed_estimated_label = "Observed: "
else:
observed_estimated_label = "Estimated: "
var step = Globals.color_step
var idx = 0.0
var cell_size = 52
for color in colors_array:
colors.add_point(idx, color)
idx = min(idx + step, .999)
# setting a color at point 1.0 failed to add it correctly to the end of the gradient
var margin_left = 0
var margin_top = 0
var new_font: DynamicFont = DynamicFont.new()
new_font.font_data = load("res://Fonts/8-bit-operator/8bitOperatorPlus-Regular.ttf")
new_font.size = 5
for cell in world_prob_array.keys():
var x = ColorRect.new()
var lab = Label.new()
x.name = str(cell)
margin_left = (int(cell[1])*cell_size)+32+2
margin_top = (int(cell[4])*cell_size)+45+2
x.rect_position = Vector2(margin_left, margin_top)
x.rect_size = Vector2(cell_size*.95,cell_size*.95)
lab.rect_position = Vector2(margin_left, margin_top)
lab.rect_size = Vector2(cell_size*.9,cell_size*.9)
if world_prob_array.get(str(cell))['Times_Dug'] == 0.0:
if Globals.play_mode == "manual":
lab.text = "Not Explored!" + "\n\nActual:" + str(world_prob_array.get(str(cell))['Prob']) + "\n"
x.color = Color(0, .5, 0, 0.25)
else:
lab.text = "Not Explored!\n\n" + observed_estimated_label + str(stepify(world_prob_array.get(str(cell))['Prob_Estimate'],0.01)) + "\n\nActual:" + str(world_prob_array.get(str(cell))['Prob']) + "\n"
x.color = Color(0, .5, 0, 0.25)
else:
lab.text = observed_estimated_label + str(stepify(world_prob_array.get(str(cell))['Prob_Observed'],0.01)) + "\n\nActual: " + str(world_prob_array.get(str(cell))['Prob']) + "\n\nTimes Dug: " + str(world_prob_array.get(str(cell))['Times_Dug'])
x.color = colors.interpolate(clamp(world_prob_array[str(cell)]['Prob_Observed'], 0.01, 0.99))
#lab.set("theme_override_font_sizes/font_size", 8)
#lab.add_theme_font_size_override("font_size", 8)
lab.set("custom_fonts/font", new_font)
lab.align = 1
lab.valign = 1
#lab.autowrap = true
add_child(x)
add_child(lab)
# Add smaller grid showing actual probabilities
for cell in world_prob_array.keys():
var x = ColorRect.new()
var lab = Label.new()
x.name = str(cell + "_actual")
margin_left = (int(cell[1])*16)+340+2
margin_top = (int(cell[4])*16)+84+2
x.rect_position = Vector2(margin_left, margin_top)
x.rect_size = Vector2(14,14)
x.color = colors.interpolate(clamp(world_prob_array[str(cell)]['Prob'], 0.01, 0.99))
lab.rect_position = Vector2(margin_left-1, margin_top-1)
lab.rect_size = Vector2(16,16)
lab.set("custom_fonts/font", new_font)
lab.text = str(stepify(world_prob_array.get(str(cell))['Prob'],0.01))
lab.align = 1
lab.valign = 1
add_child(x)
add_child(lab)
# Add smaller grid showing observed probabilities
for cell in world_prob_array.keys():
var x = ColorRect.new()
var lab = Label.new()
x.name = str(cell + "_actual")
margin_left = (int(cell[1])*16)+340+2
margin_top = (int(cell[4])*16)+210+2
x.rect_position = Vector2(margin_left, margin_top)
x.rect_size = Vector2(14,14)
lab.rect_position = Vector2(margin_left-1, margin_top-1)
lab.rect_size = Vector2(16,16)
if world_prob_array.get(str(cell))['Times_Dug'] == 0.0:
x.color = Color(0, .5, 0, 0.25)
else:
x.color = colors.interpolate(clamp(world_prob_array[str(cell)]['Prob_Observed'], 0.01, 0.99))
lab.text = str(stepify(world_prob_array.get(str(cell))['Prob_Observed'],0.01))
lab.set("custom_fonts/font", new_font)
lab.align = 1
lab.valign = 1
add_child(x)
add_child(lab)
treasureLabel.text += str(Globals.treasure_count) + " pieces"
# Add variable tracking times moved and times dug (exploit/explore measure of some kind)
AILabel.text = "Times Moved: " + str(Globals.times_moved) + "\nTimes Dug: " + str(Globals.times_dug)
if Globals.play_mode == "ai_simple":
AILabel.text += "\nExploitation Rate: " + str(Globals.agent_exploitation_rate)
elif Globals.play_mode == "ai_advanced":
AILabel.text += "\nExploitation Rate: " + str(Globals.agent_exploitation_rate) + "\nAgent Learning Rate: " + str(Globals.agent_learning_rate)