If you have the algorithm for how to set the intensity for squares when a hole is made,
and have written the code for it,
can you explain what your problem is?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
If you have the algorithm for how to set the intensity for squares when a hole is made,
and have written the code for it,
can you explain what your problem is?
If you don't understand my answer, don't ignore it, ask a question.
When placing a wall, it should remove the light from the no longer existing light source.
That would be a part of the algorithm.
If you don't understand my answer, don't ignore it, ask a question.
I know, that's why I made a thread here. I don't know how I can achieve this.
That's what we've been working on. Start with this one question:
What are the rules for setting the lightedness for squares when there is a light source (hole) at a square in the array?
If you don't understand my answer, don't ignore it, ask a question.
It only updates when placing or removing a wall. There are 2 arrays, a byte array (the light values) and a wall array(the walls). I told you how the light spreads.
If you know how the light spreads, you should be able to describe the algorithm in words to get a design for writing the code.I told you how the light spreads.
What are you trying to get from this thread? I thought you wanted to work on the algorithm. One of the steps is defining how the light is spread when a new source/hole appears. Given an x,y location for that hole, how will the light intensities be set for the near and far adjoining squares?
If you don't understand my answer, don't ignore it, ask a question.
Okay, this is how it works (some kind of pseudocode)
void removeWall(int x, int y)
{
setWall(x,y,null);
updateLight(x,y);
}
void updateLight(int x, int y)
{
if(getWall(x,y) == null -> If there's no wall)
{
sets the light level to the lamp's light level and does this for each adjacent space:
}checks if the light level is less than the light level of this space -1
if so, it sets the light level to the light level of the space -1 and calls the updateLight method on this position
else
{
does this for each adjacent space:
}checks if the light level is less than the light level of this space -1
if so, it sets the light level to the light level of the space -1 and calls the updateLight method on this position
}
Last edited by Bingo90; April 2nd, 2014 at 12:13 PM.
There are up to 8 near adjacent spaces. What is the level that is to be set for those squares?sets the light level to the lamp's light level and does this for each adjacent space:
What about the next set of spaces in the surrounding ring? and the next one out?
What happens when at edge of the array?
What does that mean? That looks like code, not some text for the algorithm.if(getWall(x,y) == null)
If you don't understand my answer, don't ignore it, ask a question.
There's a colon, updated the post and quoted it to make it more understandableThere are up to 8 near adjacent spaces. What is the level that is to be set for those squares?sets the light level to the lamp's light level and does this for each adjacent space:
What about the next set of spaces in the surrounding ring? and the next one out?
What happens when at edge of the array?
Is that comparing the square at x,y with its adjacent squares and using the value - 1 of the light intensity of the square at x,y?checks if the light level is less than the light level of this space -1
For testing I'd recommend a small 2D array with a given hole. Run the code with the small array and print out the contents of the array to see if the values are what you want.
If you don't understand my answer, don't ignore it, ask a question.
Light spreading works fine when removing a wall. But it'll do absolutely nothing when placing a wall, because I haven't implemented the code yet. I tried, but I have no idea how to do this :/
I assume replacing a wall means the removing of a hole/light source. The requirements then are to restore the light intensities to what they were before the hole was made and to consider any changes made after that hole was made.
One approach would be to pass over the whole area and set the intensities again for each hole.
If you don't understand my answer, don't ignore it, ask a question.
Bingo90 (April 2nd, 2014)
Hmm that could work... I'll try that.