-
Notifications
You must be signed in to change notification settings - Fork 0
/
position_system_print.go
437 lines (362 loc) · 13 KB
/
position_system_print.go
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
package take13
import (
"bytes"
"fmt"
l02 "github.com/muzudho/kifuwarabe-wcsc31/lesson02"
l03 "github.com/muzudho/kifuwarabe-wcsc31/lesson03"
l07 "github.com/muzudho/kifuwarabe-wcsc31/take7"
)
// Print - 2局面の比較用画面出力(^q^)
func (pPosSys *PositionSystem) SprintDiff(b1 PosLayerT, b2 PosLayerT) string {
var phase_str string
switch pPosSys.GetPhase() {
case l03.FIRST:
phase_str = "First"
case l03.SECOND:
phase_str = "Second"
default:
phase_str = "?"
}
// 0段目
zeroRanks := [10]string{" 9", " 8", " 7", " 6", " 5", " 4", " 3", " 2", " 1", " "}
// 0筋目
zeroFiles := [9]string{" a ", " b ", " c ", " d ", " e ", " f ", " g ", " h ", " i "}
// 0段目、0筋目に駒置いてたらそれも表示(^~^)
for file := 9; file > -1; file -= 1 {
if !pPosSys.PPosition[b1].IsEmptySq(l03.Square(file*10)) || !pPosSys.PPosition[b2].IsEmptySq(l03.Square(file*10)) {
zeroRanks[10-file] = fmt.Sprintf("%2s%2s", pPosSys.PPosition[b1].Board[file*10].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10].ToCodeOfPc())
}
}
// 0筋目
for rank := l03.Square(1); rank < 10; rank += 1 {
if !pPosSys.PPosition[b1].IsEmptySq(rank) || !pPosSys.PPosition[b2].IsEmptySq(rank) {
zeroFiles[rank-1] = fmt.Sprintf("%2s%2s", pPosSys.PPosition[b1].Board[rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[rank].ToCodeOfPc())
}
}
lines := []string{}
lines = append(lines, "\n")
lines = append(lines, fmt.Sprintf("[%d -> %d moves / %s / ? repeats]\n", pPosSys.StartMovesNum, (pPosSys.StartMovesNum+pPosSys.OffsetMovesIndex), phase_str))
lines = append(lines, "\n")
lines = append(lines, " k r b g s n l p\n")
lines = append(lines, "+----+----+----+----+----+----+----+----+\n")
// bytes.Bufferは、速くはないけど使いやすいぜ(^~^)
var buf bytes.Buffer
for i := l03.HAND_TYPE_SIZE; i < l03.HAND_IDX_END; i++ {
buf.WriteString(fmt.Sprintf("|%2d%2d", pPosSys.PPosition[b1].Hands1[i], pPosSys.PPosition[b2].Hands1[i]))
}
buf.WriteString("|\n")
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+\n")
buf.Reset()
for i := 0; i < 10; i += 1 {
buf.WriteString(zeroRanks[i])
}
buf.WriteString("\n")
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank := 1
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 2
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 3
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 4
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 5
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 6
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 7
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 8
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
buf.Reset()
rank = 9
for file := 9; file > 0; file-- {
buf.WriteString(fmt.Sprintf("|%2s%2s", pPosSys.PPosition[b1].Board[file*10+rank].ToCodeOfPc(), pPosSys.PPosition[b2].Board[file*10+rank].ToCodeOfPc()))
}
buf.WriteString(fmt.Sprintf("|%s\n", zeroFiles[rank-1]))
lines = append(lines, buf.String())
lines = append(lines, "+----+----+----+----+----+----+----+----+----+\n")
lines = append(lines, "\n")
lines = append(lines, " K R B G S N L P\n")
lines = append(lines, " +----+----+----+----+----+----+----+----+\n")
buf.Reset()
buf.WriteString(" ")
for i := l03.HAND_IDX_BEGIN; i < l03.HAND_TYPE_SIZE; i++ {
buf.WriteString(fmt.Sprintf("|%2d%2d", pPosSys.PPosition[b1].Hands1[i], pPosSys.PPosition[b2].Hands1[i]))
}
buf.WriteString("|\n")
lines = append(lines, buf.String())
lines = append(lines, " +----+----+----+----+----+----+----+----+\n")
lines = append(lines, "\n")
lines = append(lines, "moves")
lines = append(lines, pPosSys.createMovesText())
lines = append(lines, "\n")
buf.Reset()
for _, line := range lines {
buf.WriteString(line)
}
return buf.String()
}
// SprintSfen - SFEN文字列返せよ(^~^)投了図を返すぜ(^~^)棋譜の部分を捨てるぜ(^~^)
func (pPosSys *PositionSystem) SprintSfenResignation(pPos *Position) string {
// 9x9=81 + 8slash = 89 文字 なんだが成り駒で増えるし めんどくさ(^~^)多めに取っとくか(^~^)
// 成り駒2文字なんで、byte型だとめんどくさ(^~^)
buf := make([]byte, 0, 200)
spaces := 0
for rank := l03.Square(1); rank < 10; rank += 1 {
for file := l03.Square(9); file > 0; file -= 1 {
piece := pPos.Board[SquareFrom(file, rank)]
if piece != l03.PIECE_EMPTY {
if spaces > 0 {
buf = append(buf, OneDigitNumbers[spaces])
spaces = 0
}
pieceString := piece.ToCodeOfPc()
length := len(pieceString)
switch length {
case 2:
buf = append(buf, pieceString[0])
buf = append(buf, pieceString[1])
case 1:
buf = append(buf, pieceString[0])
default:
panic(App.LogNotEcho.Fatal("LogicError: length=%d", length))
}
} else {
// Space
spaces += 1
}
}
if spaces > 0 {
buf = append(buf, OneDigitNumbers[spaces])
spaces = 0
}
if rank < 9 {
buf = append(buf, '/')
}
}
// 手番
var phaseStr string
switch pPosSys.GetPhase() {
case l03.FIRST:
phaseStr = "b"
case l03.SECOND:
phaseStr = "w"
default:
panic(App.LogNotEcho.Fatal("LogicalError: Unknows phase=[%d]", pPosSys.GetPhase()))
}
// 持ち駒
hands := ""
// 玉は出力できません
// num := pPos.Hands1[l03.HAND_K1]
// if num == 1 {
// hands += "K"
// } else if num > 1 {
// hands += fmt.Sprintf("K%d", num)
// }
num := pPos.Hands1[l03.HAND_R1]
if num == 1 {
hands += "R"
} else if num > 1 {
hands += fmt.Sprintf("R%d", num)
}
num = pPos.Hands1[l03.HAND_B1]
if num == 1 {
hands += "B"
} else if num > 1 {
hands += fmt.Sprintf("B%d", num)
}
num = pPos.Hands1[l03.HAND_G1]
if num == 1 {
hands += "G"
} else if num > 1 {
hands += fmt.Sprintf("G%d", num)
}
num = pPos.Hands1[l03.HAND_S1]
if num == 1 {
hands += "S"
} else if num > 1 {
hands += fmt.Sprintf("S%d", num)
}
num = pPos.Hands1[l03.HAND_N1]
if num == 1 {
hands += "N"
} else if num > 1 {
hands += fmt.Sprintf("N%d", num)
}
num = pPos.Hands1[l03.HAND_L1]
if num == 1 {
hands += "L"
} else if num > 1 {
hands += fmt.Sprintf("L%d", num)
}
num = pPos.Hands1[l03.HAND_P1]
if num == 1 {
hands += "P"
} else if num > 1 {
hands += fmt.Sprintf("P%d", num)
}
// 玉は出力できません
// num := pPos.Hands1[l03.HAND_K2]
// if num == 1 {
// hands += "k"
// } else if num > 1 {
// hands += fmt.Sprintf("k%d", num)
// }
num = pPos.Hands1[l03.HAND_R2]
if num == 1 {
hands += "r"
} else if num > 1 {
hands += fmt.Sprintf("r%d", num)
}
num = pPos.Hands1[l03.HAND_B2]
if num == 1 {
hands += "b"
} else if num > 1 {
hands += fmt.Sprintf("b%d", num)
}
num = pPos.Hands1[l03.HAND_G2]
if num == 1 {
hands += "g"
} else if num > 1 {
hands += fmt.Sprintf("g%d", num)
}
num = pPos.Hands1[l03.HAND_S2]
if num == 1 {
hands += "s"
} else if num > 1 {
hands += fmt.Sprintf("s%d", num)
}
num = pPos.Hands1[l03.HAND_N2]
if num == 1 {
hands += "n"
} else if num > 1 {
hands += fmt.Sprintf("n%d", num)
}
num = pPos.Hands1[l03.HAND_L2]
if num == 1 {
hands += "l"
} else if num > 1 {
hands += fmt.Sprintf("l%d", num)
}
num = pPos.Hands1[l03.HAND_P2]
if num == 1 {
hands += "p"
} else if num > 1 {
hands += fmt.Sprintf("p%d", num)
}
if hands == "" {
hands = "-"
}
// 手数
movesNum := pPosSys.StartMovesNum + pPosSys.OffsetMovesIndex
// 指し手
// moves_text := pPosSys.createMovesText()
// return fmt.Sprintf("position sfen %s %s %s %d moves%s\n", buf, phaseStr, hands, movesNum, moves_text)
return fmt.Sprintf("position sfen %s %s %s %d\n", buf, phaseStr, hands, movesNum)
}
// SprintRecord - 棋譜表示(^~^)
func (pPosSys *PositionSystem) SprintRecord() string {
// "8h2b+ b \n" 1行9byteぐらいを想定(^~^)
record_text := make([]byte, 0, l02.MOVES_SIZE*9)
for i := 0; i < pPosSys.OffsetMovesIndex; i += 1 {
record_text = append(record_text, pPosSys.Moves[i].ToCodeOfM()...)
record_text = append(record_text, ' ')
record_text = append(record_text, pPosSys.CapturedList[i].ToCodeOfPc()...)
record_text = append(record_text, '\n')
}
return fmt.Sprintf("Record\n------\n%s", record_text)
}
// Dump - 内部状態を全部出力しようぜ(^~^)?
func (pPosSys *PositionSystem) Dump() string {
// bytes.Bufferは、速くはないけど使いやすいぜ(^~^)
var buffer bytes.Buffer
for b := PosLayerT(0); b < 2; b += 1 {
pPos := pPosSys.PPosition[b]
buffer.WriteString(fmt.Sprintf("Board[%d]:", b))
for i := 0; i < POS_LAYER_SIZE; i += 1 {
buffer.WriteString(fmt.Sprintf("%d,", pPosSys.PPosition[i].Board))
}
buffer.WriteString("\n")
buffer.WriteString(fmt.Sprintf("KingLocations[%d]:%d,%d\n", b, pPos.PieceLocations[l07.PCLOC_K1], pPos.PieceLocations[l07.PCLOC_K2]))
buffer.WriteString(fmt.Sprintf("RookLocations[%d]:%d,%d\n", b, pPos.PieceLocations[l07.PCLOC_R1], pPos.PieceLocations[l07.PCLOC_R2]))
buffer.WriteString(fmt.Sprintf("BishopLocations[%d]:%d,%d\n", b, pPos.PieceLocations[l07.PCLOC_B1], pPos.PieceLocations[l07.PCLOC_B2]))
buffer.WriteString(fmt.Sprintf("LanceLocations[%d]:%d,%d,%d,%d\n", b, pPos.PieceLocations[l07.PCLOC_L1], pPos.PieceLocations[l07.PCLOC_L2], pPos.PieceLocations[l07.PCLOC_L3], pPos.PieceLocations[l07.PCLOC_L4]))
}
// 利きボード全部
for c := ControlLayerT(0); c < CONTROL_LAYER_ALL_SIZE; c += 1 {
buffer.WriteString(pPosSys.SprintControl(c))
}
for b := PosLayerT(0); b < 2; b += 1 {
buffer.WriteString(fmt.Sprintf("Position[%d]:", b))
buffer.WriteString("Hands:")
for i := l03.HAND_IDX_BEGIN; i < l03.HAND_IDX_END; i += 1 {
buffer.WriteString(fmt.Sprintf("%d,", pPosSys.PPosition[b].Hands1[i]))
}
buffer.WriteString("\n")
}
buffer.WriteString(fmt.Sprintf("Phase:%d,\n", pPosSys.GetPhase()))
buffer.WriteString(fmt.Sprintf("StartMovesNum:%d,\n", pPosSys.StartMovesNum))
buffer.WriteString(fmt.Sprintf("OffsetMovesIndex:%d,\n", pPosSys.OffsetMovesIndex))
buffer.WriteString("Moves:")
for i := 0; i < l02.MOVES_SIZE; i += 1 {
buffer.WriteString(fmt.Sprintf("%d,", pPosSys.Moves[i]))
}
buffer.WriteString("\n")
buffer.WriteString("CapturedList:")
for i := 0; i < l02.MOVES_SIZE; i += 1 {
buffer.WriteString(fmt.Sprintf("%d,", pPosSys.CapturedList[i]))
}
buffer.WriteString("\n")
return buffer.String()
}