Code reorganizing
This commit is contained in:
+29
-18
@@ -25,7 +25,7 @@ var symptoms_arrays: Array[Array] = [
|
||||
["HETERO-AGRESSIVE BEHAVIOUR", "VISUAL HALLUCINATIONS"]
|
||||
]
|
||||
#Lists of possible patients sorted by floor
|
||||
var patient_list : Array[Array]
|
||||
var patient_list : Array[Dictionary]
|
||||
|
||||
#Supervisor file path
|
||||
var supervisor_name = "loeveth"
|
||||
@@ -55,18 +55,10 @@ func build_dialog_tree(tree_model: Array[int]) -> Dictionary: #Builds the dialog
|
||||
return tree
|
||||
|
||||
|
||||
func new_patient():
|
||||
func new_patient(patient_id):
|
||||
|
||||
var file_path: String
|
||||
|
||||
#Generating patient_id
|
||||
var floor_index = -Globals.floor_count -1
|
||||
print("Floor Index: " + str(floor_index))
|
||||
var patient_id = weighted_random(patient_list[floor_index])
|
||||
Globals.patient_id = patient_id
|
||||
Globals.patient_list.erase(patient_id) #Line to be reenabled when there is more than one patient in the list
|
||||
Globals.patients_seen.append(patient_id)
|
||||
|
||||
#Loading Patient Files
|
||||
var config := ConfigFile.new()
|
||||
file_path = "res://Dialogues/Patients/patient_" + patient_id + "_file.cfg"
|
||||
@@ -154,7 +146,7 @@ func sort_patients():
|
||||
break
|
||||
if symptom_matched:
|
||||
for k in range(j, symptoms_arrays.size()):
|
||||
patient_list[k].append({"patient_id": patient_id, "weight": j+1})
|
||||
patient_list[k].merge({patient_id: j+1}) # Adds the patient to every floor compatible
|
||||
symptom_matched = false
|
||||
break
|
||||
|
||||
@@ -163,22 +155,41 @@ func sort_patients():
|
||||
|
||||
|
||||
#Weighted random selection from an Array
|
||||
func weighted_random(array: Array):
|
||||
func weighted_random(patients: Dictionary):
|
||||
|
||||
#Calculating total weight
|
||||
var total_weight : int
|
||||
for item in array:
|
||||
total_weight += item.weight
|
||||
for weight in patients.values():
|
||||
total_weight += weight
|
||||
print("Total weight: " + str(total_weight))
|
||||
|
||||
var r = randf() * total_weight
|
||||
print("r :" + str(r))
|
||||
|
||||
var weight_sum : int
|
||||
for item in array:
|
||||
weight_sum += item.weight
|
||||
for patient_id in patients:
|
||||
weight_sum += patients[patient_id]
|
||||
if weight_sum >= r:
|
||||
print("Patient selected: " + item.patient_id + ", Weight: " + str(item.weight))
|
||||
return item.patient_id
|
||||
print("Patient selected: " + patient_id + ", Weight: " + str(patients[patient_id]))
|
||||
return patient_id
|
||||
return null
|
||||
|
||||
|
||||
func generate_patient_id() -> String: #Generates a patient ID
|
||||
|
||||
#Generating patient_id
|
||||
var floor_index = -Globals.floor_count -1
|
||||
print("Floor Index: " + str(floor_index))
|
||||
var patient_id = weighted_random(patient_list[floor_index]) #Picks a random patient depending on floor, with weighted odds
|
||||
|
||||
for j in range(len(patient_list)):
|
||||
if len(patient_list[j]) > 1:
|
||||
patient_list[j].erase(patient_id) #Removes picked patient from unseen patients list
|
||||
print("Updated Floor " + str(j) + " list: " + str(patient_list[j]))
|
||||
|
||||
#Updates global variables
|
||||
Globals.patient_id = patient_id
|
||||
Globals.patients_seen.append(patient_id)
|
||||
|
||||
return patient_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user