My problem is very similar to eight queens puzzle.
I’ve got 2-dimensional array (N x N) that for example, looks like this:
0,0,0,0,1 y 0,0,0,0,0 | 0,0,0,0,0 V 0,0,0,1,0 0,0,0,0,0 x->
I’m checking horizontally, vertically and diagonally for occurrences of 1
\,0,|,0,/ 0,\,|,/,0 -,-,1,-,- 0,/,|,\,0 /,0,|,0,\
I’m thinking about storing only the (x,y) postions of ‘1”s in a list
[[4,0],[3,3]]
and solving it mathematically, check every position of ‘1’ with another (x1,y1)<->(x2,y2),
if x1 == x2 or y1 == y2 we have a collision! if not check:
x2 == x1 + z; y2 == y1 + z; x2 == x1 - z; y2 == y1 - z;
(???)
where z is +/- that ( x1+z in 0..N ) and ( y1+z in 0..N ) .......
My problem is checking for diagonal collision, is there a better way to do it???
One possible solution:
i.e. there is a collision if the two points are on the same horizontal row, same vertical row or same diagonal (vertical distance == horizontal distance).