This site requires JavaScript, please enable it in your browser!
Greenfoot back
EvanRoscTheDev
EvanRoscTheDev wrote ...

2020/4/22

Maze generator not working properly.

EvanRoscTheDev EvanRoscTheDev

2020/4/22

#
I have been having trouble with this code and I haven't found the problem with the code. The maze generator just quits spawning in the wall objects after the first two, and I have already fixed multiple problems with the code. can anybody find a solution to this code?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class MyWorld extends World
{
    Actor[][] wallBoard;
    int rand;
    int x;
    int y;
    int z = 0;
    boolean i = true;
    boolean i1 = true;
    boolean i2 = true;
    boolean i3 = true;
    boolean i4 = true;
    
    public MyWorld()
    {
        super(1280, 720, 1, true);
        setup();
    }
    
    public void setup()
    {
        wallBoard = new Actor[(getWidth() / 10) + 1][(getHeight() / 10) + 1];
        x = Greenfoot.getRandomNumber(getWidth() / 10);
        y = Greenfoot.getRandomNumber(getHeight() / 10);
        rand = Greenfoot.getRandomNumber(3);
        do
        {
            if (null == wallBoard[x][y])
            {
                wallBoard[x][y] = new wall();
                addObject(wallBoard[x][y], (x * 10) + 5, (y * 10) + 5);
            }
            switch (rand)
            {
                case 0:
                    x--;
                    if (x < 0)
                    {
                        x = getWidth() / 10;
                    }
                    i2 = (
                            null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                                [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                                [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)]
                        );
                    i3 = (
                            null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                                [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                                [(y - 1 <= -1) ? ((getHeight() / 10) + (y - 1)) : (y - 1)]
                        );
                    i4 = (
                            null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                                [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                                [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)]
                        );
                    if (i3 && i2 && i4)
                    {
                        rand = 1;
                    }
                    else if (i3 && i4)
                    {
                        rand = 3;
                    }
                    else if (i3 && i2)
                    {
                        rand = 2;
                    }
                    else if (i2 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 2;
                    }
                    else if (i4 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 3;
                    }
                    else if (i3)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 3;
                                break;
                            case 0:
                                rand = 2;
                                break;
                        }
                    }
                    break;
                case 1:
                    x++;
                    if (x > (getWidth() / 10))
                    {
                        x = 0;
                    }
                    i1 = (
                            null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                                [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                                [(y - 1 <= -1) ? ((getWidth() / 10) + (y - 1)) : (y - 1)]
                        );
                    i2 = (
                            null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                                [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                                [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)]
                        );
                    i4 = (
                            null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                                [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                                [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)]
                        );
                    if (i1 && i2 && i4)
                    {
                        rand = 0;
                    }
                    else if (i1 && i4)
                    {
                        rand = 3;
                    }
                    else if (i1 && i2)
                    {
                        rand = 2;
                    }
                    else if (i2 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 2;
                    }
                    else if (i4 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 3;
                    }
                    else if (i1)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 3;
                                break;
                            case 0:
                                rand = 2;
                                break;
                        }
                    }
                    break;
                case 2:
                    y--;
                    if (y < 0)
                    {
                        y = getHeight() / 10;
                    }
                    i1 = (
                            null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                                [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                                [(y - 1 <= -1) ? ((getWidth() / 10) + (y - 1)) : (y - 1)]
                        );
                    i3 = (
                            null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                                [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                                [(y - 1 <= -1) ? ((getHeight() / 10) + (y - 1)) : (y - 1)]
                        );
                    i4 = (
                            null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                                [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                                [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)]
                        );
                    if (i4 && i1 && i3)
                    {
                        rand = 3;
                    }
                    else if (i4 && i1)
                    {
                        rand = 0;
                    }
                    else if (i4 && i3)
                    {
                        rand = 1;
                    }
                    else if (i1 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 0;
                    }
                    else if (i3 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 1;
                    }
                    else if (i4)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 1;
                                break;
                            case 0:
                                rand = 0;
                                break;
                        }
                    }
                    break;
                case 3:
                    y++;
                    if (y > (getHeight() / 10))
                    {
                        y = 0;
                    }
                    i1 = (
                            null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                                [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                                [(y - 1 <= -1) ? ((getWidth() / 10) + (y - 1)) : (y - 1)]
                        );
                    i2 = (
                            null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                                [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                                [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)]
                        );
                    i3 = (
                            null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                                [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                                [(y - 1 <= -1) ? ((getHeight() / 10) + (y - 1)) : (y - 1)]
                        );
                    if (i2 && i1 && i3)
                    {
                        rand = 2;
                    }
                    else if (i2 && i1)
                    {
                        rand = 0;
                    }
                    else if (i2 && i3)
                    {
                        rand = 1;
                    }
                    else if (i1 && Greenfoot.getRandomNumber(15) == 0)
                    {
                       rand = 0; 
                    }
                    else if (i3 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 1;
                    }
                    else if (i2)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 1;
                                break;
                            case 0:
                                rand = 0;
                                break;
                        }
                    }
                    break;
            }
            
        }
        while (
                (
                    (
                        null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                            [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                        null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                            [(y - 1 <= -1) ? ((getWidth() / 10) + (y - 1)) : (y - 1)]
                    ) || x == (getWidth() / 10)
                ) || 
                (
                    (
                        null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                            [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)] ||
                        null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                            [(y + 2 >= (getHeight() / 10) + 1) ? (0 + (y + 2)) : (y + 2)]
                    ) || x == (getHeight() / 10)
                ) || 
                (
                    (
                        null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                            [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                        null == wallBoard[(x - 2 <= -1) ? ((getWidth() / 10) + (x - 2)) : (x - 2)]
                            [(y - 1 <= -1) ? ((getHeight() / 10) + (y - 1)) : (y - 1)]
                    ) || x == 0
                ) || 
                (
                    (
                        null == wallBoard[(x + 1 >= (getWidth() / 10) + 1) ? (0 + (x + 1)) : (x + 1)]
                            [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)] ||
                        null == wallBoard[(x - 1 <= -1) ? ((getWidth() / 10) + (x - 1)) : (x - 1)]
                            [(y - 2 <= -1) ? ((getHeight() / 10) + (y - 2)) : (y - 2)]
                    ) || y == 0
                )
            );
    }
    
    public void act ()
    {
        
    }
}
danpost danpost

