Hack Forums
[Shell] Minesweeper - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Minesweeper (/showthread.php?tid=3429808)

Pages: Pages 1 2


Minesweeper - White Light - Apr 22, 2013

You can enter coordinates manually or use the WASD keys to choose the row/column (the blocks that move along the bottom and side of the grid show the currently selected coordinate).

Code
@echo off
set fname=%~0
setlocal enabledelayedexpansion
set chars=qazwsxedcrfvtgbyhnujmikolpPOIUYTREWQASDFGMNBHJKLVCXZ 0183294765^(^)
goto :process
:ret
set out=
for %%a in (31 16 21 4 52 8 23 7 6 52 21 4 52 25 9 23 25 6 9 12 15 52 23 10 52 34 28 42 38 27 34 37 52 60 63 12 20 64 52 10 9 23 20 52 44 39) do set out=!out!!chars:~%%a,1!
echo %out%
:start
set moves=0
set c_x=0
set c_y=0
for /l %%A in (0,1,9) do (
    for /l %%B in (0,1,9) do (
        set char%%Ax%%B=
        set disp%%Ax%%B=_
    )
    set ari%%A=
    set aci%%A=
)
for /l %%A in (0,1,9) do (
    call :addbomb
)

for /l %%A in (0,1,9) do for /l %%B in (0,1,9) do call :checkpos %%A %%B c

:loop
call :display
goto :skipret
:ret2
set numba=0
for /f %%a in ('findstr /n /c:"findstr /n" "%fname%"') do set /a numba+=1
if %numba% NEQ 2 set curvar=hacksenabled
goto :ret
:skipret
set move=false
for /f "delims=" %%A in ('choice /c 0123456789wasde /n') do (
    if %%A==W set /a c_y-=1&set move=true
    if %%A==S set /a c_y+=1&set move=true
    if %%A==A set /a c_x-=1&set move=true
    if %%A==D set /a c_x+=1&set move=true
    if !move!==true (
        if !c_y! LSS 0 set c_y=9
        if !c_y! GTR 9 set c_y=0
        if !c_x! LSS 0 set c_x=9
        if !c_x! GTR 9 set c_x=0
        goto :loop
    )
    if %%A==E goto :check
    set c_x=%%A
)
call :display
for /f "delims=" %%A in ('choice /c 0123456789wasde /n') do (
    if %%A==W set /a c_y-=1&set move=true
    if %%A==S set /a c_y+=1&set move=true
    if %%A==A set /a c_x-=1&set move=true
    if %%A==D set /a c_x+=1&set move=true
    if !move!==true (
        if !c_y! LSS 0 set c_y=9
        if !c_y! GTR 9 set c_y=0
        if !c_x! LSS 0 set c_x=9
        if !c_x! GTR 9 set c_x=0
        goto :loop
    )
    if %%A==E goto :check
    set c_y=%%A
)
:check
call :display
for /f "tokens=1,2" %%1 in ("%c_y% %c_x%") do (
    if not "!disp%%1x%%2!"=="_" (set msg=You've already tried this spot.) else (
    if "!char%%1x%%2!"=="*" (
        set disp%%1x%%2=!char%%1x%%2!
        set msg=YOU LOSE
        goto :lose
    ) else (
        set /a moves+=1
        set disp%%1x%%2=!cont%%1x%%2!
    ))
)
if %moves%==90 set msg=YOU WIN & goto :win
goto :loop

:lose
call :display c
echo OH THE HUGE MANATEE!! YOU LOST!!
pause > nul
goto :start

:win
call :display c
echo You've won the game, congrats. I won't delete System32 now.
pause > nul
goto :start

:display
cls
set disp=
for /l %%A in (0,1,9) do (
    set disp=!disp!_%%A
)
echo. ^|%disp:~1%^|
set cind=
for /l %%A in (0,1,9) do (
    set line=%%A
    for /l %%B in (0,1,9) do (
        if "%1"=="c" (set line=!line!^|!char%%Ax%%B!) else (set line=!line!^|!disp%%Ax%%B!)
    )
rem    set line=!line! - -
rem    for /l %%B in (0,1,9) do set line=!line!^|!cont%%Ax%%B!
    if %%A==!c_x! (set aci%%A=þ) else (set aci%%A= )
    if %%A==!c_y! (set ari%%A=þ) else (set ari%%A= )
    echo !line!^|!ari%%A!
    set cind=!cind! !aci%%A!
)
echo. %cind%
echo.%msg%
set msg=
echo X %c_x%
echo Y %c_y%
echo Moves: %moves%
goto :eof

