本帖最后由 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
复制代码
|