Since I stopped working on this I might as well post what I had. Credit me if you use it. Also, I think i used someones findNearestKey hole, credit them too.
How it works:
Tries to find its way into the center based on it's position in the maze relative to the center square. The maze is divided up into sections - the rooms array.
Dx and Dy are the coords to walk to if in the section. The boolean is whether it needs to rotate the compass to find the door. I have only made up the paths for the middle bit of the maze. The maze is too big to do it like this however and you will need to create more landmarks - maybe one in each corner, as you cant always see the center square on the map. As you can see i used lots of trial and error =). I left the commented code in incase anyone wants to use it.
PS. The positioning thing isn't always very accurate :P
program Maze;
{.include SRL/SRL.scar}
type
Box = record
x1, y1, x2, y2: integer;
dx, dy: integer;
rotate: boolean;
end;
var
mazeWallColor, mazeFloorColor: integer;
//x, y: integer;
//mazeCenterDTM: integer;
//c: integer;
mazeCenterMask: integer;
rooms: array of box;
squarePosx, squarePosy: integer;
function getMazeWallColor: Integer;
var
{mazeWallDTMC: TDTMPointDef;
mazeWallDTMP: Array[0..1] of TDTMPointDef;
mazeWallDTMT: TDTM;
mazeWallDTM: Integer;}
i: Integer;
begin
{//with mazeWallDTMC do
//begin
mazeWallDTMC.x := 674;
mazeWallDTMC.y := 122;
mazeWallDTMC.areaSize := 0;
mazeWallDTMC.areaShape := 0;
mazeWallDTMC.color := 255;
//end
//with mazeWallDTMP[0] do
//begin
mazeWallDTMP[0].x := 674;
mazeWallDTMP[0].y := 117;
mazeWallDTMP[0].areaSize := 0;
mazeWallDTMP[0].areaShape := 0;
mazeWallDTMP[0].color := 255;
//end
//with mazeWallDTMP[1] do
//begin
mazeWallDTMP[1].x := 674;
mazeWallDTMP[1].y := 127;
mazeWallDTMP[1].areaSize := 0;
mazeWallDTMP[1].areaShape := 0;
mazeWallDTMP[1].color := 255;
//end
mazeWallDTMT.mainPoint := mazeWallDTMC;
mazeWallDTMT.subPoints := mazeWallDTMP;
for i := 0 to 20 do
begin
mazeWallDTMC.tolerance := i;
mazeWallDTMP[0].tolerance := i; getC
mazeWallDTMP[1].tolerance := i;
mazeWallDTM := addDTM(mazeWallDTMT);
//if(FindDTM(mazeWallDTM, x, y, MMX1, MMY1, MMX2, MMY2)) then
if(FindDTM(mazeWallDTM, x, y, 579, 48, 741, 201)) then
begin
result := getColor(x, y);
writeln('Maze wall color is ' + IntToStr(result));
exit;
end;
end;
Writeln('Could not find color');}
for i := 0 to 20 do
begin
if(findColorTolerance(x, y, 255, MMCX - 10, MMCY - 10, MMCX + 10, MMCY + 10, i)) then //paint + 3
begin
result := getColor(x, y);
writeln('Maze wall color is ' + IntToStr(result));
exit;
end;
end;
Writeln('Could not find maze wall color!');
end;
function getMazeFloorColor: Integer;
var
i: integer;
begin
for i := 0 to 20 do
begin
if(findColorTolerance(x, y, 9014165, MMCX - 10, MMCY - 10, MMCX + 10, MMCY + 10, i)) then //paint
begin
result := getColor(x, y);
writeln('Maze floor color is ' + IntToStr(result));
exit;
end;
end;
Writeln('Could not find maze floor color!');
end;
procedure setupDTMS;
//var
{mazeWallDTMC: TDTMPointDef;
mazeWallDTMP: Array[0..7] of TDTMPointDef;
mazeWallDTM: TDTM;
i: integer; }
begin
//mazeCenterMask := BitmapFromString(18, 18, 'z78DA73731BFEC0800600BF5D' +
// 'D475F9A85DA3768DDA356AD7D0B58B3E65EF700200ED4BF8D0');
mazeCenterMask := BitmapFromString2(False, 'a98A6778DAED94BB0EC0200' +
'8457F8928501C6B1FFFFF49E5B2B875324D6A60382137C2619288' +
'E82C0EB2DD211A34752A312836927A388B2117412F77E4B1405B0' +
'5BB3837BEC0CE236978543BF673CC2E5FB7CCE7BB6BEEE5E94A57' +
'BAD2F55FD7377FEF4AF5009DE');
{mazeWallDTMC.y := 86;
mazeWallDTMC.areaSize := 5;
mazeWallDTMC.areaShape := 0;
mazeWallDTMC.tolerance := 0;
mazeWallDTMC.color := mazeFloorColor;
for i := 0 to 7 do
begin
mazeWallDTMP[i].areaSize := 1;
mazeWallDTMP[i].areaShape := 0;
mazeWallDTMP[i].tolerance := 0;
mazeWallDTMP[i].color := mazeWallColor;
end;
mazeWallDTMP[0].x := 648;
mazeWallDTMP[0].y := 80;
mazeWallDTMP[1].x := 648;
mazeWallDTMP[1].y := 86;
mazeWallDTMP[2].x := 648;
mazeWallDTMP[2].y := 94;
mazeWallDTMP[3].x := 655;
mazeWallDTMP[3].y := 94;
mazeWallDTMP[4].x := 662;
mazeWallDTMP[4].y := 94;
mazeWallDTMP[5].x := 662;
mazeWallDTMP[5].y := 87;
mazeWallDTMP[6].x := 662;
mazeWallDTMP[6].y := 80;
mazeWallDTMP[7].x := 655;
mazeWallDTMP[7].y := 80;
mazeWallDTM.mainPoint := mazeWallDTMC;
mazeWallDTM.subPoints := mazeWallDTMP;
mazeCenterDTM := addDTM(mazeWallDTM); }
end;
procedure getMazeColors;
begin
mazeWallColor := getMazeWallColor;
mazeFloorColor := getMazeFloorColor;
end;
procedure addToRoomsArray(var arr: array of box; x1, y1, x2, y2, dx, dy: integer; rotate: boolean);
var
i: integer;
begin
i := getArrayLength(arr);
setArrayLength(arr, i + 1);
{arr[i].x1 := x1 - 94;
arr[i].y1 := y1 - 98;
arr[i].x2 := x2 - 94;
arr[i].y2 := y2 - 98;
arr[i].dx := dx - 94;
arr[i].dy := dy - 98;}
arr[i].x1 := x1;
arr[i].y1 := y1;
arr[i].x2 := x2;
arr[i].y2 := y2;
arr[i].dx := dx;
arr[i].dy := dy;
arr[i].rotate := rotate;
end;
procedure setupRooms;
begin
{addToRoomsArray(rooms, 91, 95, 104, 108, 98, 102);
addToRoomsArray(rooms, 104, 87, 112, 116, 91, 102);
addToRoomsArray(rooms, 83, 87, 91, 116, 91, 101);
addToRoomsArray(rooms, 91, 87, 104, 95, 91, 101);
addToRoomsArray(rooms, 91, 108, 104, 116, 91, 101);}
{addToRoomsArray(rooms, -3, -3, 10, 10, 3, 3);
addToRoomsArray(rooms, 10, -11, 18, 18, -3, 4);
addToRoomsArray(rooms, -11, -11, -3, 18, -3, 3);
addToRoomsArray(rooms, -3, -11, 10, -3, -3, 3);
addToRoomsArray(rooms, -3, 9, 10, 18, -3, 3);
addToRoomsArray(rooms, 18, -18, 25, 25, 4, 18);
addToRoomsArray(rooms, -18, -18, -11, 25, 5, 18);
addToRoomsArray(rooms, -11, -18, 18, -11, 4, 18);
addToRoomsArray(rooms, -11, 18, 18, 05, 4, 18);
addToRoomsArray(rooms, 25, -26, 33, 21, 5, -26);
addToRoomsArray(rooms, 25, 21, 33, 33, -26, 17);
addToRoomsArray(rooms, -26, -26, -18, -14, 4, -26);
addToRoomsArray(rooms, -26, -14, -18, 33, -26, 17);
addToRoomsArray(rooms, -18, -26, 25, -18, 4, -26);
addToRoomsArray(rooms, -18, 25, 25, 33, 22, 33);
addToRoomsArray(rooms, 33, -34, 41, -18, 4, -26);
addToRoomsArray(rooms, 33, -18, 41, 41, -26, 18);
addToRoomsArray(rooms, -34, -34, -26, 41, -14, -34);
addToRoomsArray(rooms, -26, -34, -7, -26, -14, -34);
addToRoomsArray(rooms, -7, -34, 33, -26, 4, -26);
addToRoomsArray(rooms, -26, 33, 9, 41, -14, -34);
addToRoomsArray(rooms, 9, 33, 33, 41, 22, 33);
addToRoomsArray(rooms, -42, -42, -35, -8, -29, -42);
addToRoomsArray(rooms, -42, -8, -34, 21, -37, -22);
addToRoomsArray(rooms, -42, 21, -34, 49, -21, 45);
addToRoomsArray(rooms, 41, -42, 49, -10, 27, -38);
addToRoomsArray(rooms, 41, -10, 49, 16, 36, 17);
addToRoomsArray(rooms, 41, 16, 49, 49, 42, 16);
addToRoomsArray(rooms, -34, -42, -22, -34, -39, -25);
addToRoomsArray(rooms, -22, -42, 41, -34, 17, -34);
addToRoomsArray(rooms, -34, 41, -5, 49, 5, 45);
addToRoomsArray(rooms, -5, 41, 29, 49, 3, 37);
addToRoomsArray(rooms, 29, 41, 49, 49, 44, 28);}
addToRoomsArray(rooms, -3, -3, 10, 10, 3, 4, False); //1
addToRoomsArray(rooms, 10, -11, 18, 18, -3, 3, True); //2
addToRoomsArray(rooms, -11, -11, -3, 18, -3, 3, True); //3
addToRoomsArray(rooms, -3, -11, 10, -3, -3, 2, True); //4
addToRoomsArray(rooms, -3, 10, 10, 18, -3, 4, True); //5
addToRoomsArray(rooms, 18, -18, 25, 25, 4, 18, False); //6
addToRoomsArray(rooms, -18, -18, -11, 25, 4, 18, False);
addToRoomsArray(rooms, -11, -18, 18, -11, 21, 4, False);
addToRoomsArray(rooms, -11, 18, 18, 25, 5, 18, False); //9
addToRoomsArray(rooms, 25, -26, 33, 21, 25, 2, True);
addToRoomsArray(rooms, 25, 21, 33, 33, 4, 29, True);
addToRoomsArray(rooms, -26, -26, -18, -14, 1, -23, True);
addToRoomsArray(rooms, -26, -14, -18, 33, -25, 17, True);
addToRoomsArray(rooms, -18, -26, 25, -18, 25, 4, True);
addToRoomsArray(rooms, -18, 25, 25, 33, -26, 16, True); //15
addToRoomsArray(rooms, 33, -34, 41, -18, 6, -30, False);
addToRoomsArray(rooms, 33, -18, 41, 41, 22, 33, False);
addToRoomsArray(rooms, -34, -34, -26, 2, -14, -34, False); //18 - everthing here move down!!!!!!
addToRoomsArray(rooms, -34, 3, -26, 41, -27, -23, False);
addToRoomsArray(rooms, -26, -34, -7, -26, -14, -34, False);
addToRoomsArray(rooms, -7, -34, 33, -26, 4, -26, False);
addToRoomsArray(rooms, -26, 33, 9, 41, -28, 2, False); //22
addToRoomsArray(rooms, 9, 33, 33, 41, 22, 33, False);
addToRoomsArray(rooms, -42, -42, -35, -8, -34, 6, True); //24
addToRoomsArray(rooms, -42, -8, -34, 21, -34, 6, True);
addToRoomsArray(rooms, -42, 21, -34, 49, -4, 45, False);
addToRoomsArray(rooms, 41, -42, 49, -10, 18, -34, False);
addToRoomsArray(rooms, 41, -10, 49, 16, 41, 15, True); //28
addToRoomsArray(rooms, 41, 16, 49, 49, 41, 15, True);
addToRoomsArray(rooms, -34, -42, -22, -34, -37, -21, False);
addToRoomsArray(rooms, -22, -42, 41, -34, 17, -34, False);
addToRoomsArray(rooms, -34, 41, -5, 49, 6, 43, False);
addToRoomsArray(rooms, -5, 41, 29, 49, 5, 41, False);
addToRoomsArray(rooms, 29, 41, 41, 49, 43, 15, True);
end;
procedure removeFromTPointArray(var arr: array of tPoint; n: integer);
var
i, j: integer;
tmpArr: array of tPoint;
begin
for i := 0 to getArrayLength(arr) - 1 do
begin
if(not (n = i)) then
begin
j := getArrayLength(tmpArr);
setArrayLength(tmpArr, j + 1);
tmpArr[j] := arr[i];
end;
end;
setArrayLength(arr, j + 1);
arr := tmpArr;
end;
procedure removeBoxFromPoints(var arr: array of tPoint; box: tBox);
var
i: integer;
begin
for i := 0 to getArrayLength(arr) - 1 do
begin
if(inRange(arr[i].x, box.x1, box.x2) and inRange(arr[i].y, box.y1, box.y2)) then
begin
removeFromTPointArray(arr, i);
end;
end;
end;
procedure addToTPointArray(var arr: array of tPoint; point: tPoint);
var
i: integer;
begin
i := getArrayLength(arr);
setArrayLength(arr, i + 1);
arr[i] := point;
end;
procedure arrangePointsByDistance(var arr: array of tPoint; x, y: integer);
var
i, j, k, l: integer;
tempArr: array of tPoint;
begin
repeat
if(getArrayLength(arr) <= 0) then
begin
setArrayLength(arr, getArrayLength(tempArr));
arr := tempArr;
exit;
end;
for i := 0 to getArrayLength(arr) - 1 do
begin
//writeln(intToStr(i));
j := distance(x, y, arr[i].x, arr[i].y);
if((j < k) or (k <= 0)) then
begin
k := j;
l := i;
end;
end;
//writeln(intToStr(arr[l].x) + ', ' + intToStr(arr[l].y));
addToTPointArray(tempArr, arr[l]);
removeFromTPointArray(arr, l);
l := 0;
j := 0;
k := 0;
until(false)
end;
procedure removePointsByDistance(var arr: array of tPoint; dist: integer);
var
i, j: integer;
begin
{for i := 0 to getArrayLength(arr) - 1 do
begin
for j := 0 to getArrayLength(arr) - 1 do
begin
if(i = j) then
begin
break;
end;
try
if(distance(arr[i].x, arr[i].y, arr[j].x, arr[j].y) <= dist) then
begin
removeFromTPointArray(arr, j);
removePointsByDistance(arr, dist);
end;
except
Writeln('error');
end;
end;
end;}
end;
function FindDoor2: Boolean;
var
I, x1, y1, x2, y2, ChangeAmt: Integer;
H, S, L, X, Y, Z: Extended;
xx, yy: integer;
begin
ColorToleranceSpeed(0);
x1:= MSCX;
y1:= MSCY;
x2:= MSCX;
y2:= MSCY;
for I:= 0 to 5 do
begin
ChangeAmt:= ChangeAmt + 10;
x1:= x1 - ChangeAmt;
y1:= y1 - ChangeAmt;
x2:= x2 + ChangeAmt;
y2:= y2 + ChangeAmt;
if(FindColorSkipBoxTolerance(xx, yy, 1118485, x1, y1, x2, y2, 1, InttoBox(243, 148, 287, 195)))then
begin
ColortoHSL(GetColor(xx, yy), H, S, L);
ColortoXYZ(GetColor(xx, yy), X, Y, Z);
if(L > 6.8)then if(L < 8.1)then if(X > 0)then if(X < 1)then if(Y > 0)then if(Y < 1)then if(Z > 0)then if(Z < 1)then
begin
MMouse(xx, yy, 1, 1);
if(IsUpText('Ope'))then
begin
Result:= True;
Mouse(xx, yy, 5, 5, True);
FFlag(5);
Flag;
wait(500 + random(1000));
exit;
end;
end;
end;
end;
end;
procedure findDoor;
var
playerBox: TBox;
i, j: integer;
doors: array of tPoint;
h, s, l, x, y, z: extended;
xx, yy: integer;
begin
playerBox := intToBox(255, 148, 284, 187);
for i := 0 to 20 do
begin
findColorsTolerance(doors, 1118485, MSX1, MSY1, MSX2, MSY2, i); //paint
if(getArrayLength(doors) > 0) then
begin
removeBoxFromPoints(doors, playerBox);
arrangePointsByDistance(doors, MSCX, MSCY);
removePointsByDistance(doors, 5);
if(getArrayLength(doors) <= 0) then
begin
exit;
end;
//writeln(intToStr(getArrayLength(doors)));
for j := 0 to getArrayLength(doors) - 1 do
begin
ColortoHSL(GetColor(doors[j].x, doors[j].y), H, S, L);
ColortoXYZ(GetColor(doors[j].x, doors[j].y), X, Y, Z);
if(L > 6.8)then if(L < 8.1)then if(X > 0)then if(X < 1)then if(Y > 0)then if(Y < 1)then if(Z > 0)then if(Z < 1)then
begin
//writeln(intToStr(doors[j].x) + ', ' + intToStr(doors[j].y));
mMouse(doors[j].x, doors[j].y, 5, 5);
Wait(20 + random(50));
if(isUpTextMulti('pen', 'en W', 'all')) then
begin
GetMousePos(xx, yy);
mouse(xx, yy, 0, 0, True);
FFlag(5);
Flag;
wait(500 + random(1000));
exit;
end;
end;
end;
end
end
end;
procedure touchShrine;
var
playerBox: TBox;
i, j: integer;
shrine: array of tPoint;
begin
writeln('yay we are in the middle!');
playerBox := intToBox(255, 148, 284, 187);
for i := 0 to 20 do
begin
findColorsSpiralTolerance(MSCX, MSCY, shrine, 1907999, MSX1, MSY1, MSX2, MSY2, i); //paint
if(getArrayLength(shrine) > 0) then
begin
removeBoxFromPoints(shrine, playerBox);
arrangePointsByDistance(shrine, MSCX, MSCY);
removePointsByDistance(shrine, 5);
if(getArrayLength(shrine) <= 0) then
begin
exit;
end;
//writeln(intToStr(getArrayLength(shrine)));
for j := 0 to getArrayLength(shrine) - 1 do
begin
//writeln(intToStr(shrine[j].x) + ', ' + intToStr(shrine[j].y));
mMouse(shrine[j].x, shrine[j].y, 5, 5);
Wait(20 + random(50));
if(isUpTextMulti('ouch', 'range', 'rine')) then
begin
GetMousePos(x, y);
mouse(x, y, 0, 0, True);
FFlag(5);
Flag;
wait(500 + random(1000));
Writeln('finished maybe?');
end;
end;
end
end
end;
procedure findArea(mx, my: integer);
var
i: integer;
begin
//mx := mx * -1;
//my := my * -1; //get the inverse
//writeln(IntToStr(mx) + ', ' + intToStr(my));
for i := 0 to getArrayLength(rooms) - 1 do
begin
//writeln('testing if ' + intToStr(mx) + ' is in ' + intToStr(rooms[i].x1) + ', ' + intToStr(rooms[i].x2));
//writeln('testing if ' + intToStr(my) + ' is in ' + intToStr(rooms[i].y1) + ', ' + intToStr(rooms[i].y2));
if(inRange(mx, rooms[i].x1, rooms[i].x2) and inRange(my, rooms[i].y1, rooms[i].y2)) then
begin
Writeln('in room ' + intToStr(i));
if(i = 0) then
begin
touchShrine;
end;
Mouse(rooms[i].dx + squarePosx, rooms[i].dy + squarePosy, 2, 2, True);// in paint so add 3
Flag;
Wait(500 + random(1000));
if(rooms[i].rotate) then
begin
writeln('need to rotate');
case random(2) of
0: makeCompass('w');
1: makeCompass('e');
end;
end;
break;
end;
end;
end;
procedure findCenter;
var
acc: extended;
mazePosx, mazePosy: integer;
begin
//Writeln(intToStr(mazeCenterDTM));
{if(findDTM(mazeCenterDTM, x, y, MMX1, MMY1, MMX2, MMY2)) then
begin
Writeln('found the dtm at (' + IntToStr(x) + ', ' + IntToStr(y) + ')');
c := 0;
end else
begin
if(c >= 5) then
begin
writeln('Couldnt find the center! Exiting');
exit;
end;
Writeln('didnt find the dtm, trying again');
Inc(c);
getMazeColors;
findCenter;
end}
//if(FindBitmapMaskTolerance(mazeCenterMask, x, y, MMX1, MMY1, MMX2, MMY2, 20, 20)) then
perfectNorth;
if(FindDeformedBitmapToleranceIn(mazeCenterMask, x, y, MMX1, MMY1, MMX2, MMY2, 20, 1, False, acc)) then //paint
begin
squarePosx := x;
squarePosy := y;
x := x + 9; //in paint so take 3
y := y + 9;
//Writeln('yay it worked at (' + IntToStr(x) + ', ' + IntToStr(y) + ') with accuracy ' + FloatToStr(acc));
//MoveMouseSmooth(x, y);
mazePosx := (MMCX) - x; //paint
mazePosy := (MMCY) - y;
findArea(mazePosx, mazePosy);
end
end;
procedure makeLinesStraight
var
wall: integer;
accuracy, angle: integer;
begin
wall := := BitmapFromString2(False, 'aF1AF178DA333080015367206' +
'1EE6A0E24CDCC0D416C23673869E46A065263ECEA660AA2A94B02' +
'00FA8');
perfectNorth;
findDeformedBitmapToleranceRotationIn(wall, x, y, MMX1, MMY1, MMX2, MMY2, 20, 1, Accuracy, (2 * pi) * (5 / 360), 0, (2 * pi), Angle)
if(angle > 180) then
begin
end;
sendArrowWait();
end;
begin
setupSRL;
perfectNorth;
getMazeColors;
setupRooms;
setupDTMs;
repeat
findCenter;
findDoor;
until(isFKeyDown(12))
//getPosition;
end.