A puzzle for someone to solve :)

Assume you have a screen that contains N rectangles (all the same size) spread out in a random manner. Choosing any one rectangle determine which other rectangle would be the optimal choose to move to in all 4 directions Up, Down, Left, Right

Rectangles that have any part of another rectangle over them are to be excluded

This is for a card game where there is no mouse, no keyboard, no touch interface, and the ONLY means of navigation is a DPAD that moves the FOCUS from card to card

This is a simple layout, most will have all 52 cards in some configuration or another

Note : movement into and out of the button bar at the bottom is required too :slight_smile:

All objects (cards and buttons) are referenceable via a collection of RECT objects

What is it that you want to know? I mean I know how to find the distance from point A to point B, is that what you’re after?

I would just use Pythagoras to find the shortest distance.
For animating a card to move to that point this should help: https://www.mathsisfun.com/algebra/line-equation-2points.html

I remember I did some of those thing in RealBasic when I did the Canvas tutorials. Not sure if they still would run in Xojo but I can try to find it back on some backup if you want.


Hey Man, long time no see!


I know!!! :smile: It looks like all the cool kids from the old days are here. I did not know this forum existed else I would have joined much earlier. I don’t dare to write anything on the ‘other’ forum because I was afraid to be kicked as soon as I replied with anything not directly related to Xojo :wink:


Cant make sense of that sentence. What is it that you want to do?

I need to calculate the optimum routes between cards, the routes must follow ONLY horizontal or vertical paths, There may (will) be focus points where a path does or can change direction (where two lines in the image intersect).

So in this example… to move from the top left card to the card out in the middle would take 4 moves. 3 horizontal (stopping at each node), and one vertical

The white lines would indicate the necessary path calculations for this particular situation, and was done manually as an example

No such restriction here ! :slight_smile:
Welcome back
You can post about any coding topic here
The general goal is “cross platform”

1 Like

@Alwaysbusy answer will do that for you. You know the X & Y co-ordinates, so you know two sides of a triangle, then you can calculate the 3rd side and that’s your distance.

No Sam , actually it won’t… as the requirement is the paths must follow only HORIZONTAL or VERTICAL paths…
Look at the image above the cursor can only move along the white line and will stop at each intersection

But not to worry I have solved this puzzle.

The solution is actually quite simple. Take for example the user wishes to move RIGHT
The app scans in a horizontal line from where the “cursor” is to the far edge of the screen.
If the next scanned point is directly above or below the MidX of a card, it stops. The user can then press Right again to continue in that direction or UP/Down where a similar algoritim takes over.
I have already implemented this (and Norman has agreed to test this and other functions of the app for me). This by the way is on an Apple TV for anyone interested.

I read your review on Web 2.0, I thought it was a very fair write-up with some great technical information that Xojo could use to improve their product. Good Job.

1 Like

Err… How did this end up as the solution?

1 Like

I think it is a habit @samRowlands. Most of the time you are giving the solution and now it seems people don’t even bother reading your post and just accept it. :rofl:

1 Like

Don’t get upset guys… .you both misunderstood the problem… no worries.
And sometimes just stating the problem in writing gives insight to a possible solution, which is exactly what happened in this case. Thanks.

@DaveS I think Sam referred to his remark about my Web 2.0 post being marked as the solution to your question

1 Like