复制代码
- @echo off
- set cbt=0
- if /i "%1"=="/s" set cbt=1
- if /i "%1"=="/b" set cbt=0
- if "%cbt%"=="0" (mode con cols=31 lines=16) else mode con cols=19 lines=11
- if /i "%1"=="/?" goto help
- setlocal ENABLEDELAYEDEXPANSION
- title 四子棋 by yslyxqysl&color 60
- set "bc=●"&set "wc=○"
- set n!bc!=!wc!&set n!wc!=!bc!
- goto start%cbt%
- :start0
- set "pc=!bc!"
- for /l %%i in (1 1 6) do for /l %%j in (1 1 7) do set "c%%i%%j= "&set "c%%i%%j= "
- :loop0
- cls&echo ┌─┬─┬─┬─┬─┬─┬─┐
- for /l %%i in (1 1 6) do (
- for /l %%j in (1 1 7) do set /p"=│!c%%i%%j!"<nul
- echo │&if not %%i==6 echo ├─┼─┼─┼─┼─┼─┼─┤
- )
- echo └─┴─┴─┴─┴─┴─┴─┘
- echo, 1 2 3 4 5 6 7
- goto input
- :start1
- set "pc=!bc!"
- set "c11=┌"&set "c17=┐"&set "c61=└"&set "c67=┘"
- for /l %%j in (2 1 6) do set "c1%%j=┬"&set "c6%%j=┴"
- for /l %%z in (2 1 5) do (
- set "c%%z1=├"&set "c%%z7=┤"
- for /l %%j in (2 1 6) do set "c%%z%%j=┼"
- )
- :loop1
- cls&echo ┏━━━━━━━┓
- for /l %%z in (1 1 6) do set /p=┃<nul&(for /l %%i in (1 1 7) do set /p=!c%%z%%i!<nul)&echo ┃
- echo ┃1 2 3 4 5 6 7 ┃&echo ┗━━━━━━━┛
- goto input
- :input
- if not "!isend!"=="" goto !isend!
- set input=&set /p input=请!pc!方输入:
- if /i "!input!"=="e" exit
- if /i "!input:~0,1!"=="r" (
- if /i "!input:~1,1!"=="b" set cbt=0&set input=r&mode con cols=32 lines=15
- if /i "!input:~1,1!"=="s" set cbt=1&set input=r&mode con cols=19 lines=11
- if "!input!"=="r" goto start!cbt!
- )
- if /i "!input!"=="h" goto help
- if /i "!input!"=="?" goto help
- echo !input!|findstr "^[1-7]$">nul||goto loop!cbt!
- if "!c1%input%!"=="!bc!" goto loop!cbt!
- if "!c1%input%!"=="!wc!" goto loop!cbt!
- for /l %%z in (1 1 6) do (
- if not "!c%%z%input%!"=="!bc!" if not "!c%%z%input%!"=="!wc!" set cp=c%%z!input!
- )
- set !cp!=!pc!&call :isdraw&call :iswin
- set "pc=!n%pc%!"
- goto loop!cbt!
- :isdraw
- set isend=draw
- for /l %%j in (1 1 7) do if not "!c1%%j!"=="!bc!" if not "!c1%%j!"=="!wc!" set isend=
- goto :eof
- :iswin
- for /l %%j in (-1 1 1) do (
- for /l %%k in (-1 1 1) do (
- set lptm=0&set tp=0
- if %%j==0 if %%k==0 set tp=1
- if tp neq 1 call :getcdt %%j %%k&set d%%j%%k=!tp!
- ) )
- for %%l in ("-1 0" "-1 -1" "0 -1" "-1 1") do (
- for /f "tokens=1,2 delims= " %%m in ("%%~l") do (
- set /a adm=0-%%m,adn=0-%%n
- call set /a "urc=!d%%m%%n!+%%d!adm!!adn!%%+1"
- if !urc! geq 4 set isend=win
- ) )
- goto :eof
- :getcdt
- set /a lptm+=1
- set /a cdta=%cp:~1,1%+%1*%lptm%,cdtb=%cp:~2,1%+%2*%lptm%
- if !cdta! lss 1 goto :eof
- if !cdta! gtr 6 goto :eof
- if !cdtb! lss 1 goto :eof
- if !cdta! gtr 7 goto :eof
- if !c%cdta%%cdtb%!==!pc! set /a tp+=1
- if !lptm! equ 3 (goto :eof) else goto getcdt
- :win
- set isend=&echo !n%pc%!方胜!
- pause>nul&goto start!cbt!
- :draw
- set isend=&echo 和棋!
- pause>nul&goto start!cbt!
- :help
- cls&echo Page 1/2
- echo 输入列的代码,棋子
- echo 就会放在此列最下面
- echo 的空白处。有任何一
- echo 方的四个子或以上连
- echo 成一条直线就获胜。
- echo 棋盘满了就和局。
- pause>nul&cls
- echo Page 2/2
- echo 支持两种棋盘模式,
- echo 输入rb或rs即可选择
- echo 棋盘模式。
- echo.
- echo E 退出
- echo R[B ^| S] 重新开始
- echo H ^| ? 帮助
- pause>nul
- if "!cbt!"=="0" (mode con cols=32 lines=15) else mode con cols=19 lines=11
- goto start!cbt!
欢迎光临 批处理之家 (http://www.bathome.net/) | Powered by Discuz! 7.2 |