Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off & TITLE Mastermind [1-8] [Q]uit
- (Set \n=^^^
- %= Newline Var - Do not modify =%
- )
- ::: { Creates variable /AE = Ascii-27 escape code.
- ::: - http://www.dostips.com/forum/viewtopic.php?t=1733
- ::: - https://stackoverflow.com/a/34923514/12343998
- ::: - /AE can be used with and without DelayedExpansion.
- Setlocal
- For /F "tokens=2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
- Endlocal
- Set "/AE=%%a"
- )
- ::: }
- Set Mastermind=For %%n in (1 2) Do If %%n==2 (%\n%
- For /F "Tokens=1,2,3,4 Delims={}" %%G in ("!INPUT!") Do (%\n%
- ^<Nul Set /P "=Guess %%J: "%\n%
- Set "Guess#=%%J"%\n%
- Set "%%G="%\n%
- For /L %%# in (1 1 %%I) Do (%\n%
- For /F "Delims=" %%C In ('Choice /N /C:%%H') Do (%\n%
- If /I "%%C" == "Q" Exit /B 0%\n%
- ^<Nul Set /P "=!C#[%%C]!%%C%/AE%[0m"%\n%
- Set "%%G=!%%G!%%C"%\n%
- )%\n%
- )%\n%
- Set "Guess=!%%G!"%\n%
- )%\n%
- Set /A EXmatch=0,PAmatch=0%\n%
- For /L %%c in (0 1 4) Do (%\n%
- 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%
- If "!Code:~%%c,1!" == "!Guess:~%%c,1!" (Set /A EXmatch+=1)%\n%
- )%\n%
- Set "GuessMatch=_____"%\n%
- For /L %%e in (1 1 !EXmatch!) Do Set "GuessMatch=X!GuessMatch:~,-1!"%\n%
- For /L %%f in (1 1 !PAmatch!) Do Set "GuessMatch=O!GuessMatch:~,-1!"%\n%
- ^<Nul Set /P "=. !GuessMatch!"%\n%
- Echo/%\n%
- IF /I "!GuessMatch!" == "XXXXX" (Echo/you won ^& Pause ^& Goto :Game)%\n%
- If "!Guess#!" == "12" (Echo/you lost ^& Echo/Code was: !Code! ^& Pause ^& Endlocal ^& Goto :Game)%\n%
- ) Else Set INPUT=
- ::: [End Macro Definition]
- :Game
- CLS & Setlocal EnableDelayedExpansion
- Set /A Red=31,Yellow=33,Green=32,Blue=34,Gray=90,Pink=91,Magenta=95,Cyan=36,CI#=0
- For %%A in (Red,Yellow,Green,Blue,Pink,Gray,Magenta,Cyan) do (
- Set "%%A=%/AE%[!%%A!m"
- Set /A "CI#+=1"
- Set "C#[!CI#!]=!%%A!"
- )
- Set Code=
- For /L %%# in (1 1 5) Do (
- Set /A RND=!Random! %% 8 + 1
- Set "Code=!Code!!RND!"
- )
- For /L %%# In (1 1 12) Do %Mastermind%{Guess[%%#]}{12345678q}{5}{%%#}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement