Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: meishe91 on September 17, 2010, 04:03:28 am

Title: Checking/Accessing Eight Points Around One Point
Post by: meishe91 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.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Builderboy on September 17, 2010, 04:08:23 am
Hmmm im not quite understanding what you're asking?  And what are the different diagrams of?
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 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.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Builderboy 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?
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 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.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: calc84maniac 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
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Builderboy 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 :)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Michael_Lee 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. 
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Builderboy 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
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Michael_Lee on September 17, 2010, 01:56:05 pm
I'm jealous - it's such a shorter way to do it then mine... :)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Builderboy 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
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 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 :)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 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 :)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: calc84maniac 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
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: ztrumpet 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
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: calc84maniac on September 29, 2010, 10:16:02 pm
One of the few times the xor operator comes in handy :)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: ztrumpet on September 29, 2010, 10:21:22 pm
Yup - Checkerboard patterns.  I've used it before in drawing things like this:
. . . . .
 . . . . .
. . . . .
 . . . . .
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 on September 29, 2010, 10:23:07 pm
Ah, thanks :D So basically you use M and N to offset to the points I'm checking?

@Z
What do you mean about checkerboard patterns?
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: ztrumpet on September 29, 2010, 10:24:45 pm
For(A,1,8)
For(B,1,16)
If fpart(A/2) xor fpart(B/2)
Output(A,B,"O
End
End

Things like this. :)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 on September 29, 2010, 10:32:06 pm
Ah ok. I gotcha.

Edit:
By the way that can be just:

Code: [Select]
For(A,1,8
For(B,1,16
If fPart(A/2) xor fPart(B/2
Output(A,B,"O
End
End
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: DJ Omnimaga on September 30, 2010, 12:29:55 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.
You know, something like that would be VERY useful if I decided to do that dynamic bit-based tilemapper I wanted to make at one point in Axe, where walls are different depending of if there's a floor sprite at the top, bottom, left or right.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: calc84maniac on September 30, 2010, 12:33:52 am
You know, something like that would be VERY useful if I decided to do that dynamic bit-based tilemapper I wanted to make at one point in Axe, where walls are different depending of if there's a floor sprite at the top, bottom, left or right.
I do something sort of like that for loading maps in F-Zero. They are stored as 64x64 bitmaps, but I unpack them into a 64x64 tilemap, checking adjacent tiles for whether I need a track boundary or a diagonal track tile.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: DJ Omnimaga on September 30, 2010, 12:37:19 am
Nice. I want to give this a try because I had some RPGs that used maps where each tile was 1 bit and, while they are limited, those maps are really small in size.

EDIT: There was also a screenshot showing this in action:
(http://img.removedfromgame.com/imgs/1280784624-mrphdraw.gif)
Original topic:
http://ourl.ca/6544/106719

EDIT: I think they are called automated tiles.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: ztrumpet on September 30, 2010, 07:05:04 pm
Ah ok. I gotcha.

Edit:
By the way that can be just:

Code: [Select]
For(A,1,8
For(B,1,16
If fPart(A/2) xor fPart(B/2
Output(A,B,"O
End
End
No.
It must be one of these two:

Code: [Select]
For(A,1,8)
For(B,1,16)
If fPart(A/2) xor fPart(B/2
Output(A,B,"O
End
End

Code: [Select]
For(A,1,8
For(B,1,16
If fPart(A/2) xor fPart(B/2
Then
Output(A,B,"O
End
End
End
This is due to the For( glitch. :)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 on September 30, 2010, 07:21:56 pm
But the glitch is only if the If statement is false. I ran both versions, mine and yours, and yours is technically slower (it's negligible). It's odd, I know, but ya. It doesn't really matter though.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: DJ Omnimaga on September 30, 2010, 07:28:53 pm
If both are the same size, I would probably go with the non-glitchy one, because sometimes, the For() glitch triggers major slowdown until the next ON keypress even after exiting the For loop x.x
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 on September 30, 2010, 07:33:51 pm
Well both the ones he just showed are the same size, it looks like anyways, and guarantee no slow down but when I tested his original one and mine I didn't experience any at all when I ran mine.
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: Deep Toaster on September 30, 2010, 07:34:11 pm
If both are the same size, I would probably go with the non-glitchy one, because sometimes, the For() glitch triggers major slowdown until the next ON keypress even after exiting the For loop x.x

Wow. TI has got to fix their bugs x.x

Has anyone contacted them about this one?

Also, hurrah for XOR actually being used!
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: meishe91 on September 30, 2010, 07:35:15 pm
BrandonW fixed it, I believe. (Him or penguin, but I'm fairly sure it was BrandonW.)
Title: Re: Checking/Accessing Eight Points Around One Point
Post by: DJ Omnimaga on September 30, 2010, 07:55:10 pm
BrandonW did. I do not remember if his OS patch is compatible with other patches he made, though, and if it was for 2.53MP or not