Advertisement
T3RRYT3RR0R

Batch Mastermind Game

Jun 19th, 2020
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.19 KB | None | 0 0
  1. @Echo off & TITLE Mastermind [1-8] [Q]uit
  2.     (Set \n=^^^
  3. %= Newline Var - Do not modify =%
  4. )
  5. ::: { Creates variable /AE = Ascii-27 escape code.
  6. ::: - http://www.dostips.com/forum/viewtopic.php?t=1733
  7. ::: - https://stackoverflow.com/a/34923514/12343998
  8. ::: - /AE can be used  with and without DelayedExpansion.
  9.     Setlocal
  10.     For /F "tokens=2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  11.         Endlocal
  12.         Set "/AE=%%a"
  13.     )
  14. ::: }
  15.     Set Mastermind=For %%n in (1 2) Do If %%n==2 (%\n%
  16.     For /F "Tokens=1,2,3,4 Delims={}" %%G in ("!INPUT!") Do (%\n%
  17.     ^<Nul Set /P "=Guess %%J: "%\n%
  18.     Set "Guess#=%%J"%\n%
  19.         Set "%%G="%\n%
  20.         For /L %%# in (1 1 %%I) Do (%\n%
  21.             For /F "Delims=" %%C In ('Choice /N /C:%%H') Do (%\n%
  22.         If /I "%%C" == "Q" Exit /B 0%\n%
  23.                 ^<Nul Set /P "=!C#[%%C]!%%C%/AE%[0m"%\n%
  24.                 Set "%%G=!%%G!%%C"%\n%
  25.             )%\n%
  26.         )%\n%
  27.     Set "Guess=!%%G!"%\n%
  28.     )%\n%
  29.     Set /A EXmatch=0,PAmatch=0%\n%
  30.         For /L %%c in (0 1 4) Do (%\n%
  31.         For /L %%d in (0 1 4) Do If Not %%c==%%d If Not "!Code:~%%d,1!" == "!Guess:~%%d,1!" If Not "!Code:~%%c,1!" == "!Guess:~%%c,1!" (If "!Code:~%%d,1!" == "!Guess:~%%c,1!" Set /A PAmatch+=1)%\n%
  32.         If "!Code:~%%c,1!" == "!Guess:~%%c,1!" (Set /A EXmatch+=1)%\n%
  33.     )%\n%
  34.     Set "GuessMatch=_____"%\n%
  35.     For /L %%e in (1 1 !EXmatch!) Do Set "GuessMatch=X!GuessMatch:~,-1!"%\n%
  36.     For /L %%f in (1 1 !PAmatch!) Do Set "GuessMatch=O!GuessMatch:~,-1!"%\n%
  37.     ^<Nul Set /P "=. !GuessMatch!"%\n%
  38.     Echo/%\n%
  39.     IF /I "!GuessMatch!" == "XXXXX" (Echo/you won ^& Pause ^& Goto :Game)%\n%
  40.     If "!Guess#!" == "12" (Echo/you lost ^& Echo/Code was: !Code! ^& Pause ^& Endlocal ^& Goto :Game)%\n%
  41. ) Else Set INPUT=
  42. ::: [End Macro Definition]
  43. :Game
  44.     CLS & Setlocal EnableDelayedExpansion
  45.     Set /A Red=31,Yellow=33,Green=32,Blue=34,Gray=90,Pink=91,Magenta=95,Cyan=36,CI#=0
  46.     For %%A in (Red,Yellow,Green,Blue,Pink,Gray,Magenta,Cyan) do (
  47.         Set "%%A=%/AE%[!%%A!m"
  48.         Set /A "CI#+=1"
  49.         Set "C#[!CI#!]=!%%A!"
  50.     )
  51.     Set Code=
  52.     For /L %%# in (1 1 5) Do (
  53.         Set /A RND=!Random! %% 8 + 1
  54.         Set "Code=!Code!!RND!"
  55.     )
  56.     For /L %%# In (1 1 12) Do %Mastermind%{Guess[%%#]}{12345678q}{5}{%%#}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement