标题: 批处理象棋人人对战 [打印本页]
作者: a2002 时间: 2017-7-6 10:52 标题: 批处理象棋人人对战
本帖最后由 a2002 于 2017-7-6 10:56 编辑
唉,原创区发不了,发到这来算是批处理代码原创开源
批处理象棋人人对战,版本17.7.6,by a2002
上图:
[attach]10724[/attach]
界面比较简陋,看得懂就差不多了
想继续做人机对战,试一试行不行,行的话发出来
以下是源码,欢迎指出bug:- @echo off&setlocal enabledelayedexpansion&mode 90,33&title 批处理版象棋&color 76
- :Restart
- call :Module_StartWith
-
- :loop_1
- color 76
- title 批处理版象棋 - 请选棋
- call :Module_Echo
- set "msg_4=[信息]"
- cmos c f
- set /a t1=!errorlevel!-1001
- if !errorlevel:~-3! equ 001 goto :loop_1
- if !t1! leq 2000 goto :loop_1
- set t2=!t1:~0,-3!
- set /a Y=(t2-1)/6+1,X=(t1-t2*1000-1)/3+1
- if "!X!_!Y!" equ "2_11" goto :Undo
- if "!X!_!Y!" equ "2_12" goto :Restart
- if "!X!_!Y!" equ "2_13" exit
- if !X! gtr 10 goto :loop_1
- if !X! lss 1 goto :loop_1
- if !Y! gtr 9 goto :loop_1
- if !Y! lss 1 goto :loop_1
- call :Check_1
-
- :loop_2
- color 7e
- title 批处理版象棋 - 请走棋
- cmos c f
- set /a t1=!errorlevel!-1001
- if !errorlevel:~-3! equ 001 goto :loop_2
- if !t1! leq 2000 goto :loop_2
- set t2=!t1:~0,-3!
- set /a New_Y=(t2-1)/6+1,New_X=(t1-t2*1000-1)/3+1
- if "!New_X!_!New_Y!" equ "2_12" goto :Restart
- if "!New_X!_!New_Y!" equ "2_13" exit
- if !New_X! gtr 10 goto :loop_2
- if !New_X! lss 1 goto :loop_2
- if !New_Y! gtr 9 goto :loop_2
- if !New_Y! lss 1 goto :loop_2
- call :Check_2
- if "!P_ID_%New_X%_%New_Y%!" equ "c" msg * 红方(!E_j!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
- if "!P_ID_%New_X%_%New_Y%!" equ "j" msg * 绿方(!E_c!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
- set /a Undo_Num+=1
- set "Undo_!Undo_Num!=P_ID_!X!_!Y!=!P_ID_%X%_%Y%! P_ID_!New_X!_!New_Y!=!P_ID_%New_X%_%New_Y%!"
- set "P_ID_!New_X!_!New_Y!=!P_ID_%X%_%Y%!"&set "P_ID_!X!_!Y!=#"
- if !now! equ c (set now=j) else (set now=c)
- goto :loop_1
-
- :Module_StartWith
- set "line_0= "
- set "line_1= ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ "
- set "line_2= ┃ ┃ ┃ ┃╲ ┃ ╱┃ ┃ ┃ ┃ "
- set "line_3= ┃ ┃ ┃ ┃ ╲┃╱ ┃ ┃ ┃ ┃ "
- set "line_4= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
- set "line_5= ┃ ┃ ┃ ┃ ╱┃╲ ┃ ┃ ┃ ┃ "
- set "line_6= ┃ ┃ ┃ ┃╱ ┃ ╲┃ ┃ ┃ ┃ "
- set "line_7= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
- set "line_8= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_9= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_10= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
- set "line_11= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_12= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_13= ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┫ "
- set "line_14= ┃ ┃ "
- set "line_15= ┃ ┃ "
- set "line_16= ┣━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┫ "
- set "line_17= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_18= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_19= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
- set "line_20= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_21= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_22= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
- set "line_23= ┃ ┃ ┃ ┃╲ ┃ ╱┃ ┃ ┃ ┃ "
- set "line_24= ┃ ┃ ┃ ┃ ╲┃╱ ┃ ┃ ┃ ┃ "
- set "line_25= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
- set "line_26= ┃ ┃ ┃ ┃ ╱┃╲ ┃ ┃ ┃ ┃ "
- set "line_27= ┃ ┃ ┃ ┃╱ ┃ ╲┃ ┃ ┃ ┃ "
- set "line_28= ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ "
- set "line_29= "
- for /l %%# in (1,1,10) do set "msg_%%#= "
- set now=j&set Undo_Num=0
- set "str=卒炮将士象马车兵炮帅仕相马车"&set "var=abcdefghijklmn"
- for /l %%# in (0,1,13) do set E_!var:~%%#,1!=!str:~%%#,1!
- for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do set P_ID_%%$_%%#=#
- set P_ID_1_1=g&set P_ID_1_2=f&set P_ID_1_3=e&set P_ID_1_4=d&set P_ID_1_5=c&set P_ID_1_6=d&set P_ID_1_7=e&set P_ID_1_8=f&set P_ID_1_9=g
- set P_ID_10_1=n&set P_ID_10_2=m&set P_ID_10_3=l&set P_ID_10_4=k&set P_ID_10_5=j&set P_ID_10_6=k&set P_ID_10_7=l&set P_ID_10_8=m&set P_ID_10_9=n
- set P_ID_3_2=b&set P_ID_3_8=b&set P_ID_8_2=i&set P_ID_8_8=i
- set P_ID_4_1=a&set P_ID_4_3=a&set P_ID_4_5=a&set P_ID_4_7=a&set P_ID_4_9=a
- set P_ID_7_1=h&set P_ID_7_3=h&set P_ID_7_5=h&set P_ID_7_7=h&set P_ID_7_9=h
- set "msg_1=批处理版象棋,由a2002编写完成,第三方cmos"
- set "msg_2= ┏━┓┏━┓┏━┓ ┃悔┃┃重┃┃退┃ ┗━┛┗━┛┗━┛ "
- set "msg_4=[信息]"&set "c=h i j k l m n"&set "j=a b c d e f g"
- goto :eof
-
- :Module_Set
- for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do (
- if "!P_ID_%%$_%%#!" equ "#" (
- set /a t1=%%$*3-3,t2=t1+1,t3=t2+1,t4=%%#*3-3
- call :Command_1 "%%$" "%%#" "!t1!" "!t2!" "!t3!" "!t4!")
- for %%a in (a b c d e f g) do if "!P_ID_%%$_%%#!" equ "%%a" set "P_Top_%%$_%%#=┌─┐"&set "P_Between_%%$_%%#=│!E_%%a!│"&set "P_Bottom_%%$_%%#=└─┘"
- for %%a in (h i j k l m n) do if "!P_ID_%%$_%%#!" equ "%%a" set "P_Top_%%$_%%#=╔═╗"&set "P_Between_%%$_%%#=║!E_%%a!║"&set "P_Bottom_%%$_%%#=╚═╝")
- goto :eof
-
- :Module_Echo
- call :Module_Set
- set "msg_3=走棋方:!E_%now%!"
- cls
- echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
- for /l %%# in (1,1,10) do (
- echo ┃!P_Top_%%#_1!!P_Top_%%#_2!!P_Top_%%#_3!!P_Top_%%#_4!!P_Top_%%#_5!!P_Top_%%#_6!!P_Top_%%#_7!!P_Top_%%#_8!!P_Top_%%#_9!┃!msg_%%#:~0,15!
- echo ┃!P_Between_%%#_1!!P_Between_%%#_2!!P_Between_%%#_3!!P_Between_%%#_4!!P_Between_%%#_5!!P_Between_%%#_6!!P_Between_%%#_7!!P_Between_%%#_8!!P_Between_%%#_9!┃!msg_%%#:~15,15!
- echo ┃!P_Bottom_%%#_1!!P_Bottom_%%#_2!!P_Bottom_%%#_3!!P_Bottom_%%#_4!!P_Bottom_%%#_5!!P_Bottom_%%#_6!!P_Bottom_%%#_7!!P_Bottom_%%#_8!!P_Bottom_%%#_9!┃!msg_%%#:~30,15!)
- echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- goto :eof
-
- :Check_1
- if "!P_ID_%X%_%Y%!" equ "#" set "msg_4=棋不能为空!!!"&goto :loop_1
- for %%# in (!%now%!) do if "!P_ID_%X%_%Y%!" equ "%%#" set "msg_4=请拿自己的棋!!!"&goto :loop_1
- goto :eof
-
- :Check_2
- set t=0
- set F_c=!j!&set F_j=!c!
- for %%# in (!F_%now%!) do if "!P_ID_%New_X%_%New_Y%!" equ "%%#" set "msg_4=非法走棋!!!"&goto :loop_1
- call :CalcA
- if "!P_ID_%X%_%Y%!" equ "a" (
- if !X! leq 5 (if !Return! equ -1 goto :eof) else (
- if !Return! equ -1 goto :eof
- if !Return! equ 200 goto :eof
- if !Return! equ -200 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "h" (
- if !X! geq 6 (if !Return! equ 1 goto :eof) else (
- if !Return! equ 1 goto :eof
- if !Return! equ 200 goto :eof
- if !Return! equ -200 goto :eof))
- for %%# in (b i) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
- ) else (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 3 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 3 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 3 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 3 goto :eof))))
- if "!P_ID_%X%_%Y%!" equ "c" (if !New_X! geq 1 if !New_X! leq 3 if !New_Y! geq 4 if !New_Y! leq 6 (
- if !Return! equ 1 goto :eof
- if !Return! equ -1 goto :eof
- if !Return! equ 200 goto :eof
- if !Return! equ -200 goto :eof)
- if "!P_ID_%New_X%_%New_Y%!" equ "j" (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "j" (if !New_X! geq 8 if !New_X! leq 10 if !New_Y! geq 4 if !New_Y! leq 6 (
- if !Return! equ 1 goto :eof
- if !Return! equ -1 goto :eof
- if !Return! equ 200 goto :eof
- if !Return! equ -200 goto :eof)
- if "!P_ID_%New_X%_%New_Y%!" equ "c" (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "d" (if !New_X! geq 1 if !New_X! leq 3 if !New_Y! geq 4 if !New_Y! leq 6 (
- if !Return! equ 201 goto :eof
- if !Return! equ 199 goto :eof
- if !Return! equ -199 goto :eof
- if !Return! equ -201 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "k" (if !New_X! geq 8 if !New_X! leq 10 if !New_Y! geq 4 if !New_Y! leq 6 (
- if !Return! equ 201 goto :eof
- if !Return! equ 199 goto :eof
- if !Return! equ -199 goto :eof
- if !Return! equ -201 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "e" (if !New_X! leq 5 (
- if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
- if "!P_ID_%X%_%Y%!" equ "l" (if !New_X! geq 6 (
- if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
- for %%# in (f m) do (if "!P_ID_%X%_%Y%!" equ "%%#" (
- if !Return! equ 202 (set /a t1=X-1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -198 (set /a t1=X-1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 401 (set /a t1=X,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 399 (set /a t1=X,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -399 (set /a t1=X,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -401 (set /a t1=X,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 198 (set /a t1=X+1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -202 (set /a t1=X+1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)))
- for %%# in (g n) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
- ) else (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 2 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 2 goto :eof))))
- set "msg_4=非法走棋!!!"&goto :loop_1
-
- :CalcA
- set /a t1=X-New_X,t2=(Y-New_Y)*200
- set /a Return=t1+t2
- goto :eof
-
- :CalcB
- set CalcB_Return=0
- if "%~1" equ "1" for /l %%# in (!Y!,1,!New_Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "2" for /l %%# in (!X!,1,!New_X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "3" for /l %%# in (!New_Y!,1,!Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "4" for /l %%# in (!New_X!,1,!X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
- goto :eof
-
- :Undo
- if !Undo_Num! lss 2 set "msg_4=没有可悔的棋!!!"&goto :loop_1
- set /a t1=Undo_Num,t2=t1-1,Undo_Num-=2
- for /f "tokens=1,2 delims= " %%a in ("!Undo_%t1%!") do set "%%a"&set "%%b"
- for /f "tokens=1,2 delims= " %%a in ("!Undo_%t2%!") do set "%%a"&set "%%b"
- goto :loop_1
-
- :Command_1
- set "P_Top_%~1_%~2=!line_%~3:~%~6,3!"&set "P_Between_%~1_%~2=!line_%~4:~%~6,3!"&set "P_Bottom_%~1_%~2=!line_%~5:~%~6,3!"
- goto :eof
-
- :Command_2
- set t=&if "!P_ID_%~1_%~2!" equ "#" set t=1
- goto :eof
复制代码
下载:http://pan.baidu.com/s/1kV834yF
作者: happy886rr 时间: 2017-7-6 15:44
本帖最后由 happy886rr 于 2017-7-6 15:45 编辑
回复 1# a2002
象棋规则的实现非常赞,虽然只是人人象棋,不过稍微加几行修改,结合UCCI就能变人 机对战。
为何不用html写,批处理做这个体验都很差的。方形子感觉更像军棋,而不是象棋。
作者: a2002 时间: 2017-7-6 16:54
对于那方形子,用圆角制表符在win7下就不能对齐了
我再改进一下吧
作者: happy886rr 时间: 2017-7-6 18:16
回复 3# a2002
我记得以前有人写过一个批处理人机对战象棋,你去批处理原创区找找。不过你的规则设计的更好,我试了马绊腿,你也能提示非法走步。这点值得赞赏。
作者: a2002 时间: 2017-7-6 18:43
本帖最后由 a2002 于 2017-7-6 18:48 编辑
回复 4# happy886rr
我看了,感觉netbenton的比较精炼
但是我的这个if有些重复、啰嗦,还有for中使用了call,降低了效率
谢谢提醒,这点要改进
作者: a2002 时间: 2017-7-6 18:49
不过netbenton的我玩不了
作者: a2002 时间: 2017-7-6 20:52
我缩减了代码,体积减少了1.1K,也许更便于看清楚和修改吧。更新至17.7.6.2
以下是代码:- @echo off&setlocal enabledelayedexpansion&mode 90,33&title 批处理版象棋&color 76
- :Restart
- call :Module_StartWith
-
- :loop_1
- color 76
- title 批处理版象棋 - 请选棋
- call :Module_Echo
- set "msg_4=[信息]"
- call :Cmos loop_1 X Y
- call :Check_1
-
- :loop_2
- color 7e
- title 批处理版象棋 - 请走棋
- call :Cmos loop_2 New_X New_Y
- call :Check_2
- if "!P_ID_%New_X%_%New_Y%!" equ "c" msg * 红方(!E_j!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
- if "!P_ID_%New_X%_%New_Y%!" equ "j" msg * 绿方(!E_c!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
- set /a Undo_Num+=1
- set "Undo_!Undo_Num!=P_ID_!X!_!Y!=!P_ID_%X%_%Y%! P_ID_!New_X!_!New_Y!=!P_ID_%New_X%_%New_Y%!"
- set "P_ID_!New_X!_!New_Y!=!P_ID_%X%_%Y%!"&set "P_ID_!X!_!Y!=#"
- if !now! equ c (set now=j) else (set now=c)
- goto :loop_1
-
- :Module_StartWith
- set "line_0= "
- set "line_1= ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ "
- set "line_2= ┃ ┃ ┃ ┃╲ ┃ ╱┃ ┃ ┃ ┃ "
- set "line_3= ┃ ┃ ┃ ┃ ╲┃╱ ┃ ┃ ┃ ┃ "
- set "line_4= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
- set "line_5= ┃ ┃ ┃ ┃ ╱┃╲ ┃ ┃ ┃ ┃ "
- set "line_6= ┃ ┃ ┃ ┃╱ ┃ ╲┃ ┃ ┃ ┃ "
- set "line_7= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
- set "line_8= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_9= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_10= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
- set "line_11= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_12= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_13= ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┫ "
- set "line_14= ┃ ┃ "
- set "line_15= ┃ ┃ "
- set "line_16= ┣━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┫ "
- set "line_17= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_18= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_19= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
- set "line_20= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_21= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_22= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
- set "line_23= ┃ ┃ ┃ ┃╲ ┃ ╱┃ ┃ ┃ ┃ "
- set "line_24= ┃ ┃ ┃ ┃ ╲┃╱ ┃ ┃ ┃ ┃ "
- set "line_25= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
- set "line_26= ┃ ┃ ┃ ┃ ╱┃╲ ┃ ┃ ┃ ┃ "
- set "line_27= ┃ ┃ ┃ ┃╱ ┃ ╲┃ ┃ ┃ ┃ "
- set "line_28= ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ "
- set "line_29= "
- for /l %%# in (1,1,10) do set "msg_%%#= "
- set now=j&set Undo_Num=0
- set "str=卒炮将士象马车兵炮帅仕相马车"&set "var=abcdefghijklmn"
- for /l %%# in (0,1,13) do set E_!var:~%%#,1!=!str:~%%#,1!
- for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do set P_ID_%%$_%%#=#
- for %%# in (1_1@g 1_2@f 1_3@e 1_4@d 1_5@c 1_6@d 1_7@e 1_8@f 1_9@g 10_1@n 10_2@m 10_3@l 10_4@k 10_5@j 10_6@k 10_7@l 10_8@m 10_9@n 3_2@b 3_8@b 8_2@i 8_8@i 4_1@a 4_3@a 4_5@a 4_7@a 4_9@a 7_1@h 7_3@h 7_5@h 7_7@h 7_9@h) do (set "t=%%#"&set "P_ID_!t:@==!")
- set "msg_1=批处理版象棋,由a2002编写完成,版本17.7.6.2,第三方cmos"
- set "msg_2= ┏━┓┏━┓┏━┓ ┃悔┃┃重┃┃退┃ ┗━┛┗━┛┗━┛ "
- set "msg_4=[信息]"&set "c=h i j k l m n"&set "j=a b c d e f g"
- goto :eof
-
- :Module_Set
- for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do (
- if "!P_ID_%%$_%%#!" equ "#" (
- set /a t1=%%$*3-3,t2=t1+1,t3=t2+1,t4=%%#*3-3
- call :Command_1 "%%$" "%%#" "!t1!" "!t2!" "!t3!" "!t4!")
- for %%a in (a b c d e f g) do if "!P_ID_%%$_%%#!" equ "%%a" set "P_Top_%%$_%%#=┌─┐"&set "P_Between_%%$_%%#=│!E_%%a!│"&set "P_Bottom_%%$_%%#=└─┘"
- for %%a in (h i j k l m n) do if "!P_ID_%%$_%%#!" equ "%%a" set "P_Top_%%$_%%#=╔═╗"&set "P_Between_%%$_%%#=║!E_%%a!║"&set "P_Bottom_%%$_%%#=╚═╝")
- goto :eof
-
- :Module_Echo
- call :Module_Set
- set "msg_3=走棋方:!E_%now%!"
- cls
- echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
- for /l %%# in (1,1,10) do (
- echo ┃!P_Top_%%#_1!!P_Top_%%#_2!!P_Top_%%#_3!!P_Top_%%#_4!!P_Top_%%#_5!!P_Top_%%#_6!!P_Top_%%#_7!!P_Top_%%#_8!!P_Top_%%#_9!┃!msg_%%#:~0,15!
- echo ┃!P_Between_%%#_1!!P_Between_%%#_2!!P_Between_%%#_3!!P_Between_%%#_4!!P_Between_%%#_5!!P_Between_%%#_6!!P_Between_%%#_7!!P_Between_%%#_8!!P_Between_%%#_9!┃!msg_%%#:~15,15!
- echo ┃!P_Bottom_%%#_1!!P_Bottom_%%#_2!!P_Bottom_%%#_3!!P_Bottom_%%#_4!!P_Bottom_%%#_5!!P_Bottom_%%#_6!!P_Bottom_%%#_7!!P_Bottom_%%#_8!!P_Bottom_%%#_9!┃!msg_%%#:~30,15!)
- echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- goto :eof
-
- :Check_1
- if "!P_ID_%X%_%Y%!" equ "#" set "msg_4=棋不能为空!!!"&goto :loop_1
- for %%# in (!%now%!) do if "!P_ID_%X%_%Y%!" equ "%%#" set "msg_4=请拿自己的棋!!!"&goto :loop_1
- goto :eof
-
- :Check_2
- set t=0
- set F_c=!j!&set F_j=!c!
- for %%# in (!F_%now%!) do if "!P_ID_%New_X%_%New_Y%!" equ "%%#" set "msg_4=非法走棋!!!"&goto :loop_1
- call :CalcA
- if "!P_ID_%X%_%Y%!" equ "a" (if !X! leq 5 (if !Return! equ -1 goto :eof) else (for %%# in (-1 200 -200) do if !Return! equ %%# goto :eof))
- if "!P_ID_%X%_%Y%!" equ "h" (if !X! geq 6 (if !Return! equ 1 goto :eof) else (for %%# in (1 200 -200) do if !Return! equ %%# goto :eof))
- for %%# in (b i) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
- ) else (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 3 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 3 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 3 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 3 goto :eof))))
- if "!P_ID_%X%_%Y%!" equ "c" (if !New_X! geq 1 if !New_X! leq 3 if !New_Y! geq 4 if !New_Y! leq 6 (for %%# in (1 -1 200 -200) do if !Return! equ %%# goto :eof)
- if "!P_ID_%New_X%_%New_Y%!" equ "j" (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "j" (if !New_X! geq 8 if !New_X! leq 10 if !New_Y! geq 4 if !New_Y! leq 6 (for %%# in (1 -1 200 -200) do if !Return! equ %%# goto :eof)
- if "!P_ID_%New_X%_%New_Y%!" equ "c" (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "d" (if !New_X! geq 1 if !New_X! leq 3 if !New_Y! geq 4 if !New_Y! leq 6 (
- for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
- if "!P_ID_%X%_%Y%!" equ "k" (if !New_X! geq 8 if !New_X! leq 10 if !New_Y! geq 4 if !New_Y! leq 6 (
- for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
- if "!P_ID_%X%_%Y%!" equ "e" (if !New_X! leq 5 (
- if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
- if "!P_ID_%X%_%Y%!" equ "l" (if !New_X! geq 6 (
- if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
- for %%# in (f m) do (if "!P_ID_%X%_%Y%!" equ "%%#" (
- for %%$ in (202 -198) do if !Return! equ %%$ (set /a t1=X-1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)
- for %%$ in (401 399) do if !Return! equ %%$ (set /a t1=X,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- for %%$ in (-401 -399) do if !Return! equ %%$ (set /a t1=X,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
- for %%$ in (198 -202) do if !Return! equ %%$ (set /a t1=X+1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)))
- for %%# in (g n) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
- ) else (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 2 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 2 goto :eof))))
- set "msg_4=非法走棋!!!"&goto :loop_1
-
- :CalcA
- set /a t1=X-New_X,t2=(Y-New_Y)*200
- set /a Return=t1+t2
- goto :eof
-
- :CalcB
- set CalcB_Return=0
- if "%~1" equ "1" for /l %%# in (!Y!,1,!New_Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "2" for /l %%# in (!X!,1,!New_X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "3" for /l %%# in (!New_Y!,1,!Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "4" for /l %%# in (!New_X!,1,!X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
- goto :eof
-
- :Cmos
- cmos c f
- set /a t1=!errorlevel!-1001
- if !errorlevel:~-3! equ 001 goto :%~1
- if !t1! leq 2000 goto :%~1
- set t2=!t1:~0,-3!
- set /a %~3=(t2-1)/6+1,%~2=(t1-t2*1000-1)/3+1
- if "!%~2!_!%~3!" equ "2_11" goto :Undo
- if "!%~2!_!%~3!" equ "2_12" goto :Restart
- if "!%~2!_!%~3!" equ "2_13" exit
- if !%~2! gtr 10 goto :%~1
- if !%~2! lss 1 goto :%~1
- if !%~3! gtr 9 goto :%~1
- if !%~3! lss 1 goto :%~1
- goto :eof
-
- :Undo
- if !Undo_Num! lss 2 set "msg_4=没有可悔的棋!!!"&goto :loop_1
- set /a t1=Undo_Num,t2=t1-1,Undo_Num-=2
- for /f "tokens=1,2 delims= " %%a in ("!Undo_%t1%!") do set "%%a"&set "%%b"
- for /f "tokens=1,2 delims= " %%a in ("!Undo_%t2%!") do set "%%a"&set "%%b"
- goto :loop_1
-
- :Command_1
- set "P_Top_%~1_%~2=!line_%~3:~%~6,3!"&set "P_Between_%~1_%~2=!line_%~4:~%~6,3!"&set "P_Bottom_%~1_%~2=!line_%~5:~%~6,3!"
- goto :eof
-
- :Command_2
- set t=&if "!P_ID_%~1_%~2!" equ "#" set t=1
- goto :eof
复制代码
作者: a2002 时间: 2017-7-6 20:55
再琢磨一下看要不要用引擎,实现人机
如果能不用就不用
作者: happy886rr 时间: 2017-7-6 22:46
本帖最后由 happy886rr 于 2017-7-6 22:57 编辑
回复 8# a2002
厉害,看得出来,你用for取代了很多if,优化了结构。
至于象棋引擎早就有了,它们叫UCCI,只有UCCI才能实现人机对战。单纯批处理根本无法具备象棋智能。
因为象棋还有开局棋谱,很多特殊走法,不是5000行能解决智能算法的。这里只能借助现成的UCCI象棋引擎库,用fen格式去传递当前棋局- rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1
复制代码
有点类似前端的数据交互吧。
毕竟,你要发布的作品应该具备极强的智能,UCCI携带开局棋谱后几乎是必赢的,同样对于五子棋,也有很多引擎,在无禁手的情况下,先下者必赢。毕竟计算机可以准确无误的计算到很多步之后的权值,然后选择最佳的落子方案。
当然借助google的深度学习库tensorflow,可以通过训练,让机器具备人类棋手的经验。不过该库只能运行在64位python上。
还有阿里的Me2都是机器模拟人类思维的极佳方案,但已经涉及到量子计算、脑部扫描等前沿技术。
作者: 523066680 时间: 2017-7-7 00:14
本帖最后由 523066680 于 2017-7-7 00:17 编辑
该缩进的缩进,该模块化的模块化。没必要全部代码在一个文件。
Finally, 越早换语言,人生越美好。
作者: a2002 时间: 2017-7-7 07:26
本帖最后由 a2002 于 2017-7-7 07:54 编辑
回复 9# happy886rr
那我试一试吧
提了下速(基本不耗时间了),for中也没call了
代码:- @echo off&setlocal enabledelayedexpansion&mode 90,33&title 批处理版象棋&color 76
- :Restart
- call :Module_StartWith
-
- :loop_1
- color 76
- title 批处理版象棋 - 请选棋
- call :Module_Echo
- set "msg_4=[信息]"
- call :Cmos loop_1 X Y
- call :Check_1
-
- :loop_2
- color 7e
- title 批处理版象棋 - 请走棋
- call :Cmos loop_2 New_X New_Y
- call :Check_2
- if "!P_ID_%New_X%_%New_Y%!" equ "c" msg * 红方(!E_j!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
- if "!P_ID_%New_X%_%New_Y%!" equ "j" msg * 绿方(!E_c!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
- set /a Undo_Num+=1
- set "Undo_!Undo_Num!=P_ID_!X!_!Y!=!P_ID_%X%_%Y%! P_ID_!New_X!_!New_Y!=!P_ID_%New_X%_%New_Y%!"
- set "P_ID_!New_X!_!New_Y!=!P_ID_%X%_%Y%!"&set "P_ID_!X!_!Y!=#"
- if !now! equ c (set now=j) else (set now=c)
- goto :loop_1
-
- :Module_StartWith
- set "line_0= "
- set "line_1= ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ "
- set "line_2= ┃ ┃ ┃ ┃╲ ┃ ╱┃ ┃ ┃ ┃ "
- set "line_3= ┃ ┃ ┃ ┃ ╲┃╱ ┃ ┃ ┃ ┃ "
- set "line_4= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
- set "line_5= ┃ ┃ ┃ ┃ ╱┃╲ ┃ ┃ ┃ ┃ "
- set "line_6= ┃ ┃ ┃ ┃╱ ┃ ╲┃ ┃ ┃ ┃ "
- set "line_7= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
- set "line_8= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_9= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_10= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
- set "line_11= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_12= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_13= ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┫ "
- set "line_14= ┃ ┃ "
- set "line_15= ┃ ┃ "
- set "line_16= ┣━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┫ "
- set "line_17= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_18= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_19= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
- set "line_20= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_21= ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ "
- set "line_22= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
- set "line_23= ┃ ┃ ┃ ┃╲ ┃ ╱┃ ┃ ┃ ┃ "
- set "line_24= ┃ ┃ ┃ ┃ ╲┃╱ ┃ ┃ ┃ ┃ "
- set "line_25= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
- set "line_26= ┃ ┃ ┃ ┃ ╱┃╲ ┃ ┃ ┃ ┃ "
- set "line_27= ┃ ┃ ┃ ┃╱ ┃ ╲┃ ┃ ┃ ┃ "
- set "line_28= ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ "
- set "line_29= "
- for /l %%# in (1,1,10) do set "msg_%%#= "
- set now=j&set Undo_Num=0
- set "str=卒炮将士象马车兵炮帅仕相马车"&set "var=abcdefghijklmn"
- for /l %%# in (0,1,13) do set E_!var:~%%#,1!=!str:~%%#,1!
- for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do set P_ID_%%$_%%#=#
- for %%# in (1_1@g 1_2@f 1_3@e 1_4@d 1_5@c 1_6@d 1_7@e 1_8@f 1_9@g 10_1@n 10_2@m 10_3@l 10_4@k 10_5@j 10_6@k 10_7@l 10_8@m 10_9@n 3_2@b 3_8@b 8_2@i 8_8@i 4_1@a 4_3@a 4_5@a 4_7@a 4_9@a 7_1@h 7_3@h 7_5@h 7_7@h 7_9@h) do (set "t=%%#"&set "P_ID_!t:@==!")
- set "msg_1=批处理版象棋,由a2002编写完成,第三方cmos"
- set "msg_2= ┏━┓┏━┓┏━┓ ┃悔┃┃重┃┃退┃ ┗━┛┗━┛┗━┛ "
- set "msg_4=[信息]"&set "c=h i j k l m n"&set "j=a b c d e f g"
- goto :eof
-
- :Module_Set
- for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do (
- if "!P_ID_%%$_%%#!" equ "#" (
- set /a t1=%%$*3-3,t2=t1+1,t3=t2+1,t4=%%#*3-3
- for /f "tokens=1-6 delims= " %%a in ("%%$ %%# !t1! !t2! !t3! !t4!") do set "P_Top_%%a_%%b=!line_%%c:~%%f,3!"&set "P_Between_%%a_%%b=!line_%%d:~%%f,3!"&set "P_Bottom_%%a_%%b=!line_%%e:~%%f,3!")
- for %%a in (a b c d e f g) do if "!P_ID_%%$_%%#!" equ "%%a" set "P_Top_%%$_%%#=┌─┐"&set "P_Between_%%$_%%#=│!E_%%a!│"&set "P_Bottom_%%$_%%#=└─┘"
- for %%a in (h i j k l m n) do if "!P_ID_%%$_%%#!" equ "%%a" set "P_Top_%%$_%%#=╔═╗"&set "P_Between_%%$_%%#=║!E_%%a!║"&set "P_Bottom_%%$_%%#=╚═╝")
- goto :eof
-
- :Module_Echo
- call :Module_Set
- set "msg_3=走棋方:!E_%now%!"
- cls
- echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
- for /l %%# in (1,1,10) do (
- echo ┃!P_Top_%%#_1!!P_Top_%%#_2!!P_Top_%%#_3!!P_Top_%%#_4!!P_Top_%%#_5!!P_Top_%%#_6!!P_Top_%%#_7!!P_Top_%%#_8!!P_Top_%%#_9!┃!msg_%%#:~0,15!
- echo ┃!P_Between_%%#_1!!P_Between_%%#_2!!P_Between_%%#_3!!P_Between_%%#_4!!P_Between_%%#_5!!P_Between_%%#_6!!P_Between_%%#_7!!P_Between_%%#_8!!P_Between_%%#_9!┃!msg_%%#:~15,15!
- echo ┃!P_Bottom_%%#_1!!P_Bottom_%%#_2!!P_Bottom_%%#_3!!P_Bottom_%%#_4!!P_Bottom_%%#_5!!P_Bottom_%%#_6!!P_Bottom_%%#_7!!P_Bottom_%%#_8!!P_Bottom_%%#_9!┃!msg_%%#:~30,15!)
- echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- goto :eof
-
- :Check_1
- if "!P_ID_%X%_%Y%!" equ "#" set "msg_4=棋不能为空!!!"&goto :loop_1
- for %%# in (!%now%!) do if "!P_ID_%X%_%Y%!" equ "%%#" set "msg_4=请拿自己的棋!!!"&goto :loop_1
- goto :eof
-
- :Check_2
- set t=0
- set F_c=!j!&set F_j=!c!
- for %%# in (!F_%now%!) do if "!P_ID_%New_X%_%New_Y%!" equ "%%#" set "msg_4=非法走棋!!!"&goto :loop_1
- call :CalcA
- if "!P_ID_%X%_%Y%!" equ "a" (if !X! leq 5 (if !Return! equ -1 goto :eof) else (for %%# in (-1 200 -200) do if !Return! equ %%# goto :eof))
- if "!P_ID_%X%_%Y%!" equ "h" (if !X! geq 6 (if !Return! equ 1 goto :eof) else (for %%# in (1 200 -200) do if !Return! equ %%# goto :eof))
- for %%# in (b i) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
- ) else (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 3 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 3 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 3 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 3 goto :eof))))
- if "!P_ID_%X%_%Y%!" equ "c" (if !New_X! geq 1 if !New_X! leq 3 if !New_Y! geq 4 if !New_Y! leq 6 (for %%# in (1 -1 200 -200) do if !Return! equ %%# goto :eof)
- if "!P_ID_%New_X%_%New_Y%!" equ "j" (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "j" (if !New_X! geq 8 if !New_X! leq 10 if !New_Y! geq 4 if !New_Y! leq 6 (for %%# in (1 -1 200 -200) do if !Return! equ %%# goto :eof)
- if "!P_ID_%New_X%_%New_Y%!" equ "c" (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof))
- if "!P_ID_%X%_%Y%!" equ "d" (if !New_X! geq 1 if !New_X! leq 3 if !New_Y! geq 4 if !New_Y! leq 6 (
- for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
- if "!P_ID_%X%_%Y%!" equ "k" (if !New_X! geq 8 if !New_X! leq 10 if !New_Y! geq 4 if !New_Y! leq 6 (
- for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
- if "!P_ID_%X%_%Y%!" equ "e" (if !New_X! leq 5 (
- if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)))
- if "!P_ID_%X%_%Y%!" equ "l" (if !New_X! geq 6 (
- if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)))
- for %%# in (f m) do (if "!P_ID_%X%_%Y%!" equ "%%#" (
- for %%$ in (202 -198) do if !Return! equ %%$ (set /a t1=X-1,t2=Y&call :Command_1 !t1! !t2!&if defined t goto :eof)
- for %%$ in (401 399) do if !Return! equ %%$ (set /a t1=X,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- for %%$ in (-401 -399) do if !Return! equ %%$ (set /a t1=X,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)
- for %%$ in (198 -202) do if !Return! equ %%$ (set /a t1=X+1,t2=Y&call :Command_1 !t1! !t2!&if defined t goto :eof)))
- for %%# in (g n) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
- ) else (
- if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof)
- if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 2 goto :eof)
- if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 2 goto :eof))))
- set "msg_4=非法走棋!!!"&goto :loop_1
-
- :CalcA
- set /a t1=X-New_X,t2=(Y-New_Y)*200
- set /a Return=t1+t2
- goto :eof
-
- :CalcB
- set CalcB_Return=0
- if "%~1" equ "1" for /l %%# in (!Y!,1,!New_Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "2" for /l %%# in (!X!,1,!New_X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "3" for /l %%# in (!New_Y!,1,!Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
- if "%~1" equ "4" for /l %%# in (!New_X!,1,!X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
- goto :eof
-
- :Cmos
- cmos c f
- set /a t1=!errorlevel!-1001
- if !errorlevel:~-3! equ 001 goto :%~1
- if !t1! leq 2000 goto :%~1
- set t2=!t1:~0,-3!
- set /a %~3=(t2-1)/6+1,%~2=(t1-t2*1000-1)/3+1
- if "!%~2!_!%~3!" equ "2_11" goto :Undo
- if "!%~2!_!%~3!" equ "2_12" goto :Restart
- if "!%~2!_!%~3!" equ "2_13" exit
- if !%~2! gtr 10 goto :%~1
- if !%~2! lss 1 goto :%~1
- if !%~3! gtr 9 goto :%~1
- if !%~3! lss 1 goto :%~1
- goto :eof
-
- :Undo
- if !Undo_Num! lss 2 set "msg_4=没有可悔的棋!!!"&goto :loop_1
- set /a t1=Undo_Num,t2=t1-1,Undo_Num-=2
- for /f "tokens=1,2 delims= " %%a in ("!Undo_%t1%!") do set "%%a"&set "%%b"
- for /f "tokens=1,2 delims= " %%a in ("!Undo_%t2%!") do set "%%a"&set "%%b"
- goto :loop_1
-
- :Command_1
- set t=&if "!P_ID_%~1_%~2!" equ "#" set t=1
- goto :eof
复制代码
作者: a2002 时间: 2017-7-7 07:49
本帖最后由 a2002 于 2017-7-7 07:50 编辑
至于引擎
确实,如果我用分值的算法,开局就很难说了
我原来的想法:
分值:帅100,车20,炮10,马10,兵(未过河)2,兵5,士相6
不过开局都差不多,看来只能引擎了
作者: happy886rr 时间: 2017-7-7 09:33
回复 12# a2002
不错,挺效率啊。UCCI引擎就用那个netbenton象棋里的吧,那个直接就能供批处理调用。
作者: a2002 时间: 2017-7-7 12:10
回复 10# 523066680
虽然批处理效率低,但制作方便、没有固定格式啊,我会继续学的
作者: a2002 时间: 2017-7-7 12:12
还有我想请教一下这个“setlocal enableextensions”怎么用的
作者: 523066680 时间: 2017-7-7 12:36
本帖最后由 523066680 于 2017-7-7 12:45 编辑
回复 15# a2002
it's okay, I am not gonna to stop you learning BatchScript.
help setlocal (忘得差不多了,应该是类似 push 和 pop)
同时寻找 批处理之家经典教学,
CN-DOS_Batch_2008A.chm,
CN-DOS批处理精华贴(2007-A)(IE6).CHM,
批处理教材.rar,
我爱批处理-专项教程.chm
批处理标准教程.pdf
参考/实践
哦,其中一些资料我居然存了网盘
http://523066680.ys168.com/
教程->批处理
作者: a2002 时间: 2017-7-7 15:36
回复 13# happy886rr
引擎不会调用啊,晕
作者: a2002 时间: 2017-7-7 16:41
哦,我知道了
作者: a2002 时间: 2017-7-8 07:14
这引擎IQ貌似有点低
作者: happy886rr 时间: 2017-7-8 07:32
回复 19# a2002
这个到无所谓,你先做个人机对战的出来,引擎在UCCI的官网上有几十种,你换版本就行,各种智能度的都有。
作者: happy886rr 时间: 2017-7-8 07:33
它有个深度思考指令,你把思考深度加大,智能度就上去了,参见象棋巫师的官网用法。
作者: a2002 时间: 2017-7-8 07:34
做出来了,http://www.bathome.net/thread-44678-1-1.html
作者: happy886rr 时间: 2017-7-8 07:43
回复 22# a2002
UCCI象棋引擎列表,有很多,你随便换引擎,把棋谱也带上,有的引擎几乎是盘盘必胜。
http://www.xqbase.com/league/enginelist.htm
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |