Author Topic: Checking/Accessing Eight Points Around One Point  (Read 6642 times)

0 Members and 1 Guest are viewing this topic.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Checking/Accessing Eight Points Around One Point
« on: September 17, 2010, 04:03:28 am »
I'm not to sure if the title really says what I mean. But what I'm looking for is a good way to access or check or just be able to do something to the spots surrounding a single spot. But also, now that I think about the situation, I just need a way to get access the points surrounding a point. Whether eight, five, or three (I think those are all the options...).

Code: [Select]
123
4█5
678

█1
12

12
█3
45

Those are the points I mean. I have one method that in theory would work, haven't tested it yet, but it only works for checking all eight points. Which might work for the situation but if someone knows a better way I'd like to hear it :)

Thanks for any help.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #1 on: September 17, 2010, 04:08:23 am »
Hmmm im not quite understanding what you're asking?  And what are the different diagrams of?

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Checking/Accessing Eight Points Around One Point
« Reply #2 on: September 17, 2010, 04:20:37 am »
Hmmm, let me see if I can explain a little better.

Well first the diagrams. Those are the points that I'm talking about. I'm fairly sure that those (with the exception of rotating and such) are the only combinations that you can have where the solid block is the point that was chosen and the spaces around it are what I want to be able to change or something. The ones that are of five and three points are when you are either in a corner or on a wall/barrier type thing so it limits what is there. That explain those any better?

As for the general question, I'm wondering what is a good way to be able to find/change/etc. those points like after its chosen. The current way that I thought of includes a couple For( loops but I can't help but think there is a better way of doing it.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #3 on: September 17, 2010, 04:23:09 am »
Well if you are going for speed, hardcoding is the way to go.  If you are going for size?  Probably nested for loops, since the shapes are rectangular.  Hmm you'd just have to make sure to exclude the center pixel.  Are you going for speed or size?

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Checking/Accessing Eight Points Around One Point
« Reply #4 on: September 17, 2010, 04:28:45 am »
I honestly haven't decided since I'm still planning things out. I'm just trying to get a idea for how I want to do everything. Ya, I thought about hard coding. It more just depends how big the program gets and how fast/slow it is. I can, in theory, make both the hard coding and For( loops possible. Is there any way you can think of that would adapt? Or anyone?

I actually thought of one way just now, might be a little tricky though.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Checking/Accessing Eight Points Around One Point
« Reply #5 on: September 17, 2010, 09:01:22 am »
I think I've done this before in TI-Basic (for Minesweeper and/or Lights Out)

I think I used a couple of For loops like this (where A,B is the center square, W,H are width/height of the grid):
Code: [Select]
For(M,A-(A>1),A+(A<W
For(N,B-(B>1),B+(B<H
...code
End
End
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #6 on: September 17, 2010, 01:47:24 pm »
Ohhh i see the predicament now!  You are moving around the pixel and sometimes it goes up against the wall and you wont want a domain error, but at the same time you dont want a crapload of if/boolean statements.  Calc85 provides an elegant solution :)

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #7 on: September 17, 2010, 01:50:10 pm »
Does this work?

Code: [Select]
X-coordinate ->X
Y-coordinate ->Y
For(A,-1,1)
    For(B,-1,1)
        If A and B      (so that the code doesn't run if A and B = 0)
        Then
           Do stuff with X+A and Y+B
        End
    End
End


Edit: wait, I think calc84's method might be better. 
« Last Edit: September 17, 2010, 01:51:51 pm by Michael_Lee »
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #8 on: September 17, 2010, 01:55:04 pm »
Calc84's method also checks to see if your area goes off the positive side of the boundaries

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #9 on: September 17, 2010, 01:56:05 pm »
I'm jealous - it's such a shorter way to do it then mine... :)
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #10 on: September 17, 2010, 01:59:49 pm »
It might be shorter, but its larger in size.  I counted 40 bytes for his and 31 bytes for yours.  I thing yours would get around to be 40 if you implemented the full occlusion tho, so they are pretty equal in size

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Checking/Accessing Eight Points Around One Point
« Reply #11 on: September 17, 2010, 02:52:31 pm »
I haven't completely gone over the code for these but thanks :) If I saw them right those were basically what my ideas were too :P Thanks though :D

Edit:
After going over them more, those essentially are what I had come up with. Thanks guys :)
« Last Edit: September 17, 2010, 05:28:26 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Checking/Accessing Eight Points Around One Point
« Reply #12 on: September 29, 2010, 07:46:37 pm »
So I have a new question that is sort of like the last one. I have been thinking of routines that only check both sides, up, and down on a point. So instead of the eight points before, just the four normal directions. I've thought about like a For( but would only check when at those certain points or just hard coding it in. Wasn't sure if there was another way that this could be done. Thanks in advance :)
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Checking/Accessing Eight Points Around One Point
« Reply #13 on: September 29, 2010, 10:07:17 pm »
Here is a similar solution:
Code: [Select]
For(M,-(A>1),A<W
For(N,-(B>1),B<H
If M xor N
Then
...code here, use M,N as offsets for the center point A,B...
End
End
End
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Checking/Accessing Eight Points Around One Point
« Reply #14 on: September 29, 2010, 10:11:11 pm »
You genius!  I couldn't figure out an easy way to do this and you easily come up with the best solution possible.  Well done calc! ;D