-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCsvFileReader.java
More file actions
88 lines (85 loc) · 2.59 KB
/
Copy pathCsvFileReader.java
File metadata and controls
88 lines (85 loc) · 2.59 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.TreeMap;
public class CsvFileReader {
static final String COMMA_DELIMITER = ",";
static final String NEW_LINE_SEPARATOR = "\n";
static private BufferedReader br;
public void read (String filename ,TreeMap<String,double[]> strategy_profile){
try {
br = new BufferedReader(new FileReader(filename));
String line;
while ((line = br.readLine()) != null) {
String[] line_split = line.split(COMMA_DELIMITER);
String infoset = line_split[0];
double[] strategy = new double[line_split.length-1];
for (int i=0; i<strategy.length; i++) {
strategy[i] = Double.parseDouble(line_split[i+1]);
}
strategy_profile.put(infoset, strategy);
}
br.close();
}
catch (IOException e) {
System.out.println("CsvReader: Error in reading " + filename);
e.printStackTrace();
}
}
public void read_game_settings(String filename, String[] settings_name, int[] settings_value)
{
try {
int i=0;
br = new BufferedReader(new FileReader(filename));
String line;
while ((line = br.readLine()) != null) {
String[] line_split = line.split(COMMA_DELIMITER);
String name = line_split[0];
settings_name[i] = name;
int value = Integer.parseInt(line_split[1]);
settings_value[i] = value;
i++;
}
br.close();
}
catch (IOException e) {
System.out.println("CsvReader: Error in reading " + filename);
e.printStackTrace();
}
}
public void read_bet_sum(String filename, int[] bet_sum, int rounds)
{
try {
int i=0;
br = new BufferedReader(new FileReader(filename));
String line;
while ((line = br.readLine()) != null) {
String[] line_split = line.split(COMMA_DELIMITER);
String name = line_split[0];
if (name.equals("bet_sum")) {
assert (line_split.length-1 == rounds);
for (int j=1; j<line_split.length; j++) {
bet_sum[j-1] = Integer.parseInt(line_split[j]);
}
br.close();
return;
}
i++;
}
br.close();
}
catch (IOException e) {
System.out.println("CsvReader: Error in reading " + filename);
e.printStackTrace();
}
assert(false); //bet_sum wasn't found
}
public void close() {
try {
br.close();
} catch (IOException e) {
System.out.println("Error while flushing/closing CsvfileWriter !!!");
e.printStackTrace();
}
}
}