Board logo

标题: 批处理象棋人人对战 [打印本页]

作者: a2002    时间: 2017-7-6 10:52     标题: 批处理象棋人人对战

本帖最后由 a2002 于 2017-7-6 10:56 编辑

唉,原创区发不了,发到这来算是批处理代码原创开源

批处理象棋人人对战,版本17.7.6,by a2002

上图:

[attach]10724[/attach]

界面比较简陋,看得懂就差不多了

想继续做人机对战,试一试行不行,行的话发出来

以下是源码,欢迎指出bug:
  1. @echo off&setlocal enabledelayedexpansion&mode 90,33&title 批处理版象棋&color 76
  2. :Restart
  3. call :Module_StartWith
  4. :loop_1
  5. color 76
  6. title 批处理版象棋 - 请选棋
  7. call :Module_Echo
  8. set "msg_4=[信息]"
  9. cmos c f
  10. set /a t1=!errorlevel!-1001
  11. if !errorlevel:~-3! equ 001 goto :loop_1
  12. if !t1! leq 2000 goto :loop_1
  13. set t2=!t1:~0,-3!
  14. set /a Y=(t2-1)/6+1,X=(t1-t2*1000-1)/3+1
  15. if "!X!_!Y!" equ "2_11" goto :Undo
  16. if "!X!_!Y!" equ "2_12" goto :Restart
  17. if "!X!_!Y!" equ "2_13" exit
  18. if !X! gtr 10 goto :loop_1
  19. if !X! lss 1 goto :loop_1
  20. if !Y! gtr 9 goto :loop_1
  21. if !Y! lss 1 goto :loop_1
  22. call :Check_1
  23. :loop_2
  24. color 7e
  25. title 批处理版象棋 - 请走棋
  26. cmos c f
  27. set /a t1=!errorlevel!-1001
  28. if !errorlevel:~-3! equ 001 goto :loop_2
  29. if !t1! leq 2000 goto :loop_2
  30. set t2=!t1:~0,-3!
  31. set /a New_Y=(t2-1)/6+1,New_X=(t1-t2*1000-1)/3+1
  32. if "!New_X!_!New_Y!" equ "2_12" goto :Restart
  33. if "!New_X!_!New_Y!" equ "2_13" exit
  34. if !New_X! gtr 10 goto :loop_2
  35. if !New_X! lss 1 goto :loop_2
  36. if !New_Y! gtr 9 goto :loop_2
  37. if !New_Y! lss 1 goto :loop_2
  38. call :Check_2
  39. if "!P_ID_%New_X%_%New_Y%!" equ "c" msg * 红方(!E_j!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
  40. if "!P_ID_%New_X%_%New_Y%!" equ "j" msg * 绿方(!E_c!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
  41. set /a Undo_Num+=1
  42. set "Undo_!Undo_Num!=P_ID_!X!_!Y!=!P_ID_%X%_%Y%! P_ID_!New_X!_!New_Y!=!P_ID_%New_X%_%New_Y%!"
  43. set "P_ID_!New_X!_!New_Y!=!P_ID_%X%_%Y%!"&set "P_ID_!X!_!Y!=#"
  44. if !now! equ c (set now=j) else (set now=c)
  45. goto :loop_1
  46. :Module_StartWith
  47. set  "line_0=                           "
  48. set  "line_1= ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ "
  49. set  "line_2= ┃  ┃  ┃  ┃╲ ┃ ╱┃  ┃  ┃  ┃ "
  50. set  "line_3= ┃  ┃  ┃  ┃ ╲┃╱ ┃  ┃  ┃  ┃ "
  51. set  "line_4= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
  52. set  "line_5= ┃  ┃  ┃  ┃ ╱┃╲ ┃  ┃  ┃  ┃ "
  53. set  "line_6= ┃  ┃  ┃  ┃╱ ┃ ╲┃  ┃  ┃  ┃ "
  54. set  "line_7= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
  55. set  "line_8= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  56. set  "line_9= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  57. set "line_10= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
  58. set "line_11= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  59. set "line_12= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  60. set "line_13= ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┫ "
  61. set "line_14= ┃                       ┃ "
  62. set "line_15= ┃                       ┃ "
  63. set "line_16= ┣━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┫ "
  64. set "line_17= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  65. set "line_18= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  66. set "line_19= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
  67. set "line_20= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  68. set "line_21= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  69. set "line_22= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
  70. set "line_23= ┃  ┃  ┃  ┃╲ ┃ ╱┃  ┃  ┃  ┃ "
  71. set "line_24= ┃  ┃  ┃  ┃ ╲┃╱ ┃  ┃  ┃  ┃ "
  72. set "line_25= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
  73. set "line_26= ┃  ┃  ┃  ┃ ╱┃╲ ┃  ┃  ┃  ┃ "
  74. set "line_27= ┃  ┃  ┃  ┃╱ ┃ ╲┃  ┃  ┃  ┃ "
  75. set "line_28= ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ "
  76. set "line_29=                           "
  77. for /l %%# in (1,1,10) do set "msg_%%#= "
  78. set now=j&set Undo_Num=0
  79. set "str=卒炮将士象马车兵炮帅仕相马车"&set "var=abcdefghijklmn"
  80. for /l %%# in (0,1,13) do set E_!var:~%%#,1!=!str:~%%#,1!
  81. for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do set P_ID_%%$_%%#=#
  82. 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
  83. 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
  84. set P_ID_3_2=b&set P_ID_3_8=b&set P_ID_8_2=i&set P_ID_8_8=i
  85. 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
  86. 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
  87. set "msg_1=批处理版象棋,由a2002编写完成,第三方cmos"
  88. set "msg_2=  ┏━┓┏━┓┏━┓      ┃悔┃┃重┃┃退┃      ┗━┛┗━┛┗━┛    "
  89. set "msg_4=[信息]"&set "c=h i j k l m n"&set "j=a b c d e f g"
  90. goto :eof
  91. :Module_Set
  92. for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do (
  93. if "!P_ID_%%$_%%#!" equ "#" (
  94. set /a t1=%%$*3-3,t2=t1+1,t3=t2+1,t4=%%#*3-3
  95. call :Command_1 "%%$" "%%#" "!t1!" "!t2!" "!t3!" "!t4!")
  96. 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_%%$_%%#=└─┘"
  97. 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_%%$_%%#=╚═╝")
  98. goto :eof
  99. :Module_Echo
  100. call :Module_Set
  101. set "msg_3=走棋方:!E_%now%!"
  102. cls
  103. echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  104. for /l %%# in (1,1,10) do (
  105. 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!
  106. 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!
  107. 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!)
  108. echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  109. goto :eof
  110. :Check_1
  111. if "!P_ID_%X%_%Y%!" equ "#" set "msg_4=棋不能为空!!!"&goto :loop_1
  112. for %%# in (!%now%!) do if "!P_ID_%X%_%Y%!" equ "%%#" set "msg_4=请拿自己的棋!!!"&goto :loop_1
  113. goto :eof
  114. :Check_2
  115. set t=0
  116. set F_c=!j!&set F_j=!c!
  117. for %%# in (!F_%now%!) do if "!P_ID_%New_X%_%New_Y%!" equ "%%#" set "msg_4=非法走棋!!!"&goto :loop_1
  118. call :CalcA
  119. if "!P_ID_%X%_%Y%!" equ "a" (
  120. if !X! leq 5 (if !Return! equ -1 goto :eof) else (
  121. if !Return! equ -1 goto :eof
  122. if !Return! equ 200 goto :eof
  123. if !Return! equ -200 goto :eof))
  124. if "!P_ID_%X%_%Y%!" equ "h" (
  125. if !X! geq 6 (if !Return! equ 1 goto :eof) else (
  126. if !Return! equ 1 goto :eof
  127. if !Return! equ 200 goto :eof
  128. if !Return! equ -200 goto :eof))
  129. for %%# in (b i) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
  130. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
  131. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
  132. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
  133. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
  134. ) else (
  135. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 3 goto :eof)
  136. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 3 goto :eof)
  137. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 3 goto :eof)
  138. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 3 goto :eof))))
  139. 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 (
  140. if !Return! equ 1 goto :eof
  141. if !Return! equ -1 goto :eof
  142. if !Return! equ 200 goto :eof
  143. if !Return! equ -200 goto :eof)
  144. if "!P_ID_%New_X%_%New_Y%!" equ "j" (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof))
  145. 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 (
  146. if !Return! equ 1 goto :eof
  147. if !Return! equ -1 goto :eof
  148. if !Return! equ 200 goto :eof
  149. if !Return! equ -200 goto :eof)
  150. if "!P_ID_%New_X%_%New_Y%!" equ "c" (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof))
  151. 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 (
  152. if !Return! equ 201 goto :eof
  153. if !Return! equ 199 goto :eof
  154. if !Return! equ -199 goto :eof
  155. if !Return! equ -201 goto :eof))
  156. 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 (
  157. if !Return! equ 201 goto :eof
  158. if !Return! equ 199 goto :eof
  159. if !Return! equ -199 goto :eof
  160. if !Return! equ -201 goto :eof))
  161. if "!P_ID_%X%_%Y%!" equ "e" (if !New_X! leq 5 (
  162. if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  163. if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  164. if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  165. if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
  166. if "!P_ID_%X%_%Y%!" equ "l" (if !New_X! geq 6 (
  167. if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  168. if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  169. if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  170. if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
  171. for %%# in (f m) do (if "!P_ID_%X%_%Y%!" equ "%%#" (
  172. if !Return! equ 202 (set /a t1=X-1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)
  173. if !Return! equ -198 (set /a t1=X-1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)
  174. if !Return! equ 401 (set /a t1=X,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  175. if !Return! equ 399 (set /a t1=X,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  176. if !Return! equ -399 (set /a t1=X,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  177. if !Return! equ -401 (set /a t1=X,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  178. if !Return! equ 198 (set /a t1=X+1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)
  179. if !Return! equ -202 (set /a t1=X+1,t2=Y&call :Command_2 !t1! !t2!&if defined t goto :eof)))
  180. for %%# in (g n) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
  181. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
  182. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
  183. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
  184. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
  185. ) else (
  186. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof)
  187. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof)
  188. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 2 goto :eof)
  189. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 2 goto :eof))))
  190. set "msg_4=非法走棋!!!"&goto :loop_1
  191. :CalcA
  192. set /a t1=X-New_X,t2=(Y-New_Y)*200
  193. set /a Return=t1+t2
  194. goto :eof
  195. :CalcB
  196. set CalcB_Return=0
  197. if "%~1" equ "1" for /l %%# in (!Y!,1,!New_Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
  198. if "%~1" equ "2" for /l %%# in (!X!,1,!New_X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
  199. if "%~1" equ "3" for /l %%# in (!New_Y!,1,!Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
  200. if "%~1" equ "4" for /l %%# in (!New_X!,1,!X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
  201. goto :eof
  202. :Undo
  203. if !Undo_Num! lss 2 set "msg_4=没有可悔的棋!!!"&goto :loop_1
  204. set /a t1=Undo_Num,t2=t1-1,Undo_Num-=2
  205. for /f "tokens=1,2 delims= " %%a in ("!Undo_%t1%!") do set "%%a"&set "%%b"
  206. for /f "tokens=1,2 delims= " %%a in ("!Undo_%t2%!") do set "%%a"&set "%%b"
  207. goto :loop_1
  208. :Command_1
  209. 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!"
  210. goto :eof
  211. :Command_2
  212. set t=&if "!P_ID_%~1_%~2!" equ "#" set t=1
  213. 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

