本帖最后由 a2002 于 2017-7-6 10:56 编辑
唉,原创区发不了,发到这来算是批处理代码原创开源
批处理象棋人人对战,版本17.7.6,by a2002
上图:
界面比较简陋,看得懂就差不多了
想继续做人机对战,试一试行不行,行的话发出来
以下是源码,欢迎指出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 |