本帖最后由 caruko 于 2011-6-4 01:59 编辑
=.=
斗地主----半成品吧。
出牌法: 假如要出 JJJ35 ,就输入JJJ35 ,出10 的话输入 1 ,大王为S,小王为M。 字符间有无空格不影响。
输入E 退出,输入P,PASS。
当测试中提示牌值小无法出牌时,可先输入P,再开始新一轮。
完善了规则函数比较大小功能。
欢迎测试BUG。- @ECHO OFF&SETLOCAL ENABLEDELAYEDEXPANSION
- mode con cols=100 lines=40
- call :load
- call :洗牌
- call :发牌
- for %%i in (1 2 3) do (
- call :排序 "!Player_%%i_牌!"
- set "Player_%%i_牌=!ecode!"
- )
- call :显示
- :loop
- call :出牌 Player_1_牌 !上手牌! ||goto :loop
- call :显示
- if !input!.==E. goto :eof
- goto :loop
- goto :eof
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ::加载资源,初始数据。
- :load
- set "资源_花色=,,,"
- set "资源_牌值=A,2,3,4,5,6,7,8,9,10,J,Q,K"
- set "资源_新牌="
- set /a _1=10,_2=15,_A=14,_J=11,_Q=12,_K=13,_3=3,_4=4,_5=5,_6=6,_7=7,_8=8,_9=9,_10=10,_S=17,_M=16
- for %%i in (!资源_牌值!) do for %%j in (!资源_花色!) do (
- set "资源_新牌=!资源_新牌! %%i_%%j"
- )
- set "资源_新牌=%资源_新牌% S_U M_O"
- set "上手牌=无"
- goto :eof
-
-
- :洗牌
- set "待发_牌=!资源_新牌!"
- set "temp="
- set /a "n=!RANDOM:~-1! + 8"
- for /l %%i in (1 1 %n%) do (
- for %%j in (!待发_牌!) do (
- set/a flag=!RANDOM!%%2
- if !flag! equ 1 (set "temp=!temp! %%j") else set "temp=%%j !temp!"
- )
- set "待发_牌=!temp!"
- set "temp="
- )
- goto :eof
-
- :发牌 目前只管3人。
- set /a n=0
- set "Player_1_牌="
- set "Player_2_牌="
- set "Player_3_牌="
- for %%i in (!待发_牌!) do (
- set /a n+=1
- if !n! lss 52 (
- set /a flag=n %% 3
- if !flag! equ 0 (
- set "Player_1_牌=!Player_1_牌! %%i"
- set 待发_牌=!待发_牌:%%i=!
- )
- if !flag! equ 1 (
- set "Player_2_牌=!Player_2_牌! %%i"
- set 待发_牌=!待发_牌:%%i=!
- )
- if !flag! equ 2 (
- set "Player_3_牌=!Player_3_牌! %%i"
- set 待发_牌=!待发_牌:%%i=!
- )
- )
- )
- set "底牌=!待发_牌!"
- goto :eof
-
-
- :排序 [var] 给牌排序,返回ecode
- set "ecode="
- for %%i in (S M 2 A K Q J 1 9 8 7 6 5 4 3) do (
- for %%j in (%~1) do (
- set "temp=%%j"
- if "%%i"=="!temp:~0,1!" set ecode=!ecode! %%j
- )
- )
- goto :eof
-
-
- :显示 暂时只显示player1的牌.
- cls&set /a n=0
- setlocal
- for %%i in (!player_1_牌!) do (
- set /a n+=1
- if !n! lss 11 (
- set "p1=!p1!┏━━┓"
- set "p5=!p5!┗━━┛"
- set "p3=!p3!┃ ┃"
- for /f "tokens=1,2 delims=_" %%a in ("%%i") do (
- set "p2=!p2!┃%%a ┃"
- set "p4=!p4!┃ %%b┃"
- )
- ) else (
- set "p6=!p6!┏━━┓"
- set "p10=!p10!┗━━┛"
- set "p8=!p8!┃ ┃"
- for /f "tokens=1,2 delims=_" %%a in ("%%i") do (
- set "p7=!p7!┃%%a ┃"
- set "p9=!p9!┃ %%b┃"
- )
- )
- )
-
- for /l %%i in (-20,1,10) do (
- echo,!p%%i:10 =10!
- )
- endlocal
- goto :eof
-
-
- :出牌 [Player_n] [上手牌值] 假如要出 JJJ35 ,就输入:J J J 3 5
- set "出牌="
- set /p input=请出牌:
- echo,!input!|findstr "[^1-9JQKEP ]" >nul && (title 输入字符不合要求!&exit /b -1)
- if !input!.==E. (title 退出!&exit /b 0)
- if !input!.==P. (title PASS!&set 上手牌=无&exit /b 0)
- set "input=!input: =!"&set "temp="
- for /l %%i in (0,1,19) do set "temp=!temp! !input:~%%i,1!"
- set "input=!temp!"
- call :规则 "!input!" "%~2" || exit /b -2
- setlocal
- for %%i in (!input!) do (
- set "flag=flase"
- for %%j in (!%1!) do (
- set "temp=%%j"
- if "!flag!"=="flase" (
- if "%%i"=="!temp:~0,1!" (
- set "出牌=!出牌! %%j"
- set "%1=!%1:%%j=!"
- set "flag=true"
- )
- )
- )
- if "!flag!"=="flase" (
- endlocal
- title 您要出的一些牌不存在!
- exit /b -3
- )
- )
- set temp=!%1!
- endlocal&set %1=%temp%&set 出牌=%出牌%
- if not "!出牌!"=="" set 上手牌=!ecode!
- exit /b 0
-
-
- :规则 [此手牌] [上手牌值] 检测出牌是否符合规则
- setlocal
- set "v="
- set "temp1=%~1"
- rem set "temp2=%~2"
- set "temp=!temp1: =!"
- if "!temp!"=="SM" set "v=王炸"
- if "!temp!"=="MS" set "v=王炸"
- if not %v%.==. (
- endlocal
- set ecode=%v%
- exit /b 0
- )
- set /a n=0
- set "str=34567891JQKA"
- set "str1=3344556677889911JJQQKKAA"
- set "str2=333444555666777888999111JJJQQQKKKAAA"
- for %%B in (!temp1!) do set /a n+=1
- for /f "tokens=1-20" %%a in ("!temp1!") do (
- rem 单张 1
- if "%%b"=="" (
- set v=单张_!_%%a!_1
- )
- rem 一对 2
- if "%%a"=="%%b" if "%%c"=="" (
- set v=对子_!_%%a!_1
- )
- rem 三张 3
- if "%%a"=="%%b" if "%%a"=="%%c" if %%d.==. (
- set v=三张_!_%%a!_1
- )
- rem 三带一 4
- if "%%a"=="%%b" if "%%a"=="%%c" if not %%d.==. if %%e.==. (
- set v=三带一_!_%%a!_1
- )
- rem 三带对 5
- if "%%a"=="%%b" if "%%a"=="%%c" if %%d.==%%e. if %%f.==. (
- set v=三带对_!_%%a!_1
- )
- rem 顺子 6
- for %%A in (!temp!) do (
- if not "!str:%%A=!"=="!str!" (
- if !n! GEQ 5 set v=顺子_%%a_!n!
- )
- )
- rem 连对 7
- set /a flag=n %% 2
- if !flag! equ 0 (
- for %%A in (!temp!) do (
- if not "!str1:%%A=!"=="!str1!" (
- set /a flag=n / 2
- if !flag! GEQ 3 set v=连对_!_%%a!_!flag!
- )
- )
- )
- rem 三张顺子 8
- set /a flag= n %% 3
- if !flag! equ 0 (
- for %%A in (!temp!) do (
- if not "!str2:%%A=!"=="!str2!" (
- set /a flag=n / 3
- if !flag! GEQ 2 set v=三张顺子_!_%%a!_!flag!
- )
- )
- )
- rem 炸弹 9
- if %%a.==%%b. if %%a.==%%c. if %%a.==%%d. if %%e.==. (
- set v=炸弹_!_%%a!_1
- )
- rem 飞机 10
- set /a flag=n %% 4,flag2=n/4,t=0
- if !flag! equ 0 if !flag2! GEQ 2 (
- set /a flag=n / 4 * 3
- for %%A in (!flag!) do (
- set "tstr=!temp:~0,%%A!"
- set "tstr2=!temp:~%%A!"
- for /f "tokens=1,2" %%B in ("!tstr! !tstr2!") do (
- if not "!str2:%%B=!"=="!str2!" set t=三连
- if "!str2:%%C=!"=="!str2!" set t=!t!飞机
- )
- )
- if "!t!"=="三连飞机" (
- set v=飞机_!_%%a!_!flag2!
- )
- )
- rem 三张带对顺 11
- set /a flag=n %% 5,flag2=n / 5,t=0
- if !flag! equ 0 if !flag2! GEQ 2 (
- set /a flag=n / 5 * 3
- for %%A in (!flag!) do (
- set "tstr=!temp:~0,%%A!"
- set "tstr2=!temp:~%%A!"
- for %%B in (!tstr!) do if not "!str2:%%B=!"=="!str2!" set t=三连
- )
- if "!t!"=="三连" (
- set /a flag=n-flag-1
- for /l %%A in (0 2 !flag!) do set fstr1=!fstr1!!tstr2:~%%A,1!
- for /l %%A in (1 2 !flag!) do set fstr2=!fstr2!!tstr2:~%%A,1!
- if "!fstr1!"=="!fstr2!" set "t=!t!对子"
- )
- if "!t!"=="三连对子" (
- set v=三张带一对顺子_!_%%a!_!flag2!
- )
- )
- rem 四带二 12
- if %%a.==%%b. if %%a.==%%c. if %%a.==%%d. if not %%e.==. (
- if %%e.==%%f. if %%g.==%%h. if %%i.==. set v=四带对_%%a_1
- if not %%e.==%%f. if %%g.==. if not %%f.==. set v=四带二_%%a_1
- )
- )
- if %v%.==. (
- endlocal
- title 出牌不符合规则!
- exit /b -1
- ) else (
- if "%~2"=="无" (
- endlocal
- set ecode=%v%
- exit /b 0
- )
- for /f "tokens=1-3 delims=_" %%a in ("!v!") do (
- set "#a=%%a"
- set /a #b=%%b,#c=%%c,k=0
- )
- for /f "tokens=1-3 delims=_" %%a in ("%~2") do (
- set "$a=%%a"
- set /a $b=%%b,$c=%%c
- )
- if !#a!.==王炸. (
- endlocal
- set ecode=%v%
- exit /b 0
- )
- if !#a!.==炸弹. if not !$a!.==炸弹. (
- endlocal
- set ecode=%v%
- exit /b 0
- )
- if !#a!.==!$a!. (
- if !#c!.==!$c!. if !#b! GTR !$b! (
- endlocal
- set ecode=%v%
- exit /b 0
- )
- )
- endlocal
- title 与上家牌型不同,或者牌值小,无法出牌!
- exit /b -2
- )
复制代码
|