-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.jl
1617 lines (1506 loc) · 48 KB
/
app.jl
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Dash, JSON3, PlotlyJS
include("src/utility.jl")
function engine_ready(bot::String, proc::Base.Process)::Bool
while true
line = readline(proc)
if line == ""
print_diy("e", bot * " can not run", ln=false)
return false
elseif length(line) > 8 && line[7:9] == ": G"
print_diy("i", bot * " ready")
return true
else
println(line)
end
end
end
function run_engine()
bot = length(ARGS)==0 ? "k" : ARGS[1] # can only run KataGo currently
botCommand = Cmd(`julia src/terminal.jl $bot`, dir=dirname(@__FILE__))
botProcess = open(botCommand,"r+")
if ! engine_ready(bot, botProcess)
exit()
end
return botProcess
end
function end_engine()
query("quit")
reply()
close(engineProcess)
end
#=
function query()
sentence=""
while true
sentence=readline()
if sentence=="" || "" in split(sentence," ")
continue
else
println(engineProcess,sentence)
break
end
end
return sentence::String
end
=#
function query(sentence::String)
println(engineProcess,sentence)
#println(sentence)
end
function reply()
paragraph=""
while true
sentence=readline(engineProcess)
if sentence==""
break
else
paragraph="$paragraph$sentence\n"
end
end
#println(paragraph)
return paragraph::String
end
function color_stones(board)
colorStones::Vector{String}=[]
for vertex in board
if vertex == 0
colorStones=cat(colorStones,["rgba(0,0,0,0)"],dims=1)
elseif vertex == -1
colorStones=cat(colorStones,["rgba(0,0,0,1)"],dims=1)
elseif vertex == 1
colorStones=cat(colorStones,["rgba(255,255,255,1)"],dims=1)
else
continue
end
end
return colorStones
end
function odd_key_even_value(dictString;c=": ")
d=Dict{String,Any}()
k=""
j=1
if dictString[1]=='='
dictString=dictString[3:end]
c=[' ',':']
end
if dictString[1]=='R'
return Dict("Rules"=>odd_key_even_value(dictString[9:end-1];c=[':',',','"']))
end
for i in split(dictString,c;keepempty=false)
if j==1
k=i
j=0
else
if i in ["false","true"]
i=parse(Bool,i)
elseif tryparse(Int8,i) != nothing
i=tryparse(Int8,i)
elseif tryparse(Float64,i) != nothing
i=tryparse(Float64,i)
else
end
d[k]=i
j=1
end
end
return d
end
#=
function wait_showboard()
flag=true
paragraphVector=[]
while flag
query("showboard")
paragraph=reply()
#println(paragraph)
paragraphVector=split(paragraph,"\n",keepempty=false)
if length(paragraphVector)>2
flag=false
end
sleep(ℯ/π)
end
return paragraphVector
end
=#
function agent_showboard()
query("showboard")
paragraph=reply()
paragraphVector=split(paragraph,"\n",keepempty=false)
boardInfo=Dict{String,Any}()
n=0
for c in paragraphVector[2]
if c in 'A':'T'
n=n+1
end
end
m=3
b=Vector{Int8}()
while paragraphVector[m][1] in "1 "
for c in paragraphVector[m]
if c=='X'
b=cat(b,[-1],dims=1)
elseif c=='O'
b=cat(b,[1],dims=1)
elseif c=='.'
b=cat(b,[0],dims=1)
else
continue
end
end
m=m+1
end
colorStones=color_stones(b)
boardInfo["Board"] = b
boardInfo["Position"] = reshape(b,n,:)'
boardInfo["BoardColor"]=colorStones
boardInfo["BoardSize"]=[n,m-3]
for line in cat([paragraphVector[1]],paragraphVector[m:end],dims=1)
boardInfo=merge(boardInfo,odd_key_even_value(line))
end
boardInfo["checkBoard"]=cat(paragraphVector[2:m-1],[JSON3.write(boardInfo["Rules"])],dims=1)
query("printsgf")
sgfInfo=reply()[3:end]
boardInfo["sgf"]=sgfInfo
return boardInfo
end
function agent_showboard(paragraph)
paragraphVector=split(paragraph,"\n",keepempty=false)
boardInfo=Dict{String,Any}()
n=0
for c in paragraphVector[2]
if c in 'A':'T'
n=n+1
end
end
m=3
b=Vector{Int8}()
while paragraphVector[m][1] in "1 "
for c in paragraphVector[m]
if c=='X'
b=cat(b,[-1],dims=1)
elseif c=='O'
b=cat(b,[1],dims=1)
elseif c=='.'
b=cat(b,[0],dims=1)
else
continue
end
end
m=m+1
end
colorStones=color_stones(b)
boardInfo["Board"]=b
boardInfo["BoardColor"]=colorStones
boardInfo["BoardSize"]=[m-3,n]
for line in cat([paragraphVector[1]],paragraphVector[m:end],dims=1)
boardInfo=merge(boardInfo,odd_key_even_value(line))
end
println(boardInfo,"\n")
return boardInfo
end
function play()
while true
sentence=query()
paragraph=reply()
if occursin("quit",sentence)
break
elseif occursin("showboard",sentence)
boardInfo=agent_showboard(paragraph)
else
continue
end
end
end
#play()
#using PlotlyJS
function const_generate()
sgfX=cat(Vector('a' : 'k'),Vector('m' : 't'),dims=1)
sgfY=[c for c in reverse(sgfX)]
sgfXY=[string(sgfX[i],sgfY[j]) for j in 1:19 for i in 1:19]
gtpX=cat(['z'],Vector('a' : 'h'),Vector('j' : 'u'),dims=1)
gtpY=Vector(0:20)
gtpXY=["$j$i" for i in reverse(gtpY) for j in gtpX]
uiX=[uppercase(gtpX[i]) for i in 1:length(gtpX)]
uiY=[string(gtpY[j]) for j in 1:length(gtpY)]
uiXY=[(j,i) for i in reverse(uiY) for j in uiX]
return sgfX,sgfY,sgfXY,gtpX,gtpY,gtpXY,uiX,uiY,uiXY
end
const SGF_X,SGF_Y,SGF_XY,GTP_X,GTP_Y,GTP_XY,UI_X,UI_Y,UI_XY=const_generate()
function layout_board()
Layout(
# boardSize are as big as setting
# aspectmode="manual",aspectratio=1,,
#aspectmode="data",
#aspectratio=attr(x=1,y=1),
width=930,
height=836,
paper_bgcolor="rgb(0,255,127)",
plot_bgcolor="rgb(205,133,63)",
#plot_ratio=1,
#margin=attr(l=0,r=0,t=0,b=0),
xaxis_showgrid=false,
xaxis=attr(
# showline=true, mirror=true,linewidth=1,linecolor="black",
# zeroline=true,zerolinewidth=1,zerolinecolor="rgb(205,133,63)",
ticktext=UI_X,
tickvals=GTP_X
# if tickvals is a number array, row/col lines will become a line
),
yaxis_showgrid=false,
yaxis=attr(
# showline=true, mirror=true,linewidth=1,linecolor="black",
zeroline=false,
ticktext=UI_Y,
tickvals=GTP_Y
),
transition_duration = 500,
#=dragmode="drawopenpath",
newshape_line_color="cyan",
#title_text="Draw a path to separate versicolor and virginica",
modebar_add=[
"drawline",
"drawopenpath",
"drawclosedpath",
"drawcircle",
"drawrect",
"eraseshape"]=#
)
end
function line_fold(axisFold,axisCount)
lineFold=[axisFold[1],axisFold[end]]
N=length(axisCount)-1
for n in 1:N
if n%2==0
lineFold=cat(lineFold,[axisFold[1]],[axisFold[end]],dims=1)
else
lineFold=cat(lineFold,[axisFold[end]],[axisFold[1]],dims=1)
end
end
return lineFold
end
function trace_line(boardSize)
xLine=GTP_X[2:boardSize[1]+1]
yLine=GTP_Y[2:boardSize[2]+1]
rowX=line_fold(xLine,yLine)
rowY=[yItem for yItem in yLine for j in 1:2]
#colX=[xItem for xItem in xLine for i in 1:2]
colX=cat(
['z'],
[xLine[1]],
[xItem for xItem in xLine for i in 1:2],
[xLine[end]],
[GTP_X[boardSize[1]+2]],
dims=1
)
#=
colYLine=cat(
line_fold(yLine,xLine),
[boardSize[1]%2==0 ? yLine[1] : yLine[end]],
dims=1
)
=#
colYDotLine=cat(
[0],[nothing],line_fold(yLine,xLine),[nothing],
[GTP_Y[boardSize[2]+2]],
dims=1
)
#println(colYDotLine)
rowLine=scatter(
#x=['a','t','t','a','a','t','t','a','a','t','t','a',...,'a','t'],
#y=[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,...,19,19],
# use fold lines to plot row/col lines
x=rowX,
y=rowY,
mode="lines",
line_width=1,
line_color="rgb(0,0,0)",
hoverinfo = "skip",
name="row lines"
)
colLine=scatter(
#x=['z','a','a','b','b','c','c',...,'t','u'],
#y=[1,1,19,19,1,1,19,19,1,1,19,19,1,1,...,19,19],
# use (z,1) and (u,19) to widen col margin, if the board is 19x19
x=colX,
y=colYDotLine,
mode="lines",
line_width=1,
line_color="rgb(0,0,0)",
#marker_size=1,
#marker_color="rgb(0,0,0)",
hoverinfo = "skip",
name="col lines"
)
return colLine,rowLine
end
function star_count(axisNum)
starNum=0
if axisNum<7
starNum=0
else
if axisNum==7 || axisNum%2==0
starNum=2
else
starNum=3
end
end
#println(starNum)
return starNum
end
function star_margin(axisNum)
marginStar=4
if axisNum<=12 marginStar=3 end
#println(marginStar)
return marginStar
end
function star_cross(axisSize,starNum,starMargin)
starCross=[]
if starNum != 0
if starMargin==3
starCross=[4,axisSize-1]
else
starCross=[5,axisSize-2]
end
if starNum==3
starCross=cat(starCross,[div(axisSize+1,2)+1],dims=1)
end
end
#println(starCross)
return starCross
end
function trace_star(boardSize)
xBoard=boardSize[1]
yBoard=boardSize[2]
rowNum=star_count(xBoard)
colNum=star_count(yBoard)
numStar=rowNum*colNum
rowMargin=star_margin(xBoard)
colMargin=star_margin(yBoard)
xCrossIndex=star_cross(xBoard,rowNum,rowMargin)
yCrossIndex=star_cross(yBoard,colNum,colMargin)
xCross=[GTP_X[i] for i in xCrossIndex]
yCross=[GTP_Y[j] for j in yCrossIndex]
xStar=[xItem for xItem in xCross for k in 1:colNum]
yStar=repeat(yCross,rowNum)
#println("$xStar\n$yStar")
scatter(
x=xStar,
y=yStar,
mode="markers",
marker_color="rgb(0,0,0)",
name="star points"
)
end
function trace_stones(boardSize,colorVector)
xLine=GTP_X[2:boardSize[1]+1]
yLine=reverse(GTP_Y[2:boardSize[2]+1])
scatter(
x=repeat(xLine,boardSize[2]),
y=[yLine[i] for i in 1:boardSize[2] for j in 1:boardSize[1]],
mode="markers",
marker_color=colorVector,
marker_size=25,
name="stones"
)
end
function trace_synchroboard()
scatter(
x=['a','b'],
y=[0,0],
mode="markers+text",
marker=attr(
color="rgb(205,133,63)",
size=1
),
text=["PA","SS"],
textposition="inside",
textfont=attr(color="rgb(255,255,255)",size=25),
name="buttons"
)
end
function trace_resign()
scatter(
x=['d'],
y=[0],
mode="markers+text",
marker=attr(
color="rgb(205,133,63)",
size=1
),
text=["Resign"],
textposition="inside",
textfont=attr(color="rgb(0,0,0)",size=25),
name="resign"
)
end
#boardStone=
# colors are as many as players: black,white,blue,red...
whiteStone=scatter(
x=['k','d','r'],
y=[10,16,3],
mode="markers",
marker_color="rgb(255,255,255)",
marker_size=30,
name="White stones"
)
blackStone=scatter(
mode="markers+text",
x=['q','d','c'],
y=[16,3,6],
marker=attr(
color="rgb(0,0,0)",
size=30
),
text=["1","361"],
textposition="inside",
textfont=attr(color="rgba(255,255,255,1)",size=[24,12]),
name="Black stones"
)
ownership=scatter(
x=['q','q','r','k'], # i ?
y=[6,16,3,10],
mode="markers",
marker=attr(
symbol="diamond",
color=[
"rgba(127,127,127,0.6)","rgba(0,0,0,0.6)",
"rgba(255,255,255,0.6)","rgba(0,0,0,0.6)"
],
size=36,
# opacity=0.6,
line=attr(
width=0)
),
name="ownership"
)
#=
Basic symbols in PlotlyJS:
circle square diamond cross x
triangle pentagon hexagram star
hourglass bowtie asterisk hash y line
=#
function trace_marker()
rgbaRange = [
"rgba($r,$g,$b,1)"
for b in 0:85:255
for r in 0:85:255
for g in 0:85:255
#for a in 0.75:-0.01:0.25
]
rgbaRange = reverse(rgbaRange)
markers = scatter(
x = [GTP_X[i] for p in 1:4 for i in 2:14 ],
y = [GTP_Y[j] for j in 17:20 for q in 1:13 ],
mode = "markers",
marker = attr(
symbol = ["$k" for k in 101:152],
color = rgbaRange,
#["rgba($r,$g,$b,1)" for r in ],
size = 25,
line = attr(width = 3, color = rgbaRange)
),
name = "markers"
)
return markers
end
function trace_chess()
R,N,B,Q,K,P = '♖','♘','♗','♕','♔','♙'
r,n,b,q,k,p = '♜','♞','♝','♛','♚','♟'
chessPieces = scatter(
x = [GTP_X[i] for m in 1:4 for i in 2:9],
y = [j for j in [14.8,13.8,8.8,7.8] for n in 1:8],
mode = "text",
text = [
r,n,b,q,k,b,n,r,p,p,p,p,p,p,p,p,
P,P,P,P,P,P,P,P,R,N,B,Q,K,B,N,R
],
textposition = "bottom right",
textfont = attr(
size = 30,
color = "rgba(0,0,0,1)"
),
name = "chess pieces"
)
end
function plot_config()
none = nothing
PlotConfig(
scrollZoom = true,
responsive = true,
staticPlot = false,
displayModeBar = true,
doubleClickDelay = 300,
toImageButtonOptions=attr(
format="svg", # one of png, svg, jpeg, webp
filename="custom_image",
height = none, # to download at the currently-rendered size
width = none, # to download at the currently-rendered size
scale=1 # Multiply title/legend/axis/canvas sizes by this factor
).fields
)
end
function plot_board(boardSize,stones)
Plot(
[
trace_line(boardSize)[1],
trace_line(boardSize)[2],
trace_star(boardSize),
trace_synchroboard(),
trace_resign(),
trace_stones(boardSize,stones)
],
layout_board()
)
end
function plot_board(boardSize)
plot(
[
trace_line(boardSize)[1],
trace_line(boardSize)[2],
trace_star(boardSize),
whiteStone,
blackStone,
trace_marker(),
ownership,
trace_chess()
],
layout_board()
)
end
function main_board()
boardSize="19 19"
plot_board([parse(Int8,split(boardSize)[i]) for i in 1:2])
end
#main_board()
#include("board.jl")
topText="**Hi, welcome to VastGo!**
\n\nHave a nice game!"
bottomText=""
bottomMarkdown=dcc_markdown(bottomText)
#=
someIssues="
### VastGo is on basic testing, there are some issues need to solve:
- [x] KataGo starts up ***twice*?**(may need to add a `run KataGo` button in Dash APP or thread/coroutines or I/O redicect or import/using *.jl?)
- The [reason](https://community.plotly.com/t/why-global-code-runs-twice/12514).
- [x] You can do nothing except placing **legal** stones and `ctrl+R` to refresh.
- Now you can redefine a game in the `Begin` tab.
- [ ] Can not run in multiple tabs/browsers (how to know global or local states?)
- [x] Rules(GameInfo), SGF and Click are too long, and have no 'space' to segment.
- Use `dcc_textarea` instead of `dcc_markdown` or `html_div`.
- [x] Can not work in new version Dash because
- ArgumentError: PlotlyJS.SyncPlot doesn't have a defined `StructTypes.StructType`
- The repo using old version Dash because DashDaq added
- The [reason](https://github.com/plotly/Dash.jl/issues/153)
- [ ] Can not use DashBootstrapComponents to change app layout
- Weird syntax and not many documents/examples
- Auto delete some spaces in GTP-output
- [x] The board can not refresh autoly after change the size or obstacles.
- Type `clear_board.` in GTP commands input or click `PASS` in the board plot instead.
- Just add a `callback! Input`.
- [x] The whb in showboard not be displayed now.
- [ ] The number of obstacles doesn't fit boardSize.
- [x] Can not pass more than one time.
- Reason: `Dash.jl`'s clickEvent doesn't response to it.
- There are two pass buttons, **PA** and **SS**.
- [ ] **asyn**: `reply() != query()`
- [ ] KataGo returns answer 2 before answer 1 sonmetimes[?](https://github.com/lightvector/KataGo/blob/master/docs/GTP_Extensions.md)
- [ ] `Dash.jl` sends two commands at once sometimes.
- [x] The same two `clickData` does not run `callback!()` twice.
- It's a Dash's feature and doesn't need to solve."
=#
#----------------------------------------
# The up is tab1, the down is tab2
#----------------------------------------
whatgamesummary = html_summary("What's the game of Go/Baduk/Weiqi?")
whatgamemarkdown = dcc_markdown() do
"
\n>A turn-based abstract strategy board game, in which the aim is to
control more domains than the opponent. It was invented in China more
than **2,500 years** ago and is believed to be the oldest board game
continuously played to the present day.¹⁻²
\n> **Turn-based**: players take turns to play
\n> **Abstract**: not rely on a theme or simulate the real world
\n> **Strategy**: players' choices determine the outcome
\n> **Board Game**: a tabletop game that involves counters or pieces
moved or placed on a pre-marked surface or \"board\"
\n> **Tabletop Game**: played on a table or other flat surface, such
as board games, card games
"
end
whatgame = html_details([whatgamesummary,whatgamemarkdown])
howplaysummary = html_summary("How to play?")
howplaymarkdown = dcc_markdown() do
"
\n> [THE EASY WAY](https://www.usgo.org/learn-play) or
[THE HARD WAY](https://lightvector.github.io/KataGo/rules.html)
\n> **With bots**:
\n ![withbot](assets/withbot.png)
\n> **Free and Open Source Software** (FOSS):
\n> **GUIs**: Sabaki, Lizzie, KaTrain, GoReviewPartner, LizGoban, q5Go,
LizzieYzy, Ogatak, LeelaGUI, BadukAI, Drago, VastGo
\n> **GTP Engines**: KataGo, Leela-Zero, SAI, MiniGo, ELF, PhoenixGo,
Leela, Pachi, GNU Go, AQ, Ray
\n> **Models**: [KataGo's](https://katagotraining.org/),
[Leela-Zero's](https://zero.sjeng.org/),
[SAI's](http://sai.unich.it/)
\n> My favorites: Sabaki for editing, BadukAI for phones
and VastGo otherwise.
"
end
howplay = html_details([howplaysummary,howplaymarkdown])
isfunnysummary = html_summary("Is it funny?")
isfunnymarkdown = dcc_markdown() do
"
\n> **Yes**:
\n>easy rules, complex tactics
\n>rare draws ([~1‱](https://senseis.xmp.net/?NoResult))
\n>flexible
\n> **No**:
\n>silent
\n>AI advantages
\n>elementary (no ∞∂∫∇, only +-*/)
"
end
isfunny = html_details([isfunnysummary,isfunnymarkdown])
gotchasummary = html_summary("Gotcha")
gotchamarkdown = dcc_markdown(
"
\n> **Don't know terms**?
\n> [Sensei's Library](https://senseis.xmp.net/) (SL)
\n> **Can't find FOSS**?
\n> SL, [Github](https://github.com), [Bing](https://www.bing.com)
"
)
gotcha = html_details([gotchasummary,gotchamarkdown])
whatguisummary = html_summary("About")
whatguimarkdown = dcc_markdown(
"
\n> version: 0.0.1
\n> [readme](https://github.com/HackYardo/VastGo)
\n> [discuss without code](https://github.com/HackYardo/VastGo/discussions)
\n> [source code issues](https://github.com/HackYardo/VastGo/issues)
\n> [contributors](https://github.com/HackYardo/VastGo/graphs/contributors)
\n> [LICENSE](https://github.com/HackYardo/VastGo/blob/master/LICENSE.md)
"
)
whatgui = html_details([whatguisummary,whatguimarkdown])
guidediv = html_div([whatgame,isfunny,howplay,gotcha,whatgui])
rulesetReference=dcc_markdown() do
"**Rule Sets**³:"
end
rulesetButtons=html_div(style = Dict("columnCount" => 4)) do
html_button("Fuzhou-like Rules",id="fRule"),
html_button("Chinese-like Rules",id="cRule"),
html_button("Japaness-like Rules",id="jRule"),
html_button("Tromp-Taylor Rules",id="tRule"),
html_button("OGS/KGS \"Chinese\"-like Rules",id="oRule"),
html_button("AGA-like Rules",id="aRule"),
html_button("New Zealand-like Rules",id="zRule"),
html_button("Stone-Scoring Rules",id="sRule")
end
rulesetChecklists=html_div(style = Dict("columnCount" => 2)) do
html_label("X,Y:",title="Integers indicating the board size."),
dcc_input(id="SZ_X",value=19,type="number",min=2,step=1,max=19),
dcc_input(id="SZ_Y",value=19,type="number",min=2,step=1,max=19),
dcc_markdown(""),
html_label("Komi:",title="Integer or half-integer indicating compensation given to White for going second."),
dcc_input(id="KM",value=7.0,type="number",min=-150,step=0.5,max=150),
dcc_markdown(""),
html_label("KoRule:",title="The variant of the rule prohibiting repetition. https://senseis.xmp.net/?KoRules"),
dcc_radioitems(id="ko",
options = [
Dict("label" => "Simple", "value" => "SIMPLE"),
Dict("label" => "Positional Superko", "value" => "POSITIONAL"),
Dict("label" => "Situational Superko", "value" => "SITUATIONAL")
],
value = "POSITIONAL",
),
html_label("ScoringRule:",title="Defines what the score of a finished game is. Area (count stones and surrounded empty points, \"Chinese\"-like); Territory (count captures and surrounded empty points, \"Japanese\"-like). https://senseis.xmp.net/?Scoring"),
dcc_radioitems(id="score",
options = [
Dict("label" => "Area", "value" => "AREA"),
Dict("label" => "Territory", "value" => "TERRITORY")
],
value = "AREA",
),
html_label("TaxRule:",title="Minor adjustments to scoring rule, indicating what, if any, empty points may not be scored. None (surrounded empty points always count); Seki (empty points surrounded by groups in seki do not count); All (all groups are taxed up to 2 of their surrounded empty points - i.e. empty points surrounded by groups in seki do not count, and living groups are taxed 2 points each)."),
dcc_radioitems(id="tax",
options = [
Dict("label" => "None", "value" => "NONE"),
Dict("label" => "Seki", "value" => "SEKI"),
Dict("label" => "All", "value" => "ALL")
],
value = "NONE",
),
html_label("Button:",title="Whether a half-point is awarded to the first player to be able to pass. (e.g. slightly rewarding endgame efficiency, partially reconciling area and territory scoring)."),
dcc_radioitems(id="buttonRule",
options = [
Dict("label" => "Used", "value" => "true"),
Dict("label" => "Not Used", "value" => "false")
],
value = "true",
),
html_label("MultiStoneSuicide:",title="Whether suicide of multiple stones is allowed. (in these rules, a suicide move that kills only the stone just played and nothing else, leaving the board unchanged, is never allowed)"),
dcc_radioitems(id="sui",
options = [
Dict("label" => "Allowed", "value" => "true"),
Dict("label" => "Disallowed", "value" => "false")
],
value = "false",
),
html_label("WhiteHandicapBonus:",title="How many bonus points white receives during handicap games when black gets N stones. KataGo supports handicap games, but for simplicity, this rules document does NOT describe them. These checkboxes are included merely to provide a convenience reference as how this quirk of handicap game scoring differs between rulesets."),
dcc_radioitems(id="whb",
options = [
Dict("label" => "0", "value" => "0"),
Dict("label" => "N-1", "value" => "N-1"),
Dict("label" => "N", "value" => "N")
],
value = "0",
)
end
rulesetDiv=html_div() do
rulesetReference,
rulesetButtons,
rulesetChecklists
end
appendixDiv=dcc_markdown() do
"
\n**Appendix A Synonyms**:
\nsituation==position+turn, position==board+stones, ko==repeat, seki==symbiotic, handicap==obstacle, grid nodes==vertices
\n**Appendix B Tips**:
\n**a** If hover over the rule items, more details will be displayed.
\n**b** If modify the obstacles, X, Y, the board will be cleared.
\n**c** Button can't be used in territory-scoring.
\n**d** There are two pass buttons, **PA** and **SS**, used for consecutive passes.
\n**Appendix C References**:
\n***1*** [A Brief History of Go](https://www.usgo.org/brief-history-go). *American Go Association*, 2022
\n***2*** Peter Shotwell. [The Game of Go: Speculations on its Origins and Symbolism in Ancient China](https://www.usgo.org/sites/default/files/bh_library/originsofgo.pdf). *American Go Association*, 2008.
\n***3*** David J Wu. KataGo's Supported Go Rules (Version 2), 2021. https://lightvector.github.io/KataGo/rules.html. (not include the Fuzhou-like Rules)
"
end
ruleCheck=html_div() do
dcc_markdown("**Rule Check**:"),
html_button("SUBMIT",id="submitRule"),
html_div(),
dcc_textarea(
placeholder="To check if the whole rule is valid...",
id="confirmRule",
style=Dict("width"=>"390px","height"=>"360px")
),
html_div(),
html_button("OK",id="okRule")
end
startGame=html_div(style = Dict("columnCount" => 2)) do
guidediv,
dcc_markdown(
"
\n### Start Now:
\nJust skip the rule items below and go to the `While` tab to play a game.
\nOr check the items and click the `SUBMIT` to check the rule before a game.
\nA game will over after 1 resign or 2 consecutive passes*(not include the button-pass)*, and you will see the outcome.
"
),
html_label("To play first or not:"),
dcc_radioitems(id="playerColor",
options = [
Dict("label" => "Black", "value" => "B"),
Dict("label" => "White", "value" => "W")
],
value = "B"
),
html_label("Nonstandard Go, Move&Position:",title="Search on https://senseis.xmp.net/ for more details"),
dcc_radioitems(id="moveMode",
options = [
Dict("label" => "magnet", "value" => "magnet"),
Dict("label" => "quantum", "value" => "quantum"),
Dict("label" => "skid", "value" => "skid"),
Dict("label" => "standard", "value" => "standard")
],
value = "standard"
),
html_label("Nonstandard Go——Visibility:",title="Search on https://senseis.xmp.net/ for more details"),
dcc_radioitems(id="colorMode",
options = [
Dict("label" => "blind", "value" => "blind"),
Dict("label" => "phantom", "value" => "phantom"),
Dict("label" => "war fog", "value" => "warFog"),
Dict("label" => "one colour", "value" => "oneColour"),
Dict("label" => "standard", "value" => "standard")
],
value = "standard"
),
html_label("Fixed obstacles:",title="The obstacles are placed on the board on the vertices the GTP prefers, e.g. 2"),
dcc_input(id="fObstacle",value="0",type="number",min=0,step=1,max=9),
html_label("Placed obstacles:",title="The obstacles are placed on the board on the vertices the engine prefers, e.g. 2"),
dcc_input(id="pObstacles",value="0",type="number",min=0,step=1,max=20),
html_label("Set obstacles:",title="The obstacles are placed on the board on the vertices the player prefers, e.g. k10 q16"),
dcc_input(id="sObstacles",value="",type="text"),
rulesetDiv,
ruleCheck,
appendixDiv,
dcc_markdown("**Debug:**"),
html_div(id="rulesetBtn"),
html_div(id="ruleSmt")
end
playGame=html_div() do
html_div(
dcc_markdown(topText),
style=Dict(
"backgroundColor"=>"#111111",
"textAlign"=>"center",
"columnCount"=>"2",
"color"=>"rgba(0,255,0,1)"
)
),
html_div(
[
dcc_graph(id="board"),
html_div(
[
dcc_textarea(
id="gtpO",
#placeholder = "Enter a value...",
#value="This is a TextArea component",
style=Dict("width"=>"900px","height"=>"800px")
);
dcc_input(
id="gtpI",
placeholder="GTP commands end with a '.'",
value="",
type="text",
style=Dict("width"=>"900px","height"=>"30px")
)
],
style=Dict("float"=>"right")
)
],
style=Dict("columnCount"=>"2")
),
html_div(
bottomMarkdown,
style=(width="100%",display="inline-block",textAlign="right"#=,float="right"=#)
),
dcc_textarea(id="Info",style=Dict("width"=>"900px","height"=>"300px",#="cols"=>2=#)),
dcc_confirmdialog(id="finalDialog",message="",displayed=false)
end
#include("tab.jl")
function mode_color(colorVector,colorPlayer,modeColor)
if modeColor=="blind"
colorVector=["rgba(0,0,0,0)" for v in 1:length(colorVector)]
elseif modeColor=="phantom"
if colorPlayer=="B"
for i in 1:length(colorVector)
if colorVector[i] == "rgba(255,255,255,1)"
colorVector[i]="rgba(255,255,255,0)"
end
end
else
for j in 1:length(colorVector)
if colorVector[j] == "rgba(0,0,0,1)"
colorVector[j]="rgba(0,0,0,0)"
end
end
end
elseif modeColor=="oneColour"
for k in 1:length(colorVector)
if colorVector[k] =="rgba(255,255,255,1)"
colorVector[k]="rgba(0,0,0,1)"
end
end
else
end
return colorVector
end
#include("visibility.jl")
#using JSON3
function abc_num(color,vertex,boardSizeY) # move_syntax_converter: gtp & num
if color in [-1,1]
if color == -1
color = 'B'
else
color = 'W'
end
vertex = string(GTP_X[vertex[2]+1],boardSizeY+1-vertex[1])
else
if color in ['B','b',"B","b"]
color = -1
else
color = 1
end
i = 2
while true
if GTP_X[i] == vertex[1] || uppercase(GTP_X[i]) == vertex[1]
break
end
# println(GTP_X[i],' ',UI_X[i],' ',vertex[1])
i = i+1
end
i = i-1
vertex = [boardSizeY+1-parse(Int,vertex[2:end]),i]
end