2020/4/22

#
There are two things you need to understand. The first is that getRandomNumber returns a value between 0, inclusive, and its given limit, exclusive. For example, line 27 will set rand to a value in the set { 0, 1, 2 }. Notice that there are 3 possible values, not including 3. The other, which is quite similar in nature, is that the last cell, both horizontally and vertically, has a coordinate value one less than the dimensional length. With your world width of 1280, the x range is { 0 ... 1279 } (giving a total of 1280 cells). Your code will need to be adjusted to account for both of the above.
EvanRoscTheDev EvanRoscTheDev

2020/4/22

#
Thank you! I did not see that, I thought it was something deeper.
EvanRoscTheDev EvanRoscTheDev

2020/4/22

#
Just tested it now, the problem still persists. some how it has to do with the code internally. here is the rough code for review now:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class MyWorld extends World
{
    Actor[][] wallBoard;
    int rand;
    int x;
    int y;
    int z = 0;
    boolean i = true;
    boolean i1 = true;
    boolean i2 = true;
    boolean i3 = true;
    boolean i4 = true;
    
    public MyWorld()
    {
        super(1280, 720, 1, true);
        setup();
    }
    
    public void setup()
    {
        wallBoard = new Actor[getWidth() / 10][getHeight() / 10];
        x = Greenfoot.getRandomNumber(getWidth() / 10);
        y = Greenfoot.getRandomNumber(getHeight() / 10);
        rand = Greenfoot.getRandomNumber(4);
    }
    
    public void act ()
    {
        do
        {
            if (null == wallBoard[x][y])
            {
                wallBoard[x][y] = new wall();
                addObject(wallBoard[x][y], (x * 10) + 5, (y * 10) + 5);
            }
            switch (rand)
            {
                case 0:
                    x--;
                    if (x < 0)
                    {
                        x = (getWidth() / 10) - 1;
                    }
                    i2 = (
                            null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                                [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                                [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)]
                        );
                    i3 = (
                            null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                                [(y + 1 >= getHeight() / 10) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                                [(y - 1 <= -1) ? (((getHeight() / 10) - 1) + (y - 1)) : (y - 1)]
                        );
                    i4 = (
                            null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                                [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                                [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)]
                        );
                    if (i3 && i2 && i4)
                    {
                        rand = 1;
                    }
                    else if (i3 && i4)
                    {
                        rand = 3;
                    }
                    else if (i3 && i2)
                    {
                        rand = 2;
                    }
                    else if (i2 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 2;
                    }
                    else if (i4 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 3;
                    }
                    else if (i3)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 3;
                                break;
                            case 0:
                                rand = 2;
                                break;
                        }
                    }
                    break;
                case 1:
                    x++;
                    if (x > ((getWidth() / 10) - 1))
                    {
                        x = 0;
                    }
                    i1 = (
                            null == wallBoard[(x + 2 >= getWidth() / 10) ? (0 + (x + 2)) : (x + 2)]
                                [(y + 1 >= getHeight() / 10) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x + 2 >= getWidth() / 10) ? (0 + (x + 2)) : (x + 2)]
                                [(y - 1 <= -1) ? (((getWidth() / 10) - 1) + (y - 1)) : (y - 1)]
                        );
                    i2 = (
                            null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                                [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                                [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)]
                        );
                    i4 = (
                            null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                                [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                                [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)]
                        );
                    if (i1 && i2 && i4)
                    {
                        rand = 0;
                    }
                    else if (i1 && i4)
                    {
                        rand = 3;
                    }
                    else if (i1 && i2)
                    {
                        rand = 2;
                    }
                    else if (i2 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 2;
                    }
                    else if (i4 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 3;
                    }
                    else if (i1)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 3;
                                break;
                            case 0:
                                rand = 2;
                                break;
                        }
                    }
                    break;
                case 2:
                    y--;
                    if (y < 0)
                    {
                        y = (getHeight() / 10) - 1;
                    }
                    i1 = (
                            null == wallBoard[(x + 2 >= getWidth() / 10) ? (0 + (x + 2)) : (x + 2)]
                                [(y + 1 >= (getHeight() / 10) + 1) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x + 2 >= getWidth() / 10) ? (0 + (x + 2)) : (x + 2)]
                                [(y - 1 <= -1) ? (((getWidth() / 10) - 1) + (y - 1)) : (y - 1)]
                        );
                    i3 = (
                            null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                                [(y + 1 >= getHeight() / 10) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                                [(y - 1 <= -1) ? (((getHeight() / 10) - 1) + (y - 1)) : (y - 1)]
                        );
                    i4 = (
                            null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                                [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                                [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)]
                        );
                    if (i4 && i1 && i3)
                    {
                        rand = 3;
                    }
                    else if (i4 && i1)
                    {
                        rand = 0;
                    }
                    else if (i4 && i3)
                    {
                        rand = 1;
                    }
                    else if (i1 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 0;
                    }
                    else if (i3 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 1;
                    }
                    else if (i4)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 1;
                                break;
                            case 0:
                                rand = 0;
                                break;
                        }
                    }
                    break;
                case 3:
                    y++;
                    if (y > ((getHeight() / 10) - 1))
                    {
                        y = 0;
                    }
                    i1 = (
                            null == wallBoard[(x + 2 >= getWidth() / 10) ? (0 + (x + 2)) : (x + 2)]
                                [(y + 1 >= getHeight() / 10) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x + 2 >= (getWidth() / 10) + 1) ? (0 + (x + 2)) : (x + 2)]
                                [(y - 1 <= -1) ? (((getWidth() / 10) - 1) + (y - 1)) : (y - 1)]
                        );
                    i2 = (
                            null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                                [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)] ||
                            null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                                [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)]
                        );
                    i3 = (
                            null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                                [(y + 1 >= getHeight() / 10) ? (0 + (y + 1)) : (y + 1)] ||
                            null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                                [(y - 1 <= -1) ? (((getHeight() / 10) - 1) + (y - 1)) : (y - 1)]
                        );
                    if (i2 && i1 && i3)
                    {
                        rand = 2;
                    }
                    else if (i2 && i1)
                    {
                        rand = 0;
                    }
                    else if (i2 && i3)
                    {
                        rand = 1;
                    }
                    else if (i1 && Greenfoot.getRandomNumber(15) == 0)
                    {
                       rand = 0; 
                    }
                    else if (i3 && Greenfoot.getRandomNumber(15) == 0)
                    {
                        rand = 1;
                    }
                    else if (i2)
                    {
                        switch (Greenfoot.getRandomNumber(1))
                        {
                            case 1:
                                rand = 1;
                                break;
                            case 0:
                                rand = 0;
                                break;
                        }
                    }
                    break;
            }
            Greenfoot.delay(2097152);
        }
        while (
                (
                    (
                        null == wallBoard[(x + 2 >= getWidth() / 10) ? (0 + (x + 2)) : (x + 2)]
                            [(y + 1 >= getHeight() / 10) ? (0 + (y + 1)) : (y + 1)] ||
                        null == wallBoard[(x + 2 >= getWidth() / 10) ? (0 + (x + 2)) : (x + 2)]
                            [(y - 1 <= -1) ? (((getWidth() / 10) - 1) + (y - 1)) : (y - 1)]
                    ) || x == (getWidth() / 10)
                ) || 
                (
                    (
                        null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                            [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)] ||
                        null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                            [(y + 2 >= getHeight() / 10) ? (0 + (y + 2)) : (y + 2)]
                    ) || x == (getHeight() / 10)
                ) || 
                (
                    (
                        null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                            [(y + 1 >= getHeight() / 10) ? (0 + (y + 1)) : (y + 1)] ||
                        null == wallBoard[(x - 2 <= -1) ? (((getWidth() / 10) - 1) + (x - 2)) : (x - 2)]
                            [(y - 1 <= -1) ? (((getHeight() / 10) - 1) + (y - 1)) : (y - 1)]
                    ) || x == 0
                ) || 
                (
                    (
                        null == wallBoard[(x + 1 >= getWidth() / 10) ? (0 + (x + 1)) : (x + 1)]
                            [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)] ||
                        null == wallBoard[(x - 1 <= -1) ? (((getWidth() / 10) - 1) + (x - 1)) : (x - 1)]
                            [(y - 2 <= -1) ? (((getHeight() / 10) - 1) + (y - 2)) : (y - 2)]
                    ) || y == 0
                )
            );
    }
}
danpost danpost

2020/4/22

#
Apparently, rand is alternating between 0 and 1 inside the do loop, making x add and subtract; add and subtract. You need to be very careful with loops and make sure that they will eventually, at some point, be broken out of. Unfortunately, your coding is (1) undocumented; (2) bulky, and not easily readable; and (3) unfactored; -- making it virtually impossible to see what is going on (especially for an outsider). All I can say at this point is that you need better control of the flow within the loop. A visited cell should not be re-visited.
You need to login to post a reply.