Click here to Skip to main content
15,914,386 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
Neo1010118-Jul-11 6:47
Neo1010118-Jul-11 6:47 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
David198718-Jul-11 7:03
David198718-Jul-11 7:03 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
Neo1010118-Jul-11 7:04
Neo1010118-Jul-11 7:04 
GeneralRe: Find an emtpy entry in a 3x3 grid? Pin
Wjousts21-Jul-11 9:45
Wjousts21-Jul-11 9:45 
QuestionCollision detection? [modified] Pin
Neo1010116-Jul-11 4:29
Neo1010116-Jul-11 4:29 
AnswerRe: Collision detection? [modified] Pin
Wjousts21-Jul-11 9:30
Wjousts21-Jul-11 9:30 
QuestionSorting algorithm problem [modified] Pin
Neo1010115-Jul-11 6:56
Neo1010115-Jul-11 6:56 
AnswerRe: Sorting algorithm problem Pin
Wjousts21-Jul-11 9:02
Wjousts21-Jul-11 9:02 
I think your problem is a XAML/JS problem not an algorithm problem. I assume borderArray is a flat array of all 9 cells and you are looking at each one in turn to find the one that is empty. That is a perfectly valid way of doing it, although a better way would be if you have populated the grid in the first place, can't you just keep track of which cell is empty instead of searching every time? That would be much more efficient.

As to what causes your actual problem, I can see a couple of things that strike me as odd, but you don't provide enough information to make sense of it.

Firstly, if every cell in your grid contains a border (which I assume is what borderArray is), setting another control to the same grid row and column does not make it a child of the Border (assuming your sender is the ellipse and not the border itself) in that cell.

Second, your search for 'ellipse' + (i+1); I'm assuming you have 8 ellipses that you've named ellipse1, ellipse2, ellipse3, etc. Then you've put ellipse1 in cell 0,0 ellipse2 in cell 0,1, etc. Now, once you've swapped one of those ellipses to a different cell, your borders (which I'm assuming aren't moving) don't hold the same ellipse (although they don't hold them at all, as I said earlier) as they started with. So looking for ellipse1 in borderArray[0] isn't valid if borderArray[0] now contains ellipse2.

Finally, if, as I suspect, you set this up so that the ellipse originally are children of Border controls that are actually in the grid, then it's not a surprise that you get Grid.Row and Grid.Column of 0,0. The ellipses aren't actually in the grid, their parents are.
GeneralData Pin
Burt12313-Jul-11 10:23
Burt12313-Jul-11 10:23 
GeneralRe: Data Pin
Richard MacCutchan13-Jul-11 21:48
mveRichard MacCutchan13-Jul-11 21:48 
GeneralRe: Data Pin
Burt12314-Jul-11 7:37
Burt12314-Jul-11 7:37 
GeneralRe: Data Pin
Richard MacCutchan14-Jul-11 8:11
mveRichard MacCutchan14-Jul-11 8:11 
QuestionModulo statement Pin
Lutosław5-Jul-11 1:44
Lutosław5-Jul-11 1:44 
GeneralRe: Modulo statement Pin
David19875-Jul-11 2:05
David19875-Jul-11 2:05 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 2:38
BobJanova5-Jul-11 2:38 
GeneralRe: Modulo statement Pin
David19875-Jul-11 3:13
David19875-Jul-11 3:13 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 2:47
Lutosław5-Jul-11 2:47 
GeneralRe: Modulo statement Pin
David19875-Jul-11 3:06
David19875-Jul-11 3:06 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 5:19
Lutosław5-Jul-11 5:19 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 5:45
BobJanova5-Jul-11 5:45 
GeneralRe: Modulo statement Pin
David19875-Jul-11 6:03
David19875-Jul-11 6:03 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 7:13
BobJanova5-Jul-11 7:13 
GeneralRe: Modulo statement Pin
BobJanova5-Jul-11 3:13
BobJanova5-Jul-11 3:13 
GeneralRe: Modulo statement Pin
David19875-Jul-11 3:14
David19875-Jul-11 3:14 
GeneralRe: Modulo statement Pin
Lutosław5-Jul-11 5:13
Lutosław5-Jul-11 5:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.