|
bat-zw
金牌会员
永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『楼 主』:
[原创]批处理版五子棋
@echo off&color 1f&setlocal enabledelayedexpansion
title 五子棋 by zw19750516
set "codes= a b c d e f g h i j "&set "s=┃"&set "m=-1"
set "code= %codes: =% "
:begin
cls&echo ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓
for /l %%a in (1,1,10) do (
for /l %%i in (1,1,10) do (set str=!code:~%%i,1!
if defined _%%a!str! (call :lp %%a
set /p=%s% !var! <nul
) else (
set /p=%s% <nul
))
set /p=%s% %%a<nul
if %%a neq 10 (
echo.&echo ┣━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━╋━━┫
) else (
echo.&echo ┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛
))
for /l %%i in (1,1,10) do set /p= !code:~%%i,1! <nul
echo.&echo.请依次输入右、下双坐标如:4c来走棋,持黑者先。
if %m% neq -1 set /p=对手上一步走的%a%%b%,<nul
set /a n+=1,m+=1
if %m% equ 2 set m=0
set ab=&set flag=&if %m% equ 0 (set /p ab=请黑方走棋:) else (set /p ab=请白方走棋:)
if not defined ab goto wrong
if "%ab:~3%" neq "" goto wrong
if "%ab:~2%" neq "" (set a=%ab:~,2%&set b=%ab:~2,1%) else (set a=%ab:~,1%&set b=%ab:~1%)
echo %a%|findstr "[1-9]">nul||goto wrong
if %a% gtr 10 goto wrong
for %%i in (%codes%) do if "%%i" equ "%b%" set flag=a
if not defined flag goto wrong
if not defined _%a%%b% (if %m% equ 0 (set "_%a%%b%=○") else (set "_%a%%b%=●")) else (goto wrong)
if %n% lss 101 (goto begin) else (pause>nul&goto :eof)
:wrong
set /a n-=1,m-=1
set /p=错误!<nul&ping /n 2 127.1>nul&goto begin
:lp
set var=!_%1%str%! [ Last edited by zw19750516 on 2008-7-14 at 01:46 AM ]
|
批处理之家新域名:www.bathome.net |
|
2008-7-14 01:06 |
|
|
26933062
银牌会员
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第
2 楼』:
暂时提两点问题。
一、无法判断正负
二、最后一行无法输入
发个我以前写的。
@echo off&mode con cols=80 lines=22&color 1f&title 批处理五子棋
:: code 随风 @bbs.bathome.cn 2008-04-06
echo\&echo 请选择 y 电脑自动走棋(随机乱走,以判断程序是否正确)
echo\&echo 选择 n 人走棋,不能人机对弈
echo\&set /p cs= y n ?
if /i not "%cs%"=="y" (set "cs=") ELSE (set cs=现在是由电脑随机走棋)
set gz1= 走棋方法
set gz3= 输入行和列的代号即可
set gz5= 英文字母代表列,数字代表行
set gz7= 如输入: h8 或 8h
set gz9= 即是在 h列 和 行8 的交叉点落子
set gz11= 如屏幕变成红色,则说明走棋错误
:start
setlocal enabledelayedexpansion&cls&color 1f
set a1=┌&set o1=┐&set a12=└&set "o12=┘"&set "yans=0"
for %%j in (2 3 4 5 6 7 8 9 10 11) do (set a%%j=├&set o%%j=┤)
for %%z in (b c d e f g h i j k l m n) do (
set %%z1=┬&set "%%z12=┴"
for /l %%j in (2 1 11) do set "%%z%%j=┼"
)
for %%z in (a b c d e f g h i j k l m n o) do (
set /a max+=1&set %%z=!max!&set "!max!=%%z"
)
for /l %%a in (0 1 9) do set abc%%a=a
goto :xs
:loop
if !yans! equ 0 (set ya=白棋&set bk=●) else (set ya=黑棋&set bk=○)
if not defined cs (
set flag=&echo\&set /p zou= 请走!ya!
) else (
set zzzmm=ABCDEFGHIJKLMNO
set /a www=!random!%%12+1
set /a www1=!random!%%14+0
call set zzzmm1=%%zzzmm:~!www1!,1%%
set flag=&echo\&set zou=!zzzmm1!!www!
)
if "!zou!"=="" set flag= 输入不能为空&set zou=&goto xs
set "zou=!zou: =!"
if "!zou:~1,1!"=="" set flag= !zou! 输入不正确!&set zou=&goto xs
if not "!zou:~3,1!"=="" set flag= !zou! 输入不正确!&set zou=&goto xs
set "abc=!zou:~0,1!"
if defined abc!abc! set "zou=!zou:~-1!!zou:~0,-1!"
set "abc=!zou:~0,1!"
if defined abc!abc! (set flag= 输入不正确!&set zou=&goto xs)
if /i "!zou!"=="ccc" endlocal&goto start
if not defined !zou! set flag= !zou! 目标位置不存在!&set zou=&goto xs
if defined !zou!x set flag= 不能走 !zou!&set zou=&goto xs
set "!zou!x=!ya!"
set "!zou!=!bk!"
:xs 显示棋盘
cls&echo 批处理五子棋
echo\&echo 输入 ccc 重新开始游戏 %cs%
if not defined flag set /a yans=^^!yans
echo\&echo A B C D E F G H I J K L M N O
for /l %%i in (1 1 12) do (
set "ko= "
if %%i lss 10 (set ko= !ko!)
set/p=!ko!%%i <nul
for %%z in (a b c d e f g h i j k l m n o) do set/p=!%%z%%i!<nul
if defined gz%%i set /p= !gz%%i!<nul
echo.
)
if defined flag (
echo\&echo !flag!&color cf
ping/n 2 127.1>nul&color 1f
goto loop
)
if not defined zou goto loop
::判断胜负
:pd
set hang=!zou:~0,1!&set lie=!zou:~1!
set /a _hangx=!lie!-4,_hangda=!lie!+4
call set _lie=%%!hang!%%
set /a lx=!_lie!-4,lda=!_lie!+4
:: 判断列是否定出胜负
for /l %%a in (!_hangx! 1 !_hangda!) do (
set zon=!zou:~0,1!%%ax
call set _zon=%%!zon!%%-!zon!
if defined _zon (set _pphen=!_pphen! !_zon!) else (
set _pphen=!_pphen! x
))
call :sss "!_pphen!"
if defined jiesu endlocal&goto ok
:: 判断横向是否定出胜负
set _pphen=&set _x_x=&set xie=!_hangx!
set _you=&set _you1=
for /l %%a in (!lx! 1 !lda!) do (
set "phx=!%%a!!zou:~1!x"
call set "pphen=%%!phx!%%-!%%a!!zou:~1!x"
if defined pphen (set _pphen=!_pphen! !pphen!) else (
set "_pphen=!_pphen! x"
)
rem 判断左上至右下是否胜出
call set "_xie=%%!%%a!!xie!x%%"
call set "_xie_=%%_xie%%-!%%a!!xie!x"
set /a xie+=1
if defined _xie_ (set _x_x=!_x_x! !_xie_!) else (
set "_x_x=!_x_x! x"
)
rem 判断右上至左下是否胜出
call set "you=%%!%%a!!_hangda!x%%"
call set "_you=%%you%%-!%%a!!_hangda!x"
set /a _hangda-=1
if defined _you (set _you1=!_you1! !_you!) else (
set "_you1=!_you1! x"
)
)
call :sss "!_pphen!"
if defined jiesu endlocal&goto ok
call :sss "!_you1!"
if defined jiesu endlocal&goto ok
call :sss "!_x_x!"
if defined jiesu endlocal&goto ok
goto loop
:sss
set _pphen=%~1&set pdpd=0&set num1=&set "num2="&set "jiesu="
for %%a in (!_pphen!) do (
set "num1=!num2!"
set "num2=%%a"
if /i "!num1:~0,3!"=="!num2:~0,3!" (
if not "!num1:~0,1!"=="-" (
set /a pdpd+=1&set "senc=!senc! !num2:~0,-1!"
if !pdpd! geq 4 (
call set "jiesu=%%senc:!num2:~0,3!=%%"
echo\&echo !num1:~0,2! 胜出 !jiesu!
goto :eof
)
) else (set pdpd=0&set senc=!num2:~0,-1!)
) else (set pdpd=0&set senc=!num2:~0,-1!)
)
goto :eof
:ok
echo\&echo 按任意键重新开始。。。
for /l %%i in (1 1 5) do (
for %%a in (a d) do color %%af&ping/n 1 127.1>nul
)
pause>nul
goto start
|
致精致简! |
|
2008-7-14 01:23 |
|
|
bat-zw
金牌会员
永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第
3 楼』:
Quote: | Originally posted by 26933062 at 2008-7-14 01:23:
暂时提两点问题。
一、无法判断正负
二、最后一行无法输入
发个我以前写的。
[code]
@echo off&mode con cols=80 lines=22&color 1f&title 批处理五子棋 ... |
|
第一个问题已经解决,粗心了,谢谢。
第二个问题在思考中。
|
批处理之家新域名:www.bathome.net |
|
2008-7-14 01:35 |
|
|