以下是代码:
  1. @echo off&setlocal enabledelayedexpansion&mode 90,33&title 批处理版象棋&color 76
  2. :Restart
  3. call :Module_StartWith
  4. :loop_1
  5. color 76
  6. title 批处理版象棋 - 请选棋
  7. call :Module_Echo
  8. set "msg_4=[信息]"
  9. call :Cmos loop_1 X Y
  10. call :Check_1
  11. :loop_2
  12. color 7e
  13. title 批处理版象棋 - 请走棋
  14. call :Cmos loop_2 New_X New_Y
  15. call :Check_2
  16. if "!P_ID_%New_X%_%New_Y%!" equ "c" msg * 红方(!E_j!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
  17. if "!P_ID_%New_X%_%New_Y%!" equ "j" msg * 绿方(!E_c!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
  18. set /a Undo_Num+=1
  19. set "Undo_!Undo_Num!=P_ID_!X!_!Y!=!P_ID_%X%_%Y%! P_ID_!New_X!_!New_Y!=!P_ID_%New_X%_%New_Y%!"
  20. set "P_ID_!New_X!_!New_Y!=!P_ID_%X%_%Y%!"&set "P_ID_!X!_!Y!=#"
  21. if !now! equ c (set now=j) else (set now=c)
  22. goto :loop_1
  23. :Module_StartWith
  24. set  "line_0=                           "
  25. set  "line_1= ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ "
  26. set  "line_2= ┃  ┃  ┃  ┃╲ ┃ ╱┃  ┃  ┃  ┃ "
  27. set  "line_3= ┃  ┃  ┃  ┃ ╲┃╱ ┃  ┃  ┃  ┃ "
  28. set  "line_4= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
  29. set  "line_5= ┃  ┃  ┃  ┃ ╱┃╲ ┃  ┃  ┃  ┃ "
  30. set  "line_6= ┃  ┃  ┃  ┃╱ ┃ ╲┃  ┃  ┃  ┃ "
  31. set  "line_7= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
  32. set  "line_8= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  33. set  "line_9= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  34. set "line_10= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
  35. set "line_11= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  36. set "line_12= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  37. set "line_13= ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┫ "
  38. set "line_14= ┃                       ┃ "
  39. set "line_15= ┃                       ┃ "
  40. set "line_16= ┣━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┫ "
  41. set "line_17= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  42. set "line_18= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  43. set "line_19= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
  44. set "line_20= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  45. set "line_21= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  46. set "line_22= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
  47. set "line_23= ┃  ┃  ┃  ┃╲ ┃ ╱┃  ┃  ┃  ┃ "
  48. set "line_24= ┃  ┃  ┃  ┃ ╲┃╱ ┃  ┃  ┃  ┃ "
  49. set "line_25= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
  50. set "line_26= ┃  ┃  ┃  ┃ ╱┃╲ ┃  ┃  ┃  ┃ "
  51. set "line_27= ┃  ┃  ┃  ┃╱ ┃ ╲┃  ┃  ┃  ┃ "
  52. set "line_28= ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ "
  53. set "line_29=                           "
  54. for /l %%# in (1,1,10) do set "msg_%%#= "
  55. set now=j&set Undo_Num=0
  56. set "str=卒炮将士象马车兵炮帅仕相马车"&set "var=abcdefghijklmn"
  57. for /l %%# in (0,1,13) do set E_!var:~%%#,1!=!str:~%%#,1!
  58. for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do set P_ID_%%$_%%#=#
  59. 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:@==!")
  60. set "msg_1=批处理版象棋,由a2002编写完成,版本17.7.6.2,第三方cmos"
  61. set "msg_2=  ┏━┓┏━┓┏━┓      ┃悔┃┃重┃┃退┃      ┗━┛┗━┛┗━┛    "
  62. set "msg_4=[信息]"&set "c=h i j k l m n"&set "j=a b c d e f g"
  63. goto :eof
  64. :Module_Set
  65. for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do (
  66. if "!P_ID_%%$_%%#!" equ "#" (
  67. set /a t1=%%$*3-3,t2=t1+1,t3=t2+1,t4=%%#*3-3
  68. call :Command_1 "%%$" "%%#" "!t1!" "!t2!" "!t3!" "!t4!")
  69. 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_%%$_%%#=└─┘"
  70. 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_%%$_%%#=╚═╝")
  71. goto :eof
  72. :Module_Echo
  73. call :Module_Set
  74. set "msg_3=走棋方:!E_%now%!"
  75. cls
  76. echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  77. for /l %%# in (1,1,10) do (
  78. 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!
  79. 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!
  80. 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!)
  81. echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  82. goto :eof
  83. :Check_1
  84. if "!P_ID_%X%_%Y%!" equ "#" set "msg_4=棋不能为空!!!"&goto :loop_1
  85. for %%# in (!%now%!) do if "!P_ID_%X%_%Y%!" equ "%%#" set "msg_4=请拿自己的棋!!!"&goto :loop_1
  86. goto :eof
  87. :Check_2
  88. set t=0
  89. set F_c=!j!&set F_j=!c!
  90. for %%# in (!F_%now%!) do if "!P_ID_%New_X%_%New_Y%!" equ "%%#" set "msg_4=非法走棋!!!"&goto :loop_1
  91. call :CalcA
  92. 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))
  93. 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))
  94. for %%# in (b i) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
  95. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
  96. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
  97. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
  98. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
  99. ) else (
  100. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 3 goto :eof)
  101. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 3 goto :eof)
  102. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 3 goto :eof)
  103. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 3 goto :eof))))
  104. 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)
  105. if "!P_ID_%New_X%_%New_Y%!" equ "j" (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof))
  106. 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)
  107. if "!P_ID_%New_X%_%New_Y%!" equ "c" (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof))
  108. 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 (
  109. for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
  110. 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 (
  111. for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
  112. if "!P_ID_%X%_%Y%!" equ "e" (if !New_X! leq 5 (
  113. if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  114. if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  115. if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  116. if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
  117. if "!P_ID_%X%_%Y%!" equ "l" (if !New_X! geq 6 (
  118. if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  119. if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  120. if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)
  121. if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_2 !t1! !t2!&if defined t goto :eof)))
  122. for %%# in (f m) do (if "!P_ID_%X%_%Y%!" equ "%%#" (
  123. 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)
  124. 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)
  125. 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)
  126. 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)))
  127. for %%# in (g n) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
  128. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
  129. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
  130. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
  131. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
  132. ) else (
  133. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof)
  134. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof)
  135. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 2 goto :eof)
  136. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 2 goto :eof))))
  137. set "msg_4=非法走棋!!!"&goto :loop_1
  138. :CalcA
  139. set /a t1=X-New_X,t2=(Y-New_Y)*200
  140. set /a Return=t1+t2
  141. goto :eof
  142. :CalcB
  143. set CalcB_Return=0
  144. if "%~1" equ "1" for /l %%# in (!Y!,1,!New_Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
  145. if "%~1" equ "2" for /l %%# in (!X!,1,!New_X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
  146. if "%~1" equ "3" for /l %%# in (!New_Y!,1,!Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
  147. if "%~1" equ "4" for /l %%# in (!New_X!,1,!X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
  148. goto :eof
  149. :Cmos
  150. cmos c f
  151. set /a t1=!errorlevel!-1001
  152. if !errorlevel:~-3! equ 001 goto :%~1
  153. if !t1! leq 2000 goto :%~1
  154. set t2=!t1:~0,-3!
  155. set /a %~3=(t2-1)/6+1,%~2=(t1-t2*1000-1)/3+1
  156. if "!%~2!_!%~3!" equ "2_11" goto :Undo
  157. if "!%~2!_!%~3!" equ "2_12" goto :Restart
  158. if "!%~2!_!%~3!" equ "2_13" exit
  159. if !%~2! gtr 10 goto :%~1
  160. if !%~2! lss 1 goto :%~1
  161. if !%~3! gtr 9 goto :%~1
  162. if !%~3! lss 1 goto :%~1
  163. goto :eof
  164. :Undo
  165. if !Undo_Num! lss 2 set "msg_4=没有可悔的棋!!!"&goto :loop_1
  166. set /a t1=Undo_Num,t2=t1-1,Undo_Num-=2
  167. for /f "tokens=1,2 delims= " %%a in ("!Undo_%t1%!") do set "%%a"&set "%%b"
  168. for /f "tokens=1,2 delims= " %%a in ("!Undo_%t2%!") do set "%%a"&set "%%b"
  169. goto :loop_1
  170. :Command_1
  171. 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!"
  172. goto :eof
  173. :Command_2
  174. set t=&if "!P_ID_%~1_%~2!" equ "#" set t=1
  175. 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格式去传递当前棋局
  1. 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了

    代码:
  1. @echo off&setlocal enabledelayedexpansion&mode 90,33&title 批处理版象棋&color 76
  2. :Restart
  3. call :Module_StartWith
  4. :loop_1
  5. color 76
  6. title 批处理版象棋 - 请选棋
  7. call :Module_Echo
  8. set "msg_4=[信息]"
  9. call :Cmos loop_1 X Y
  10. call :Check_1
  11. :loop_2
  12. color 7e
  13. title 批处理版象棋 - 请走棋
  14. call :Cmos loop_2 New_X New_Y
  15. call :Check_2
  16. if "!P_ID_%New_X%_%New_Y%!" equ "c" msg * 红方(!E_j!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
  17. if "!P_ID_%New_X%_%New_Y%!" equ "j" msg * 绿方(!E_c!)获胜,点击鼠标继续&color c0&cmos c f&goto :Restart
  18. set /a Undo_Num+=1
  19. set "Undo_!Undo_Num!=P_ID_!X!_!Y!=!P_ID_%X%_%Y%! P_ID_!New_X!_!New_Y!=!P_ID_%New_X%_%New_Y%!"
  20. set "P_ID_!New_X!_!New_Y!=!P_ID_%X%_%Y%!"&set "P_ID_!X!_!Y!=#"
  21. if !now! equ c (set now=j) else (set now=c)
  22. goto :loop_1
  23. :Module_StartWith
  24. set  "line_0=                           "
  25. set  "line_1= ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ "
  26. set  "line_2= ┃  ┃  ┃  ┃╲ ┃ ╱┃  ┃  ┃  ┃ "
  27. set  "line_3= ┃  ┃  ┃  ┃ ╲┃╱ ┃  ┃  ┃  ┃ "
  28. set  "line_4= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
  29. set  "line_5= ┃  ┃  ┃  ┃ ╱┃╲ ┃  ┃  ┃  ┃ "
  30. set  "line_6= ┃  ┃  ┃  ┃╱ ┃ ╲┃  ┃  ┃  ┃ "
  31. set  "line_7= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
  32. set  "line_8= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  33. set  "line_9= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  34. set "line_10= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
  35. set "line_11= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  36. set "line_12= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  37. set "line_13= ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┫ "
  38. set "line_14= ┃                       ┃ "
  39. set "line_15= ┃                       ┃ "
  40. set "line_16= ┣━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┫ "
  41. set "line_17= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  42. set "line_18= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  43. set "line_19= ╠━━╋━━╬━━╋━━╬━━╋━━╬━━╋━━╣ "
  44. set "line_20= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  45. set "line_21= ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃ "
  46. set "line_22= ┣━━╬━━╋━━╋━━╋━━╋━━╋━━╬━━┫ "
  47. set "line_23= ┃  ┃  ┃  ┃╲ ┃ ╱┃  ┃  ┃  ┃ "
  48. set "line_24= ┃  ┃  ┃  ┃ ╲┃╱ ┃  ┃  ┃  ┃ "
  49. set "line_25= ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫ "
  50. set "line_26= ┃  ┃  ┃  ┃ ╱┃╲ ┃  ┃  ┃  ┃ "
  51. set "line_27= ┃  ┃  ┃  ┃╱ ┃ ╲┃  ┃  ┃  ┃ "
  52. set "line_28= ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ "
  53. set "line_29=                           "
  54. for /l %%# in (1,1,10) do set "msg_%%#= "
  55. set now=j&set Undo_Num=0
  56. set "str=卒炮将士象马车兵炮帅仕相马车"&set "var=abcdefghijklmn"
  57. for /l %%# in (0,1,13) do set E_!var:~%%#,1!=!str:~%%#,1!
  58. for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do set P_ID_%%$_%%#=#
  59. 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:@==!")
  60. set "msg_1=批处理版象棋,由a2002编写完成,第三方cmos"
  61. set "msg_2=  ┏━┓┏━┓┏━┓      ┃悔┃┃重┃┃退┃      ┗━┛┗━┛┗━┛    "
  62. set "msg_4=[信息]"&set "c=h i j k l m n"&set "j=a b c d e f g"
  63. goto :eof
  64. :Module_Set
  65. for /l %%$ in (1,1,10) do for /l %%# in (1,1,9) do (
  66. if "!P_ID_%%$_%%#!" equ "#" (
  67. set /a t1=%%$*3-3,t2=t1+1,t3=t2+1,t4=%%#*3-3
  68. 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!")
  69. 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_%%$_%%#=└─┘"
  70. 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_%%$_%%#=╚═╝")
  71. goto :eof
  72. :Module_Echo
  73. call :Module_Set
  74. set "msg_3=走棋方:!E_%now%!"
  75. cls
  76. echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  77. for /l %%# in (1,1,10) do (
  78. 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!
  79. 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!
  80. 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!)
  81. echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  82. goto :eof
  83. :Check_1
  84. if "!P_ID_%X%_%Y%!" equ "#" set "msg_4=棋不能为空!!!"&goto :loop_1
  85. for %%# in (!%now%!) do if "!P_ID_%X%_%Y%!" equ "%%#" set "msg_4=请拿自己的棋!!!"&goto :loop_1
  86. goto :eof
  87. :Check_2
  88. set t=0
  89. set F_c=!j!&set F_j=!c!
  90. for %%# in (!F_%now%!) do if "!P_ID_%New_X%_%New_Y%!" equ "%%#" set "msg_4=非法走棋!!!"&goto :loop_1
  91. call :CalcA
  92. 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))
  93. 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))
  94. for %%# in (b i) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
  95. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
  96. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
  97. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
  98. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
  99. ) else (
  100. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 3 goto :eof)
  101. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 3 goto :eof)
  102. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 3 goto :eof)
  103. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 3 goto :eof))))
  104. 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)
  105. if "!P_ID_%New_X%_%New_Y%!" equ "j" (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof))
  106. 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)
  107. if "!P_ID_%New_X%_%New_Y%!" equ "c" (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof))
  108. 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 (
  109. for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
  110. 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 (
  111. for %%# in (201 199 -199 -201) do if !Return! equ %%# goto :eof))
  112. if "!P_ID_%X%_%Y%!" equ "e" (if !New_X! leq 5 (
  113. if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
  114. if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
  115. if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)
  116. if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)))
  117. if "!P_ID_%X%_%Y%!" equ "l" (if !New_X! geq 6 (
  118. if !Return! equ 402 (set /a t1=X-1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
  119. if !Return! equ 398 (set /a t1=X+1,t2=Y-1&call :Command_1 !t1! !t2!&if defined t goto :eof)
  120. if !Return! equ -398 (set /a t1=X-1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)
  121. if !Return! equ -402 (set /a t1=X+1,t2=Y+1&call :Command_1 !t1! !t2!&if defined t goto :eof)))
  122. for %%# in (f m) do (if "!P_ID_%X%_%Y%!" equ "%%#" (
  123. 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)
  124. 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)
  125. 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)
  126. 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)))
  127. for %%# in (g n) do (if "!P_ID_%X%_%Y%!" equ "%%#" (if "!P_ID_%New_X%_%New_Y%!" equ "#" (
  128. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 1 goto :eof)
  129. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 1 goto :eof)
  130. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 1 goto :eof)
  131. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 1 goto :eof)
  132. ) else (
  133. if !Return! lss 200 if !Return! gtr 0 (call :CalcB 4&if !CalcB_Return! equ 2 goto :eof)
  134. if !Return! lss 0 if !Return! gtr -200 (call :CalcB 2&if !CalcB_Return! equ 2 goto :eof)
  135. if "!Return:~-2!" equ "00" if !Return! gtr 0 (call :CalcB 3&if !CalcB_Return! equ 2 goto :eof)
  136. if "!Return:~-2!" equ "00" if !Return! lss 0 (call :CalcB 1&if !CalcB_Return! equ 2 goto :eof))))
  137. set "msg_4=非法走棋!!!"&goto :loop_1
  138. :CalcA
  139. set /a t1=X-New_X,t2=(Y-New_Y)*200
  140. set /a Return=t1+t2
  141. goto :eof
  142. :CalcB
  143. set CalcB_Return=0
  144. if "%~1" equ "1" for /l %%# in (!Y!,1,!New_Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
  145. if "%~1" equ "2" for /l %%# in (!X!,1,!New_X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
  146. if "%~1" equ "3" for /l %%# in (!New_Y!,1,!Y!) do if "!P_ID_%X%_%%#!" neq "#" set /a CalcB_Return+=1
  147. if "%~1" equ "4" for /l %%# in (!New_X!,1,!X!) do if "!P_ID_%%#_%Y%!" neq "#" set /a CalcB_Return+=1
  148. goto :eof
  149. :Cmos
  150. cmos c f
  151. set /a t1=!errorlevel!-1001
  152. if !errorlevel:~-3! equ 001 goto :%~1
  153. if !t1! leq 2000 goto :%~1
  154. set t2=!t1:~0,-3!
  155. set /a %~3=(t2-1)/6+1,%~2=(t1-t2*1000-1)/3+1
  156. if "!%~2!_!%~3!" equ "2_11" goto :Undo
  157. if "!%~2!_!%~3!" equ "2_12" goto :Restart
  158. if "!%~2!_!%~3!" equ "2_13" exit
  159. if !%~2! gtr 10 goto :%~1
  160. if !%~2! lss 1 goto :%~1
  161. if !%~3! gtr 9 goto :%~1
  162. if !%~3! lss 1 goto :%~1
  163. goto :eof
  164. :Undo
  165. if !Undo_Num! lss 2 set "msg_4=没有可悔的棋!!!"&goto :loop_1
  166. set /a t1=Undo_Num,t2=t1-1,Undo_Num-=2
  167. for /f "tokens=1,2 delims= " %%a in ("!Undo_%t1%!") do set "%%a"&set "%%b"
  168. for /f "tokens=1,2 delims= " %%a in ("!Undo_%t2%!") do set "%%a"&set "%%b"
  169. goto :loop_1
  170. :Command_1
  171. set t=&if "!P_ID_%~1_%~2!" equ "#" set t=1
  172. 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://bbs.bathome.net/) Powered by Discuz! 7.2