标题: CMD下批处理小游戏21点 [打印本页]
作者: everest79 时间: 2008-10-26 09:20 标题: CMD下批处理小游戏21点
规则:
发牌与叫牌为先闲后庄
庄为电脑,闲为玩家
首次发牌一家两张,一明一暗,庄家的明牌显示在屏幕上给闲家参考,闲家的明牌做为一个值提供给电脑判断是否要牌,然后闲家首先决定是否叫牌
当闲家爆掉(大于21点)时,庄家直接赢得本局,庄家不用再叫牌
闲家牌总数达到五张时,自动结束闲家叫牌,转为庄家选择叫牌
闲家放弃叫牌后转为庄家叫牌
相同点数庄吃闲,五张牌大4-20点
要求:
在CMD下不能显示扑克牌图案,用汉字代替
需要有总局数,庄闲胜局纪录
胜利判定需要你自定义一个渐进递归的算式,例如
总局为1-5局时需要对战比分 1:2
6-15局时比分 1:1.9
...
具体局数自定义,递归单位也自定义
游戏的结局有三个结果,第一是庄胜闲,第二是闲胜庄,第三是累死电累(达到总局上限)
牌的正面:复制代码
牌的背面- ┏━━┓
- ┃++++┃
- ┃++++┃
- ┃++++┃
- ┗━━┛
复制代码
操作界面- ┏━━┓┏━━┓
- ┃6 ┃┃++++┃
- ┃ ┃┃++++┃
- ┃ 方┃┃++++┃
- ┗━━┛┗━━┛
-
-
-
-
-
-
-
-
-
-
- ┏━━┓┏━━┓
- ┃10 ┃┃A ┃
- ┃ ┃┃ ┃
- ┃ 黑┃┃ 梅┃
- ┗━━┛┗━━┛
复制代码
我自已也在写,但判断方面比较困难
首先电脑叫牌与否取决于自已牌面大小,对家明牌,对家叫了几张牌,接近21点时叫牌判断不但要考虚这些,还需要添加一个随机数
再者就是代码的效率,这个每个人的爱好不同,就不多讲了
作者: pusofalse 时间: 2008-10-29 20:22
期待大侠的代码出炉!~
作者: everest79 时间: 2008-10-31 23:38
抛砖引玉,我只写了一半,逻辑方面还没有完成- @ECHO OFF
- :Init
- ECHO A=0 B=0 >ll.txt
- SETLOCAL ENABLEDELAYEDEXPANSION
- Set _String=黑红梅方
- Set _Replace1=1 A 1 1
- Set _Replace2=A3 K 13 10
- Set _Replace3=A2 Q 12 10
- Set _Replace4=AA J 11 10
- Set _Replace5=A0 10 10 10
- Set /A _ZFen=0,_XFen=0,Total+=1
-
-
- :Start
- Set /A Count+=1,1/(2/Count) 2>nul||Set Count=2&&Goto SelectP
- If Not Defined _Computer2 (
- CALL :FaPai Computer%Count%
- If Not Defined _Computer2 (
- CALL :Screen "A" "!DianShu:~0,2!" "!HuaSe!"
- CAll :Back "A"
- )
- )
- CALL :FaPai Players%Count%
- CALL :Screen "B" "!DianShu:~0,2!" "!HuaSe!"
- Goto Start
-
- :SelectP
- Set /A CountP+=1,1/(3/CountP) 2>nul||Set CountP=3&&Goto SelectC
- If Not Defined _Players3 (
- Set ACount=2
- CALL :JiFen Players SelectP
- )
- CALL :Output
- Set /P Instr="(Quit;Enter any key;Enter):"
- If Defined Instr (
- If /I *!Instr! == *quit (
- Goto :eof
- ) Else (
- Set /A CountP=CountP-1
- Goto SelectC
- )
- )
- CALL :Console "Players" "B" "SelectP" %CountP%
- Goto %_Label%
-
- :SelectC
- Set /A CountC+=1,1/(3/CountC) 2>nul||Set CountC=3&&Goto End
- Set /A _Chk1=Players1+10,_Chk2=(21-ComputerFen-CountP)/2
- Set /A _Chk3=%random%%%2,_Chk4=%random%%%100
- If Not Defined _Computer3 (
- Set ACount=2
- CALL :JiFen Computer SelectC
- )
- If %ComputerFen% LSS 15 (
- Goto Next) Else (
- If !_Chk1! GTR !ComputerFen! (
- If !CountP! GTR 0 (
- If !_Chk2! GEQ 2 (
- If !_Chk3! EQU 1 (Goto Next)
- ) Else (
- If !_Chk2! LEQ -2 (
- If !_Chk4! EQU 99 (Goto Next)
- )
- )
- )
- )
- )
- Set /A CountC-=1
- Goto End
- :Next
- CALL :Console "Computer" "A" "SelectC" %CountC%
- Goto %_Label%
-
-
-
- :Console
- ::%1=Players(Computer) %2=B(A) %3=Select+C(P)
- Set /A ACount=Count+%~4
- CALL :FaPai %~1%ACount%
- CALL :JiFen %~1 %~3
- CALL :Screen "%~2" "!DianShu:~0,2!" "!HuaSe!"
- Goto :eof
-
- :FaPai
- ::%1=Computer(Players)+Count
- Set /A DianShu=%random%%%13+1
- If *!Set%DianShu%! == *Not Goto FaPai
- Set _%~1=%DianShu%
- If Not Defined Set%DianShu% (
- CALL :Strto
- Set Set%DianShu%=!Str!
- )
- Set Set%DianShu%=!Set%DianShu%:Not=!
- Set HuaSe=!Set%DianShu%:~0,1!
- Set Set%DianShu%=!Set%DianShu%:%HuaSe%=!Not
- :Conver
- For /F "tokens=2-5 delims== " %%a in ('
- Set _Replace') DO (
- Set "DianShu=!DianShu:%%a=%%b! "
- Set _%~1=!_%~1:%%c=%%d!
- )
- Set _x%~1=!DianShu:~0,2! !HuaSe!
- Goto :eof
-
- :Strto
- Set Str=%_String%
- Set /A _str1=%random%%%4
- Set _str2=!Str:~%_str1%,4!
- Set Str=%_str2%!Str:%_str2%=!
- Set /A _str1=%random%%%3+1
- Set _str2=!Str:~0,-%_str1%!
- Set Str=%_str2%!Str:%_str2%=!
- Goto :eof
-
- :JiFen
- Set /A Shangx=21,Fen=0,aaa=0,bbb=0,xxx=0
- For /L %%i in (1,1,%ACount%) DO (
- Set /A aaa=!_%~1%%i!,bbb=aaa/^(aaa*aaa^)*10,Fen+=aaa+bbb,Shangx+=bbb
- Set /A xxx+=aaa/^(aaa*aaa^)
- )
- If %xxx% GTR 0 Set /A Fen=Fen-(xxx-1)*10
- If %Fen% LEQ %Shangx% (
- Set _Label=%~2
- If !Fen! GTR 21 Set /A Fen-=10
- ) Else (
- Set _Label=Overflow
- Set _Lose=%~2
- If !Shangx! GTR 21 Set /A Fen-=10)
- Set %~1Fen=%Fen%
- Goto :eof
-
- :Screen
- ::%1=A(B) %2=DianShu %3=HuaSe
- Set %~11=!%~11!┏━━┓
- Set %~12=!%~12!┃%~2 ┃
- Set %~13=!%~13!┃ ┃
- Set %~14=!%~14!┃ %~3┃
- Set %~15=!%~15!┗━━┛
- Goto :eof
-
- :Back
- Set %~11=!%~11!┏━━┓
- Set %~12=!%~12!┃++++┃
- Set %~13=!%~13!┃++++┃
- Set %~14=!%~14!┃++++┃
- Set %~15=!%~15!┗━━┛
- Goto :eof
-
- :Output
- CLS
- CALL :Show 5 A
- CALL :Show 9
- ECHO.%_XFen%/%Total%
- CALL :Show 5 B
- CALL :Show 2
- Goto :eof
-
- :Show
- For /L %%i in (1,1,%~1) DO ECHO.!%~2%%i!
- Goto :eof
-
- :Overflow
- If *%_Lose% == *SelectC (
- Set _Lose=闲) Else (Set _Lose=庄)
- Goto Pri
-
- :End
- If %ComputerFen% GEQ %PlayersFen% (
- Set _Lose=庄) Else (Set _Lose=闲)
- Goto Pri
- :Pri
- Set /A CountC+=Count
- For /L %%i in (1,1,5) DO Set "A%%i="
- For /L %%i in (1,1,%CountC%) DO CALL :Screen "A" "!_xComputer%%i:~0,2!" "!_xComputer%%i:~-1!"
- CALL :Output
- ECHO %_Lose%赢
- For /F "tokens=1,2" %%i in (ll.txt) DO Set /a %%i,%%j
- If *%_Lose% == *庄 (
- Set /A A+=1) Else (
- Set /A B+=1)
- ECHO A=%A% B=%B% >ll.txt
- PAUSE>nul
- ENDLOCAL
-
- Goto :Init
复制代码
作者: xiong8707 时间: 2008-12-25 22:33 标题: 高手...
小弟 佩服之至!!!!!!!!!!
作者: gbw911 时间: 2009-11-29 10:42
太长了,没奈心看了都
作者: qzwqzw 时间: 2010-1-3 12:59
可以使用ASCII字符集中0x03~0x06显示花色- @echo off
- echo.红桃
- echo.方片
- echo.草花
- echo.黑桃
复制代码
作者: anoki 时间: 2010-2-9 00:26
楼主,能写出这样的来,不简单,但小弟发现一个小小问题,自己看图吧~!
作者: caruko 时间: 2011-4-6 12:45
♤♡♧♢ ♠♥♦♣
作者: caruko 时间: 2011-4-6 21:25
本帖最后由 caruko 于 2011-4-6 21:37 编辑
测试数十次,可能还有些隐藏BUG,另外拿5张牌的没有设置特殊。- @ECHO OFF&SETLOCAL ENABLEDELAYEDEXPANSION
- set /a C=0,P=0
- set /a j=10,q=10,k=10,a=100
- set "s_hs=,,,"
- set "s_pai=A,2,3,4,5,6,7,8,9,10,J,Q,K"
- :start
- set /a 庄_张次=0,闲_张次=0,庄_牌值=0,闲_牌值=0,P_明值=0
- set "庄_牌="
- set "闲_牌="
- set "P_明="
- set "msg="
- set "msg1="
- set "牌="
- set "s_p="
- for /l %%i in (1,1,5) do set "p%%i="
- for %%i in (!s_hs!) do for %%j in (!s_pai!) do set "s_p=%%i_%%j !s_p!"
- set "标准牌=!s_p!"
- ::洗牌 【随机5-11次洗牌,可自己改】
- set /a "n=%RANDOM% %% 7 + 5"
- :洗牌次
- for %%i in (!s_p!) do (
- set /a "x=!RANDOM! %% 2"
- if !x! equ 1 (set "牌=!牌! %%i") else set "牌=%%i !牌!"
- )
- set /a n-=1
- set "s_p=!牌!"
- if !n! GTR 0 (
- set "牌="
- goto :洗牌次
- )
-
- ::主流程
- call :发牌 庄
- call :发牌 闲 P1
- call :发牌 庄
- call :发牌 闲
- :loop
- call :玩家叫牌||goto :loop
- call :判断玩家值
- call :估计玩家值 !庄_牌值!
- :break
- ::计分重来
- if !庄_牌值! gEQ !闲_牌值! (
- set msg1=!庄_牌值!:!闲_牌值!,庄家获胜!
- set /a C+=1
- ) else (
- set msg1=!庄_牌值!:!闲_牌值!,闲家获胜!
- set /a P+=1
- )
- call :显示 2
- pause
- goto :start
-
-
- :爆
- set msg=%1家爆牌,点数!%1!。
- if "%1"=="庄" (
- set msg1=闲家获胜!
- set /a P+=1
- ) else (
- set msg1=庄家获胜!
- set /a C+=1
- )
- call :显示 3
- pause
- goto :start
-
- :end
- echo,按任意键退出!
- pause>nul
- exit
-
- :显示
- cls
- if "%*"=="" (
- setlocal
- for /l %%i in (1,1,!庄_张次!) do (set "p1=!p1!┏━━┓ "&set "p5=!p5!┗━━┛ ")
- for /f "tokens=2 delims=_ " %%i in ("!庄_牌!") do if "%%i"=="10" (set "p2=┃%%i ┃ ") else set "p2=┃%%i ┃ "
- for /l %%i in (2,1,!庄_张次!) do set "p2=!p2!┃++++┃ "
- set "p3=┃ ┃ "
- for /l %%i in (2,1,!庄_张次!) do set "p3=!p3!┃++++┃ "
- for /f "tokens=1 delims=_ " %%i in ("!庄_牌!") do set "p4=┃ %%i┃ "
- for /l %%i in (2,1,!庄_张次!) do set "p4=!p4!┃++++┃ "
- for /l %%i in (1,1,5) do echo !p%%i!
- endlocal
- ) else (
- setlocal
- for /l %%i in (1,1,!庄_张次!) do (set "p1=!p1!┏━━┓ "&set "p5=!p5!┗━━┛ ")
- for %%i in (!庄_牌!) do for /f "tokens=2 delims=_" %%j in ("%%i") do if "%%j"=="10" (set "p2=!p2!┃%%j ┃ ") else set "p2=!p2!┃%%j ┃ "
- for /l %%i in (1,1,!庄_张次!) do set "p3=!p3!┃ ┃ "
- for %%i in (!庄_牌!) do for /f "tokens=1 delims=_" %%j in ("%%i") do set "p4=!p4!┃ %%j┃ "
- for /l %%i in (1,1,5) do echo !p%%i!
- endlocal
- )
- echo,&echo,!msg!&echo,&echo,!msg1!&echo,对局: 庄[!C!] / 闲[!P!]
- setlocal
- for /l %%i in (1,1,!闲_张次!) do (set "p1=!p1!┏━━┓ "&set "p5=!p5!┗━━┛ ")
- for %%i in (!闲_牌!) do for /f "tokens=2 delims=_" %%j in ("%%i") do if "%%j"=="10" (set "p2=!p2!┃%%j ┃ ") else set "p2=!p2!┃%%j ┃ "
- for /l %%i in (1,1,!闲_张次!) do set "p3=!p3!┃ ┃ "
- for %%i in (!闲_牌!) do for /f "tokens=1 delims=_" %%j in ("%%i") do set "p4=!p4!┃ %%j┃ "
- for /l %%i in (1,1,5) do echo !p%%i!
- endlocal
- goto :eof
-
-
- :玩家叫牌
- choice /c HSE /n /m "拿牌(Hit:H) 停牌(Stand:S) 退出(Exit:E):"
- if !ERRORLEVEL! equ 0 exit /b 1
- if !ERRORLEVEL! equ 255 exit /b 1
- if !ERRORLEVEL! equ 2 exit /b 0
- if !ERRORLEVEL! equ 3 goto :end
- call :发牌 闲 ||exit /b 0
- exit /b 1
- goto :eof
-
-
- :发牌 [庄/闲]
- if !%1_张次! geq 5 (
- set msg=最多只能拿5张牌!
- call :显示
- exit /b 1
- )
- set "msg=%1家拿牌!"
- for /f "tokens=1*" %%i in ("!牌!") do (
- set "当前牌=%%i"
- set "牌=%%j"
- )
- set "%1_牌=!%1_牌! !当前牌!"
- set /a %1_张次+=1
- if "%2"=="P1" (
- set "P_明=!当前牌!"
- for /f "tokens=2 delims=_" %%j in ("!当前牌!") do set /a "P_明值=%%j"
- )
-
- for /f "tokens=2 delims=_" %%j in ("!当前牌!") do set /a "%1_牌值=!%1_牌值! + %%j"
- call :显示
- goto :eof
-
-
- :判断玩家值
- if !闲_牌值! gtr 100 (
- set /a tpp=!闲_牌值! %% 100 + 11
- if !tpp! gtr 21 (set /a 闲_牌值=!闲_牌值! %% 100 + 1) else set /a 闲_牌值=tpp
- if !闲_牌值! gtr 21 call :爆 闲
- ) else (
- if !闲_牌值! gtr 21 call :爆 闲
- )
- goto :eof
-
- :估计玩家值 【电脑估计玩家牌值,因为统计学没学好,并且计算量也非常大,就采用初略估计值,否着计算各种值的可能性几分钟绝对算不完。】
- if !P_明值! geq 100 (
- if !P_次数! equ 2 set /a P_明值=17
- if !P_次数! equ 3 set /a P_明值=16
- if !P_次数! equ 4 set /a P_明值=16
- if !P_次数! equ 5 set /a P_明值=18
- ) else (
- if !P_次数! equ 2 set /a P_明值=14
- if !P_次数! equ 3 set /a P_明值=17
- if !P_次数! equ 4 set /a P_明值=16
- if !P_次数! equ 5 set /a P_明值=18
- )
- :判断电脑点数
- for %%i in (!庄_牌!) do set "标准牌=!标准牌:%%i=!"
- for %%i in (!P_明!) do set "标准牌=!标准牌:%%i=!"
- if !庄_牌值! GEQ 100 (
- set /a 庄_牌值=%1 %% 100 + 11
- if !庄_牌值! GTR 21 set /a 庄_牌值=%1 %% 100 + 1
- if !庄_牌值! GEQ 17 if !庄_牌值! lss 22 goto :break
- call :判断叫牌 !庄_牌值! || (
- set /a 庄_牌值=%1 %% 100 + 1
- if !庄_牌值! GTR 21 call :爆 庄
- if !庄_牌值! GEQ 17 goto :break
- call :判断叫牌 !庄_牌值!
- )
- ) else (
- if !庄_牌值! GTR 21 call :爆 庄
- if !庄_牌值! GEQ 17 goto :break
- call :判断叫牌 !庄_牌值!
- )
- goto :eof
-
- :判断叫牌 【分析是否叫牌】
- set /a jl=0,ct=0,n=0
- for %%i in (!标准牌!) do (
- for /f "tokens=2 delims=_" %%j in ("%%i") do (
- set /a num=%%j+%1,n+=1
- if !num! lss 22 set /a jl+=1
- if !num! lss !P_明值! set /a jl+=1
- )
- )
- set /a jl=jl*100/n
- if !jl! gtr 55 (
- set "msg=庄家叫牌!"
- call :发牌 庄 || exit /b 0
- call :判断电脑点数 !庄_牌值!
- exit /b 0
- )
- exit /b 1
复制代码
作者: caruko 时间: 2011-4-6 21:29
好奇怪,复制代码得到的是LZ的牌。
set s_hs 显示空的,实际是6楼提供的ACSII码。
作者: mikeer 时间: 2011-4-26 21:33
呵呵,我玩这个游戏
开始还行
后来就不行了
作者: sds 时间: 2023-2-3 20:37
回复 6# qzwqzw 大王和小王:
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |