-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimulatorKuhn.java
More file actions
69 lines (66 loc) · 2.33 KB
/
Copy pathSimulatorKuhn.java
File metadata and controls
69 lines (66 loc) · 2.33 KB
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
import java.util.*;
import java.io.File;
public class SimulatorKuhn
{
public static final int NUM_PLAYERS = 2;
public static final int TOTAL_GAME_ACTIONS = 2;
public static final String log_dir_path = "logs/";
public static final int ITERAION_GAP = 1;
public static final boolean UPDATE_STRATEGY_CSV = false;
public static void main(String[] args) // function Solve in the algorithm.
{
CsvFileWriter CsvWriter = new CsvFileWriter();
create_logs_dir();
int num_iterations;
if (args.length == 0)
{
num_iterations =500000;
}
else
{
num_iterations = Integer.valueOf(args[0]);
}
System.out.format("num_iterations is %d\n",num_iterations);
//TrainCFR_Vanilla trainer= new TrainCFR_Vanilla();
//TrainCFR_CS trainer= new TrainCFR_CS();
TrainCFR_Vanilla_trim_weighted trainer= new TrainCFR_Vanilla_trim_weighted();
//TrainCFR_Vanilla_prune trainer= new TrainCFR_Vanilla_prune();
//TrainMCCFR trainer= new TrainMCCFR();
double utility[] = new double[NUM_PLAYERS];
double utility_avg[] = new double[NUM_PLAYERS];
for (int iteration = 0; iteration < num_iterations; iteration++)
{
for (int player=0;player < NUM_PLAYERS;player++)
{
HistoryNodeKuhn h = new HistoryNodeKuhn(NUM_PLAYERS, TOTAL_GAME_ACTIONS);
utility[player] += trainer.cfr(h,player,iteration,1.0,1.0);
}
if (iteration % ITERAION_GAP == 0) {
System.out.println("iterations passed: " + iteration);
if (UPDATE_STRATEGY_CSV == true) {
trainer.update_strategy_csv(log_dir_path);
for (int j=0;j<NUM_PLAYERS;j++){
utility_avg[j] = utility[j] / (iteration+1);
}
CsvWriter.write(log_dir_path + "util_hist.csv", utility_avg[0] + "," +utility_avg[1] + "," + String.valueOf(iteration) + ","+ VisitedNodesCounter.to_String());
}
}
}
CsvWriter.flush_close();
trainer.create_infoset_csv(log_dir_path);
trainer.print();
for (int j=0;j<NUM_PLAYERS;j++){
System.out.print("player " + String.valueOf(j) + " utility:");
System.out.println(utility[j] / num_iterations);
}
System.out.println("total decision nodes visited: " + VisitedNodesCounter.to_String());
}
static void create_logs_dir()
{
File log_dir = new File(log_dir_path);
log_dir.mkdir();
for (File sub : log_dir.listFiles()) {
sub.delete();
}
}
}