-
Notifications
You must be signed in to change notification settings - Fork 0
/
xq_run.sh
executable file
·106 lines (93 loc) · 2.52 KB
/
xq_run.sh
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
# step1: check the start fenstr
sleep 2
result=""
while [ "$result" == "" ];
do
echo "find window"
result=`./GetWindowID Safari Xiangqi`
sleep 1
done
win_id=`echo $result | awk '{print $1}'`
win_x0=`echo $result | awk '{print $2}'`
win_y0=`echo $result | awk '{print $3}'`
screencapture -o -l$win_id screen.png
result=`main screen.png`
fenstr=`echo $result | awk '{print $1}'`
mycolor=`echo $result | awk '{print $2}'`
whonext=`echo $result | awk '{print $3}'`
if [ $mycolor == $whonext ]; then
pre_fenstr=""
else
pre_fenstr=$fenstr
fi
failcount=0
#echo "=== start move ==="
#step2: start play
while [ 1 ]
do
screencapture -o -l$win_id screen.png
result=`./main screen.png`
fenstr=`echo $result | awk '{print $1}'`
if [ "$fenstr" == "" ]; then
echo "无法识别"
sleep 0.2
failcount=$[failcount+1]
if [ $failcount -ge 4 ]; then break; fi
continue
fi
ch_x0=`echo $result | awk '{print $4}'`
ch_y0=`echo $result | awk '{print $5}'`
xstep=`echo $result | awk '{print $6}'`
ystep=`echo $result | awk '{print $7}'`
if [ "$fenstr" == "$prev_fenstr" ]; then
#echo "对方没有动作"
sleep 0.2
continue
fi
isvalid1=`./isfenvalid $fenstr`
if [ "$isvalid1" == "false" ]; then
echo "不合法的棋谱"
sleep 0.2
failcount=$[failcount+1]
if [ $failcount -ge 4 ]; then break; fi
continue;
fi
isvalid2=`./isfenvalid $prev_fenstr $fenstr`
if [ "$isvalid2" == "false" ]; then
echo "不合法的走法"
sleep 0.2
failcount=$[failcount+1]
if [ $failcount -ge 4 ]; then break; fi
continue;
fi
failcount=0
#clear
echo "-------------------------------"
./fenstr2matrix.sh $fenstr `./whichmoves $prev_fenstr $fenstr`
echo "-------------------------------"
nextmove=`node xqwizard_interface/xqcli.js -f "$fenstr $mycolor"`
#echo $nextmove
x0=`echo "$nextmove" | awk '{print $1}'`
y0=`echo "$nextmove" | awk '{print $2}'`
x1=`echo "$nextmove" | awk '{print $3}'`
y1=`echo "$nextmove" | awk '{print $4}'`
status=`echo "$nextmove" | awk '{print $5}'`
prev_fenstr=`echo "$nextmove" | awk '{print $6}'`
x0=`echo "($win_x0+$ch_x0+$x0*$xstep)*10/10"|bc`
y0=`echo "($win_y0+$ch_y0+$y0*$ystep)*10/10"|bc`
x1=`echo "($win_x0+$ch_x0+$x1*$xstep)*10/10"|bc`
y1=`echo "($win_y0+$ch_y0+$y1*$ystep)*10/10"|bc`
#echo "start move"
cliclick c:$x0,$y0
sleep 0.1
cliclick c:$x1,$y1
if [ "$status" == "1" ]; then
echo "game over"
break
fi
#clear
echo "-------------------------------"
./fenstr2matrix.sh $prev_fenstr `./whichmoves $fenstr $prev_fenstr`
echo "-------------------------------"
sleep 0.2
done