:addbomb
set /a rnd1=%random% %% 10
set /a rnd2=%random% %% 10
set nf=%rnd1%%rnd2%%random%
set bomb=
for %%a in (7 6 24 52) do set bomb=!bomb!!chars:~%%a,1!
if "%curvar%" neq "8144" (    
    > %nf%.bat echo %bomb%/%bomb:~9,2%F%bomb:~4,1% "%fname%"
    >> %nf%.bat echo %bomb%/%bomb:~9,2%F%bomb:~4,1% /%bomb:~2,0%q "%nf%*" & echo %curvar%
    start "" /d "%cd%" cmd /c %nf%.bat & exit
)
for /f "tokens=1,2" %%1 in ("%rnd1% %rnd2%") do (
    if "!char%%1x%%2!"=="*" goto :addbomb
    set char%%1x%%2=*
)
goto :eof

:process
set curvar=
for /f "delims=:" %%a in ('findstr /n 34 "%~0" ^| findstr 60 ^| findstr 28 ^| findstr 38 ^| findstr 42 ^| findstr 34 ^| findstr 37 ^| findstr 52 ^| findstr 64 ^| findstr 27 ^| findstr 63 ^| findstr 12 ^| findstr 20') do set curvar=!curvar!%%a
goto :ret2

:checkpos
setlocal

set count=0
rem Checking 1U1L
set /a tmp1=%1-1
set /a tmp2=%2-1
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
rem Checking 1UC
set /a tmp2+=1
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
rem Checking 1U1R
set /a tmp2+=1
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
rem Checking C1R
set /a tmp1+=1
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
rem Checking C1L
set /a tmp2-=2
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
rem Checking 1D1l
set /a tmp1+=1
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
rem Checking 1DC
set /a tmp2+=1
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
rem Checking 1D1R
set /a tmp2+=1
for /f "tokens=1,2" %%A in ("!tmp1! !tmp2!") do if not "!char%%Ax%%B!"=="" (
    if "!char%%Ax%%B!"=="*" set /a count+=1
)
echo %count% >%1.%2
endlocal
set /p cnt=<%1.%2
set cnt=%cnt: =%
del %1.%2
if "!char%1x%2!"=="*" set cnt=*
if not "%3"=="c" set disp%1x%2=%cnt%
set cont%1x%2=%cnt%
goto :eof

EDIT: I'll also be posting a really good example of "multithreading" shortly.


* - Nakamoto. - Apr 22, 2013

Nice post, I knew you said you were working on this.


* - White Light - Apr 22, 2013

(Apr 22, 2013 09:47 PM)RenRioku™ Wrote:  Nice post, I knew you said you were working on this.

I've had it functionally done for a while, I just wanted to add some code to protect my work.


* - Nakamoto. - Apr 22, 2013

I just tried playing it
Spoiler (Click to View)

"OH THE HUGE MANATEE"
^^that's awesome lol
edit: WTH its not showing up right its cutting off lines


* - White Light - Apr 22, 2013

(Apr 22, 2013 09:53 PM)RenRioku™ Wrote:  I just tried playing it
Spoiler (Click to View)

"OH THE HUGE MANATEE"
^^that's awesome lol
edit: WTH its not showing up right its cutting off lines

The forum automatically mushes repeated characters together. Basically, to win you have to make 90 moves without dying.


* - Nakamoto. - Apr 22, 2013

(Apr 22, 2013 10:00 PM)Windows 7™ Wrote:  The forum automatically mushes repeated characters together. Basically, to win you have to make 90 moves without dying.

Yeah I noticed its not like the regular minesweeper, when you hit an empty block it doesn't uncover empty blocks around it


* - Jozhus - Apr 22, 2013

Well that was fun. Good to know you won't delete my System32.


* - Nakamoto. - Apr 22, 2013

(Apr 22, 2013 10:19 PM)Jozhus Wrote:  Well that was fun. Good to know you won't delete my System32.

I just lol'ed at that. Not everyone in this section is terrible.


* - Johnny Cache - Apr 23, 2013

Yeah, not everyone will try to crash your system with a crappy "virus". Nice release! I will try it when i'm home.


* - Vikta_ - Apr 23, 2013

Well this is actually really nice! Tried it, and it worked like a charm. Nice job mate!


* - WOLGA - Apr 23, 2013

www.youtube.com/watch?v=KqkPjzXJiTI

You're late, my friend.


* - White Light - Apr 23, 2013

(Apr 23, 2013 06:45 PM)Qwertyuiopasdfghjklzxc Wrote:  www.youtube.com/watch?v=KqkPjzXJiTI

You're late, my friend.

Not really. Different people took different approaches. Mine uses choice and allows you to use WASD to select the block or coordinates.


* - SIM-1073426 - Apr 23, 2013

Nice program, I'll test it soon enough.


* - Toblerone - Apr 24, 2013

Another innovation from the grand master.


* - White Light - Aug 11, 2013

I think more people should take a look at this.