中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-09 07:01
47,811 主题排行 / 349,895 发帖 / 今日 0 篇 / 48,253 会员排行
DOS批处理 & 脚本技术(批处理室) » 挑战代码极限效率(模拟围棋版五子棋)
可打印版本  833 / 10
第1楼 bat-zw 发表于 2008-07-18 18:26
金牌会员 发帖 1,276 积分 3,105
挑战代码极限效率(模拟围棋版五子棋)
在此,要非常感谢namejm的大力帮助,也请大家都来挑战一下这极限的效率(单
单大循环就是361*361次,其中还要涉及到call...)
----------------------------------------------------------------------------------------------------------




[ Last edited by zw19750516 on 2008-7-18 at 08:16 PM ]
第2楼 BC 发表于 2008-07-18 20:01
中级用户 发帖 175 积分 338
看到一行行的for就头晕``

最近论坛好冷清``
第3楼 BC 发表于 2008-07-18 20:02
中级用户 发帖 175 积分 338
怎么是自己下的?

电脑自己打自己,但是好像速度慢了点哦
第4楼 bat-zw 发表于 2008-07-18 20:18
金牌会员 发帖 1,276 积分 3,105
Originally posted by BC at 2008-7-18 20:02:
怎么是自己下的?

电脑自己打自己,但是好像速度慢了点哦

要改为手动操作是很容易的,这也速度慢,估计这是最快的速度了!
第5楼 26933062 发表于 2008-07-18 22:15
银牌会员 发帖 879 积分 2,268
速度已经不错了,视觉效果也不错。美中不足是电脑走棋没有智能。
另外:提个建议,看是否行的通。
一、棋盘可扩大,不要边框 ,这样更美观。
二、是否可以将棋盘的落子处,不要显示十字架,而是直接显示坐标呢?否则走棋时寻找坐标很麻烦。但不知道这样是否会影响美观程度。
第6楼 slore 发表于 2008-07-18 22:31
铂金会员 发帖 2,478 积分 5,212
。。。。。

随机太厉害……快摆满了才有5个联的……

貌似名字不对哦~
第7楼 metoo 发表于 2008-07-18 22:58
初级用户 发帖 93 积分 195
Originally posted by BC at 2008-7-18 08:01 PM:
看到一行行的for就头晕``

最近论坛好冷清``

for没啥头晕的。。到处是goto最晕了。。自己写的看着都晕
第8楼 bat-zw 发表于 2008-07-18 23:39
金牌会员 发帖 1,276 积分 3,105
更新到双人下,并加入注释:




[ Last edited by zw19750516 on 2008-7-19 at 01:35 PM ]
第9楼 HAT 发表于 2008-07-19 01:29
版主 发帖 5,017 积分 9,023
要想电脑走棋有智能,可以到网上找个公开的算法,我看过很多C语言版本的,试着用批处理实现,不过估计会比较复杂。
第10楼 BC 发表于 2008-07-19 09:37
中级用户 发帖 175 积分 338
支持下,总觉得批处理在这方面的能力很弱..
第11楼 BC 发表于 2008-07-19 09:41
中级用户 发帖 175 积分 338
@echo off
title 五子棋之兵临城下 作者:英雄 E-mail:bizhuang0917@126.com
setlocal enabledelayedexpansion
mode con cols=40 lines=5
color E0
echo.
set /p slt1= 您确定要向英雄家族挑战吗?(y/n)
cls
if /i not "%slt1%"=="y" goto def
:whofirst
echo.

echo 1、挑战者先手
echo 2、英雄家族先手
set /p slt2=
if not "%slt2%" equ "1" if not "%slt2%" equ "2" cls&echo 请正确输入!!&pause&cls&goto whofirst
cls
mode con cols=45 lines=10
:people
echo 请选择人物
echo.
echo 级别越高思考时间越长
echo.
echo 1、宠物 棋力--9级以下
echo 2、小师妹 宝宝 棋力--9~7级
echo 3、三师兄 猛虎 棋力--6~4级
echo 4、二师兄 飞龙 棋力--3~1级
echo 5、大师兄 英雄 棋力--9段
set /p slt3=
cls
if %slt3%==5 echo 对不起,英雄请产假回家照顾老婆了,请谅解~~。&pause&cls&goto people
if not "%slt3%" equ "1" if not "%slt3%" equ "2" if not "%slt3%" equ "3" if not "%slt3%" equ "4" (
cls
echo 请输入正确的人物代号!
pause
cls
goto people
)



::::::::::::::::::::::::::::::::::::::::::::::::
::以下定义一些变量,包括图形界面中的元素
::::::::::::::::::::::::::::::::::::::::::::::::
:def

set 纵轴=B C D E F G H I J K L M N

for %%i in (a %纵轴% o) do (
set /a bridge+=1
set ctoi%%i=!bridge!

)

set bridge=

for %%i in (a %纵轴% o) do (
set /a bridge+=1
set itoc!bridge!=%%i

)

:start



for %%i in (a %纵轴% o) do (
for /l %%j in (1,1,15) do (
set my%%i%%j=*
)

)

set A1=┏
set A15=┓
set O1=┗
set O15=┛

for /l %%i in (2,1,14) do set a%%i=┳
for /l %%i in (2,1,14) do set o%%i=┻
for %%i in (%纵轴%) do set %%i1=┣&set %%i15=┫
for %%i in (%纵轴%) do (
for /l %%j in (2,1,14) do (
set %%i%%j=╋
)
)

set round=1
set preinput=
mode con cols=61 lines=40
:::::::::::::::::::::::::::::::::::::::::::::::
::以下为交替落子模块
:::::::::::::::::::::::::::::::::::::::::::::::
call:graph

:play

:blackinput
if %round% geq 100 goto nowin
if /i "%slt1%"=="y" if "%slt2%"=="2" call:ai ● b&goto whiteinput
set /p input=第%round%手,请黑方输入
if /i "%input%"=="restart" goto start
if "!my%input%!"=="*" (
set %input%=●
set my%input%=b
set /a round+=1
) else (
echo 输入有误,请重新输入!
goto blackinput)
call:graph
call:judge %input%

:whiteinput
if %round% geq 100 goto nowin
if /i "%slt1%"=="y" if "%slt2%"=="1" call:ai ○ w&goto play
set /p input=第%round%手,请白方输入
if /i "%input%"=="restart" goto start
if "!my%input%!"=="*" (
set %input%=○
set my%input%=w
set /a round+=1
) else (
echo 输入有误,请重新输入!
goto whiteinput)
call:graph
call:judge %input%

goto play

:::::::::::::::::::::::::::::::::::::::::::::::
::以下为判断胜负模块
:::::::::::::::::::::::::::::::::::::::::::::::
:judge
set tmp=%1
set var1=!tmp:~0,1!
set var2=!tmp:~1!
set /a flag1=ctoi%var1%-1+var2
set /a flag2=var2-ctoi%var1%+1
rem 下面定义四个判断要用到的指标,分别代表横纵斜四个方向的落子情况
set judgeheng=
set judgezong=
set judgeyszx=
set judgezsyx=
rem 下面定义上述变量的具体值

rem 横向
for /l %%j in (1,1,15) do (
set judgeheng=!judgeheng!!my%var1%%%j!
)
rem 纵向
for %%j in (a %纵轴% o) do (
set judgezong=!judgezong!!my%%j%var2%!
)
rem 从右上到左下
for %%i in (a %纵轴% o) do (
call set judgeyszx=!judgeyszx!%%my%%i!flag1!%%
set /a flag1-=1
)
rem 从左上到右下
for %%i in (a %纵轴% o) do (
call set judgezsyx=!judgezsyx!%%my%%i!flag2!%%
set /a flag2+=1
)
rem 将上述四个指标串起来并进行判断
set judge=!judgeheng!*!judgezong!*!judgeyszx!*!judgezsyx!

(echo !judge!|find "bbbbb">nul)&&goto blackwin
(echo !judge!|find "wwwww">nul)&&goto whitewin
set score=
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::
::以下胜负已分
:::::::::::::::::::::::::::::::::::::::::::::::
:blackwin
set %input%=★
call :graph
echo 黑第%round%手胜!
pause
goto start

:whitewin
set %input%=☆
call :graph
echo 白第%round%手胜!
pause
goto start

