批处理实现三子棋游戏
2024-07-15 01:59:29
供稿:网友
@echo off
setlocal enabledelayedexpansion
mode con lines=25
:start
cls
set str=a1a2a3b1b2b3c1c2c3
set slt1=0
for %%i in (a b c) do (
set m%%i=
for %%j in (1 2 3) do (
set m%%j=
set m%%i%%j=
set n%%i%%j=
)
)
set mlr=
set mrl=
set mmlr=a1b2c3
set mmrl=c1b2a3
set win=
for %%i in (a,b,c) do (
for %%j in (1,2,3) do (
set %%i%%j=
)
)
echo ┏━┳━┳━┓
echo ┃1 ┃2 ┃3 ┃
echo ┣━╋━╋━┫
echo ┃4 ┃5 ┃6 ┃
echo ┣━╋━╋━┫
echo ┃7 ┃8 ┃9 ┃
echo ┗━┻━┻━┛
echo 谁先走?(c代表电脑,h代表人)
set /p slt1=
set human=
set cpu=
if %slt1% equ c set human=○&set cpu=●&goto 2
if %slt1% equ C set human=○&set cpu=●&goto 2
set human=●&set cpu=○
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:begin
:1
echo 请您走棋!(输入数字1~9)
set /p slt2=
if !slt2! equ 1 set slt2=a1
if !slt2! equ 2 set slt2=b1
if !slt2! equ 3 set slt2=c1
if !slt2! equ 4 set slt2=a2
if !slt2! equ 5 set slt2=b2
if !slt2! equ 6 set slt2=c2
if !slt2! equ 7 set slt2=a3
if !slt2! equ 8 set slt2=b3
if !slt2! equ 9 set slt2=c3
if "!n%slt2%!" neq "" echo 此处已经有子!&goto 1
set str=!str:%slt2%=!
set mmrl=!mmrl:%slt2%=!
set mmlr=!mmlr:%slt2%=!
set %slt2%=%human%
set m%slt2%=h
set n%slt2%=h
cls
echo ┏━┳━┳━┓
echo ┃%a1%┃%b1%┃%c1%┃
echo ┣━╋━╋━┫
echo ┃%a2%┃%b2%┃%c2%┃
echo ┣━╋━╋━┫
echo ┃%a3%┃%b3%┃%c3%┃
echo ┗━┻━┻━┛
call :judge
if !win! equ h echo 你居然赢了,太让我惊讶了!&pause&goto end
if !win! equ c echo 嘿嘿,不好意思我赢了!&pause&goto end
if "!str!" equ "" echo 平局!&pause&goto end
:2
echo 等待电脑走棋
call :ai
for /l %%i in (1,1,15) do set/p r=^><nul&ping /n 0 127.1>nul
set slt3=!max!
set str=!str:%slt3%=!
set mmrl=!mmrl:%slt3%=!
set mmlr=!mmlr:%slt3%=!
cls
set %slt3%=%cpu%