ShadowThief wrote:Add the line
right before the
and everything works
But somehow, the final product does not work as expected.
If somebody has a different way of doing this, let me know. For now, here is the non-working code. I'll try to figure out the problem myself, but any help I have would be greatly appreciated.
Code: Select all
@echo off
setlocal enabledelayedexpansion
for /l %%g in (0,1,15) do set board[%%g]=0
call :tilespawn
call :tilespawn
:startloop
cls
echo !board[0]! !board[1]! !board[2]! !board[3]!
echo !board[4]! !board[5]! !board[6]! !board[7]!
echo !board[8]! !board[9]! !board[10]! !board[11]!
echo !board[12]! !board[13]! !board[14]! !board[15]!
choice /c wasdx /n /m ""
if %errorlevel%==1 rem UP
if %errorlevel%==2 rem LEFT
if %errorlevel%==3 goto movedown
if %errorlevel%==4 rem RIGHT
:backtoloop
if %errorlevel%==5 exit /b
goto startloop
exit /b
:tilespawn
set /a randtile=%random%%%16
if !board[%randtile%]! gtr 0 goto tilespawn
set /a board[%randtile%]=%random%%%10/9*2+2
exit /b
:movedown
set a=3
set j=0
set h=-1
set k=12
set i=0
set g=-4
:movetile
set /a d=0
set /a c=%k%
set /a b=%c%
:1
set /a l=%a%+%b%
set e=-1
if !board[%l%]! neq 0 (
set /a e=!board[%l%]!
set /a board[%l%]=0
if %e% equ %d% (
set /a board[%l%-%g%]*=2
set /a d=!board[%l%-%g%]!
) else (
set /a c+=%g%
set /a board[%a%+%c%+4]=%e%-%d%
set /a d=%e%
)
)
set /a b+=%g%
set /a o=%b%+%g%
if %i% neq %o% goto 1
set /a a+=%h%
set /a p=%a%+%h%
if %j% neq %p% goto movetile
goto backtoloop
Sample starting configuration (determined randomly):
0 2 0 0
0 0 0 0
0 0 0 4
0 0 0 0
Expected output:
0 0 0 0
0 0 0 0
0 0 0 0
0 2 0 4
Sample starting configuration:
0 0 2 0
0 0 0 0
0 0 0 0
0 0 2 0
Expected output:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 4 0
You should know what this is code for by now.
EDIT: I have found out the problem is that the IF blocks did not work as expected. When I go through them, the value of e never changes, despite there being a change to e right after the if is entered. Help?