Yea, my tile order is wacked out. My chief concern was starting with 0,0 (the city square) and moving out in distance order. Which isn't what MoM did. Thanks for working on your algorithm, which (I think) achieves the MoM behavior, at least with the nearby squares.
Taking a maxDistance of 3, the version in my post:
Code: Select all
(* do each distance "layer" one at a time *)
for currentDistance:=0 to maxDistance do
(* for all x where abs(x) <= currentDistance *)
for dX:=-currentDistance to currentDistance do
(* for all y where abs(x)+abs(y) <= currentDistance *)
for dY:=-currentDistance+abs(dX) to currentDistance-abs(dX) do
(* exclude cases where abs(x)+abs(y) < currentDistance because those would be duplicates *)
if abs(dX)+abs(dY) = currentDistance then
begin
currentPoint := CoordinatePair.Create;
currentPoint.X := dX;
currentPoint.Y := dY;
result.Add(currentPoint);
end
Gives these tiles when run in Delphi 7:
Code: Select all
0,0
-1,0
0,-1
0,1
1,0
-2,0
-1,-1
-1,1
0,-2
0,2
1,-1
1,1
2,0
-3,0
-2,-1
-2,1
-1,-2
-1,2
0,-3
0,3
1,-2
1,2
2,-1
2,1
3,0
Whereas the version in your post:
(adapted to Delphi 7)
Code: Select all
for currentDistance:=0 to maxDistance do begin
dY:=-currentDistance;
for dX:=-currentDistance to currentDistance do begin
currentPoint := CoordinatePair.Create;
currentPoint.X := dX;
currentPoint.Y := dY;
result.Add(currentPoint);
end;
//at this point dX should still = currentDistance (I believe?)
for dY:=-currentDistance+1 to currentDistance do begin
currentPoint := CoordinatePair.Create;
currentPoint.X := dX;
currentPoint.Y := dY;
result.Add(currentPoint);
end;
//and now dY is left at currentDistance
for dX:=currentDistance-1 to -currentDistance do begin
currentPoint := CoordinatePair.Create;
currentPoint.X := dX;
currentPoint.Y := dY;
result.Add(currentPoint);
end;
//and now we traverse the last side with dX = -currentDistance
for dY:=currentDistance-1 to currentDistance+1 do begin
currentPoint := CoordinatePair.Create;
currentPoint.X := dX;
currentPoint.Y := dY;
result.Add(currentPoint);
end;
end;
Gives these tiles:
Code: Select all
0,0
-1,1
0,1
1,-1
1,0
1,1
-1,-1
0,-1
1,-1
2,0
2,1
0,0
0,1
0,2
-2,-2
-1,-2
0,-2
1,-2
2,-2
3,-1
3,0
3,1
3,2
1,1
1,2
1,3
-3,-3
-2,-3
-1,-3
0,-3
1,-3
2,-3
3,-3
4,-2
4,-1
4,0
4,1
4,2
4,3
2,2
2,3
2,4
I think the first 9 tiles are correct, but I'm not sure after that (hard to visualize). Also, it yields a bunch of duplicates which isn't the end of the world (and might be due to my adaption of the algorithm), but I'd like to avoid. Finally, I don't know how a maxdistance of 3 yields an offset of 4,3 ;) I'm not sure I translated the algorithm correctly, I'll look more closely when I get the time.
edit: actually, upon visualizing, the first 9 tiles in the list I got out of the second algorithm aren't right:
the (9) means that (+1,-1) is both the 4th and 9th tile. And it appears that (-1,0) is not generated at all.
the first tile list isn't much better, of course:
Code: Select all
10
08 04 12
06 02 01 05 13
07 03 11
09