-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_game.jl
117 lines (101 loc) · 3.48 KB
/
run_game.jl
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
include("src/game.jl")
include("src/simulation.jl")
include("src/utils.jl")
using DataFrames
using CSV
using Serialization
using ProgressBars
# TODO set and variate text generation length? --> kinda covered with dialog steps. should be irrelevant
# TODO Number of teams and players does not affect bench data --> should also cut it?
# TODO Add sanity check (at least one action taken and add invalid flag?) --> do in data analysis
# Everything not set will result in usage of default values
conf = init_sim_conf(
# model="gpt-4-1106-preview",
model="gpt-3.5-turbo-16k",
# secret_key=get(ENV, "OPENAI_API_KEY", ""),
# wargame_dir="wargame/",
# output_dir="results/",
# out_csv_file="",
use_dummygpt=true,
use_bench_players=true,
no_dialog=false,
no_chiefs=false,
boostrap_players=true,
pacificsm=false,
sociopaths=false,
more_disagreement=false,
verbose=false,
# save_results_to_csv=true,
run_test_game=true,
n_teams=10,
n_players=6,
n_dialog_steps=3,
)
function run_simulation(config::SimulationConfig)
# Prepare the connection to the GPT model
# TODO? turn into assert and combine with && !config.use_dummygpt
if config.secret_key == ""
@warn "OPENAI_API_KEY not set in ENV"
end
chat_setup = ChatSetup(config.secret_key, config.model, config.use_dummygpt)
# Setup the results dataframe and game dir
res = results_df(config)
# Setup outpuf file names
if config.out_csv_file == ""
ending = create_file_ending(config.output_dir)
data_filename = config.output_dir * "data" * ending * ".csv"
else
data_filename = config.output_dir * config.out_csv_file
end
if conf.use_bench_players
test_data = deserialize("wargame/test_data.jls")
treatments = test_data[1]
teams = test_data[2]
else
# Generate Treatments
treatments = gen_all_treatments(config)
# Generate teams
teams = gen_teams(config)
end
if conf.pacificsm
for (team_ind, team) in enumerate(teams)
teams[team_ind] = [changeXP_player(p, "Strict pacifist") for p in team]
end
elseif conf.sociopaths
for (team_ind, team) in enumerate(teams)
teams[team_ind] = [changeXP_player(p, "Aggressive sociopath") for p in team]
end
end
# Run a test game or all treatments * teams
if config.run_test_game
result = run_game(config, treatments[1], teams[1], chat_setup)
push!(res, result)
# Write the results DataFrame to a CSV file
if config.save_results_to_csv
CSV.write(data_filename, res)
end
else
# Run the games
for (j, team) in ProgressBar(enumerate(teams))
println("Team: ", j)
for (i, game) in ProgressBar(enumerate(treatments))
println("Running treatment: ", i)
try
result = run_game(config, game, team, chat_setup)
push!(res, result)
# Write the results DataFrame to a CSV file
if config.save_results_to_csv
CSV.write(data_filename, res)
end
catch e
println(e)
sleep(10)
end
end
end
end
return res
end
# run_simulation(SimulationConfig())
# run_simulation(SimulationConfig(run_test_game=true, verbose=true, use_dummygpt=true))
run_simulation(conf)