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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
var _koma = {
Fu: 0, Ky: 1, Ke: 2, Gi: 3, Ki: 4, Ka: 5, Hi: 6, Ou: 7,
To: 8, Ny: 9, Nk: 10, Ng: 11, Um: 13, Ry: 14,
MOJI: [
"歩", "香", "桂", "銀", "金", "角", "飛", "玉",
"と", "成香", "成桂", "成銀", "", "馬", "龍", "",
],
};
var _opt = {
NARI: 0x1, NARAZU: 0x2, UTSU: 0x4, DOU: 0x8, // 成, 不成, 打, 同
AGARU: 0x10, YORU: 0x20, HIKU: 0x40, YUKU: 0x80,
MIGI: 0x100, HIDARI: 0x200, SUGU: 0x400, // 右, 左, 直
// 上, 寄, 引, 行
TOURYOU: 0x1000, HANSOKU: 0x2000, SENNICHI: 0x4000, JISHOUGI: 0x8000,
// 投了, 反則負け, 千日手, 持将棋
MOJI: [
"成", "不成", "打", "同",
"上", "寄", "引", "行",
"右", "左", "直", "",
"投了", "反則負け", "千日手", "持将棋",
],
};
var _key = {
SEPARATOR: ":",
SASITE: "sasite",
KYOKUMEN: "kyokumen",
MOCHIGOMA: "mochigoma",
PLAYER: "player",
};
var _val = {
KOMADAI_LEN: 3,
NAME_LEN: 20,
VIEW_W: 300,
VIEW_H: 300,
MASU_W: 28,
MASU_H: 28,
KOMA_L: 24,
KOMADAI_H: 30,
KOMABAKO_W: 200,
KOMABAKO_H: 100,
};
var _str = {
SURU: "する", SHINAI: "しない",
HAYAI: "速い", FUTSUU: "普通", OSOI: "遅い",
KOUGO: "交互", JIYUU: "自由",
DEFAULT_PLAYERS: ["先手", "", "後手", ""],
MOCHIGOMA_EMPTY: "なし",
MOCHIGOMA_ALL: "残り全部",
SENTE: "▲", GOTE: "△",
KANSUUJI: "零一二三四五六七八九十",
ZENKAKU_SUUJI: "0123456789",
KOMA_FONT: _val.KOMA_L + "px 'Hiragino Mincho ProN'",
};
var _label = {
KYOUCHOU: "指し手の強調",
HANTEN: "盤面の反転",
SPEED: "再生速度",
TEBAN: "手番",
NEXT: "次の手の表示",
SETTING: "詳細設定",
END_SETTING: "設定終了",
PLAYER: ["<<", "<", "||", ">", ">>"],
MAIN: ["対局情報", "盤面編集", "棋譜編集", "棋譜読書"],
INFO: ["平手局面", "全て駒箱", "残り全部", "設定終了"],
BANMEN: ["盤面反転", "編集終了"],
KIFU: ["削除", "開始局面", "終局情報", "編集終了"],
IO: ["棋譜読込", "中止"],
NAMES: [
["", "持駒", "名前"],
["先手", _val.KOMADAI_LEN, _val.NAME_LEN],
["後手", _val.KOMADAI_LEN, _val.NAME_LEN],
],
MONDAI: ["一手戻す", "解答"],
KAITOU: ["問題"],
};
var _color = {
KOMA: "black",
PICK: "#c0c0c0",
KOMADAI: "#f0f0f0",
};
var _pointer = {
PRESSED: ("ontouchstart" in window) ?
"touchstart" : "mousedown",
RELEASED: ("ontouchstart" in window) ?
"touchend" : "mouseup",
};
var _msg = {
NARI: "成りますか?",
KAITOU: "解答を見ますか?",
MONDAI: "問題に戻りますか?",
};
var _war = {
LOST_KYOKUMEN: "局面情報が消去されますが、よろしいですか?",
LOST_KIFU: "棋譜情報が消去されますが、よろしいですか?",
REMOVE_AFTER: "この指し手以降を削除しますか?",
REMOVE_BEFORE: "この局面を開始局面にしますか?",
};
var _err = {
BROWSER_NOT_SUPPORTED: "ブラウザが対応していません",
BAD_QUALITY: "描画の質が正しくありません",
SASITE_END: "棋譜の途中でファイルの終端に達しました",
SASITE_POS: "指し手の位置が正しくありません",
SASITE_KOMA: "指し手の駒が正しくありません",
SASITE_OPT: "指し手のオプションが正しくありません",
SASITE_RULE: "指し手がルールに反しています",
KYOKUMEN_FORMAT: "局面の書式が正しくありません",
KYOKUMEN_POS: "局面の位置が正しくありません",
KYOKUMEN_KOMA: "局面の駒が正しくありません",
KYOKUMEN_MOCHIGOMA: "局面の持駒が正しくありません",
KYOKUMEN_SASITE: "局面の指し手が正しくありません",
KYOKUMEN_KINJITE: "局面に禁じ手があります",
KYOKUMEN_OVER: "局面に駒が多すぎます",
PLAYER_FORMAT: "対局者の書式が正しくありません",
MOCHIGOMA_MODE: "持駒のモードが正しくありません",
};
var _util = {
arr_copy: function(a) {
return a.concat();
},
arr_equals: function(a, b) {
if (a.length != b.length) return false;
for (var i = 0; i < a.length; i++)
if (a[i] != b[i]) return false;
return true;
},
is_digit: function(c) { return c.match(/^\d$/) != null; },
parse_digit: function(c) {
if (_util.is_digit(c)) return parseInt(c);
var index;
if ((index = _str.KANSUUJI.indexOf(c)) == -1)
index = _str.ZENKAKU_SUUJI.indexOf(c);
return index;
},
opt_moji: function(flag) {
if (flag == 0) return "";
for (var i = 0; i < 16; i++)
if ((0x1 << i) == flag) return _opt.MOJI[i];
return "";
},
max_len: function(s, len) {
if (s.length <= len) return s;
return s.substring(0, len);
},
onload: function(callback) {
window.addEventListener("DOMContentLoaded", callback);
},
touched: function(div, callback) {
div.addEventListener(_pointer.PRESSED, function(e) {
var x, y;
if (e.type == "touchstart") {
x = e.touches[0].clientX;
y = e.touches[0].clientY;
} else {
x = e.clientX;
y = e.clientY;
}
var rc = e.target.getBoundingClientRect();
x -= rc.left; y -= rc.top;
callback(x, y);
});
},
add_panel: function(div) {
var panel = document.createElement("div");
panel.className = "panel";
div.appendChild(panel);
return panel;
},
change_panel: function(div, index) {
var panels = div.getElementsByClassName("panel");
[].forEach.call(panels, function(panel, i) {
panel.style.display = (i == index) ? "block" : "none";
});
},
add_menu: function(div, cmds, callback) {
var btn;
for (cmd of cmds) {
btn = _util.create_element("button", cmd);
btn.addEventListener("click", function(e) {
callback(cmds.indexOf(e.target.innerHTML));
});
div.appendChild(btn);
}
},
create_element: function(tag_name, text, class_name) {
var e = document.createElement(tag_name);
e.innerHTML = text;
if (class_name != undefined) e.className = class_name;
return e;
},
get_text: function(e) { return e.textContent; },
set_text: function(e, text) { e.textContent = text; },
set_options: function(e, options, b_show_next) {
for (var i = e.length - 1; i >= 0; i--)
e.remove(i);
if (!b_show_next) e.add(new Option("?"));
for (var option of options)
e.add(new Option(option.to_string()));
},
};