-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadData.pde
78 lines (72 loc) · 2.35 KB
/
loadData.pde
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
//kif形式のtxtファイルを読むクラス
class LoadData{
String path;
String[] kifFile;
int handsStart;
int handsLength;
ArrayList<String> curHandsStr = new ArrayList<String>();
ArrayList<Integer> preHandsInt = new ArrayList<Integer>();
LoadData() {
path = "sample.txt";
kifFile = loadStrings(path);
loadTxt();
handsLength = curHandsStr.size();
println("手数:" + handsLength);
}
void loadTxt() {
for(int i=0; i<kifFile.length; i++) {
if(kifFile[i].indexOf("手数")!=-1) handsStart=i+1;
}
for(int i=handsStart; i<kifFile.length; i++) {
kifFile[i] = formatText(kifFile[i]);
separate(kifFile[i]);
}
formatToInt(); //curHandsStr例:77桂成 preHandsInt例:31
}
String formatText(String str) {
String[] newStr = str.split(" ");
str = newStr[1];
return str;
}
void separate(String str){
if(str.contains("投了")){
}else if(!str.contains("(")) { //持ち駒から指した場合など
curHandsStr.add(str);
preHandsInt.add(0);
}else {
String[] newStr = str.split("\\(");
curHandsStr.add(newStr[0]);
String pre = newStr[1].substring(0, newStr[1].length()-1); //()削除
preHandsInt.add(Integer.valueOf(pre));
}
}
void formatToInt() {
String cur = "";
for(int i = 0; i < curHandsStr.size(); i++) {
cur = curHandsStr.get(i);
if(i>0 && cur.contains("同")) {
//同を一個前の手に置き換え
for(int j = 1; j < i; j++){
if(!curHandsStr.get(i-j).contains("同")){
cur = cur.replace("同", curHandsStr.get(i-j).substring(0, 2));
break;
}
}
}
cur = cur.replace(" ", "").replace("打", "");
cur = cur.replace("一", "1").replace("1", "1");
cur = cur.replace("二", "2").replace("2", "2");
cur = cur.replace("三", "3").replace("3", "3");
cur = cur.replace("四", "4").replace("4", "4");
cur = cur.replace("五", "5").replace("5", "5");
cur = cur.replace("六", "6").replace("6", "6");
cur = cur.replace("七", "7").replace("7", "7");
cur = cur.replace("八", "8").replace("8", "8");
cur = cur.replace("九", "9").replace("9", "9");
curHandsStr.set(i, cur);
//print(cur);
//println("手:"+i);
//println(preHandsInt.get(i));
}
}
}