:nowin
echo 百手和棋!
pause
goto start
:::::::::::::::::::::::::::::::::::::::::::::::
::以下为绘图过程
:::::::::::::::::::::::::::::::::::::::::::::::
:graph
cls
echo 输入RESTART重新开局
set /p = <nul
for /l %%i in (1,1,8) do set /p=%%i <nul
for /l %%i in (9,1,15) do set /p=%%i <nul
::echo.
for %%i in (A %纵轴%) do (
set /p =%%i<nul
for /l %%j in (1,1,14) do (
set /p =!%%i%%j!━<nul
)
echo !%%i15!
for /l %%j in (1,1,15) do (
set /p = ┃ <nul
)
echo.
)
set /p =O<nul
for /l %%i in (1,1,14) do set /p =!O%%i!━<nul
echo !O15!
echo 输入时先字母后数字。如H8。
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::
::以下是电脑下棋思路
:::::::::::::::::::::::::::::::::::::::::::::::
:ai
if %round% equ 1 set input=h8&goto ainext
set aitmp=%input%
set aivar1=%aitmp:~0,1%
set aivar2=%aitmp:~1%

:loop
set /a aiflag1=ctoi%aivar1%+%random%%%3-%random%%%3
set aiflag2=!itoc%aiflag1%!

set /a aivar=aivar2+%random%%%3-%random%%%3

if "!my%aiflag2%%aivar%!"=="*" (
set input=%aiflag2%%aivar%
)else goto loop

set /a aic1=ctoi%aivar1%+1
set /a aic2=ctoi%aivar1%-1
set aic1=!itoc%aic1%!
set aic2=!itoc%aic2%!
set /a aii1=aivar2+1
set /a aii2=aivar2-1
set aistr=bw
set air=!aistr:%2=!

call :analyse %aivar1%%aii1% %air%
call :analyse %aivar1%%aii2% %air%
call :analyse %aic1%%aivar2% %air%
call :analyse %aic2%%aivar2% %air%
call :analyse %aic1%%aii1% %air%
call :analyse %aic1%%aii2% %air%
call :analyse %aic2%%aii1% %air%
call :analyse %aic2%%aii2% %air%

if not defined preinput goto ainext
set aitmp=%preinput%
set aivar1=!aitmp:~0,1!
set aivar2=!aitmp:~1!
set /a aic1=ctoi%aivar1%+1
set /a aic2=ctoi%aivar1%-1
set aic1=!itoc%aic1%!
set aic2=!itoc%aic2%!
set /a aii1=aivar2+1
set /a aii2=aivar2-1
call :analyse %aivar1%%aii1% %2
call :analyse %aivar1%%aii2% %2
call :analyse %aic1%%aivar2% %2
call :analyse %aic2%%aivar2% %2
call :analyse %aic1%%aii1% %2
call :analyse %aic1%%aii2% %2
call :analyse %aic2%%aii1% %2
call :analyse %aic2%%aii2% %2

:ainext
set %input%=%1
set my%input%=%2
set /a round+=1
set preinput=%input%
call:graph
call:judge %input%
goto :eof
:::::::::::::::::::::::::::::::::::::::::::
::分析评价模块
:::::::::::::::::::::::::::::::::::::::::::
:analyse
if not "!my%1!"=="*" goto :eof
set Atmp=%1
set Avar1=!Atmp:~0,1!
set Avar2=!Atmp:~1!
set /a Aflag1=ctoi%Avar1%-1+Avar2
set /a Aflag2=Avar2-ctoi%Avar1%+1

set judgeheng=
set judgezong=
set judgeyszx=
set judgezsyx=


for /l %%j in (1,1,15) do (
set judgeheng=!judgeheng!!my%Avar1%%%j!
)

for %%j in (a %纵轴% o) do (
set judgezong=!judgezong!!my%%j%Avar2%!
)

for %%i in (a %纵轴% o) do (
call set judgeyszx=!judgeyszx!%%my%%i!Aflag1!%%
set /a Aflag1-=1
)

for %%i in (a %纵轴% o) do (
call set judgezsyx=!judgezsyx!%%my%%i!Aflag2!%%
set /a Aflag2+=1
)

set judge=!judgeheng!*!judgezong!*!judgeyszx!*!judgezsyx!

set Astr=%2

(echo !judge!|find "%Astr%">nul)&&(if "%score%" leq "1" set score=1&set input=%1)
if "%slt3%" geq "2" (echo !judge!|find "%Astr%%Astr%">nul)&&(if "%score%" leq "2" set score=2&set input=%1)
if "%slt3%" geq "3" (echo !judge!|find "%Astr%%Astr%%Astr%">nul)&&(if "%score%" leq "3" set score=3&set input=%1)
if "%slt3%" equ "4" (echo !judge!|find "%Astr%%Astr%%Astr%%Astr%">nul)&&(if "%score%" leq "4" set score=4&set input=%1)

goto :eof

从verybat转过来的
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023