SRL Archive - General

[Committed] Hybrid Walking


Coh3n

2011-01-24 18:09:50

I started this the other day, and I ran in to a few snags and I need some ideas for solutions or work-arounds.

Problems:
  1. In order for the system to work properly, the reflection and color paths need to be the same length. Currently, they're not because we use one reflection path (and inverse it) and two color paths.
  2. Markus brought up that it always walks to the same tiles. Not a huge deal, but I really like Nava and Zeph's system that randomly creates the straight line paths, meaning a path to VE Mine would be 3-4 tiles rather than 10-12 (the in between tiles are automatically generated).
  3. That would most likely cause there to be a different amount of tiles clicked each run, which will mess up the color points as the will now have different lengths.
  4. What should be done with these constants?

  5. WALK_WC_VE_TREE_1 = 0;
    WALK_WC_VE_TREE_2 = 1;
    WALK_WC_VE_TREE_3 = 2;
    WALK_WC_VE_TREE_4 = 3;

    WALK_WC_VE_OAKS_1 = 4;
    WALK_WC_VE_OAKS_2 = 5;

    WALK_WC_VE_BANK_1 = 6;
    WALK_WC_VE_BANK_2 = 7;
    WALK_WC_VE_BANK_3 = 8;
    WALK_WC_VE_BANK_4 = 9;

    WALK_WC_DB_WILLOWS_1 = 10;
    WALK_WC_DB_WILLOWS_BANK_1 = 11;

    WALK_MINE_LSW_1 = 12;
    WALK_MINE_LSW_2 = 13;
    WALK_MINE_LSW_3 = 14;
    WALK_MINE_LSW_4 = 15;
    WALK_MINE_LSW_5 = 16;
    WALK_MINE_LSW_6 = 17;
    WALK_MINE_LSW_7 = 18;
    WALK_MINE_LSW_8 = 19;

    WALK_MINE_LSW_BANK_1 = 20;
    WALK_MINE_LSW_BANK_2 = 21;
    WALK_MINE_LSW_BANK_3 = 22;
    WALK_MINE_LSW_BANK_4 = 23;
    WALK_MINE_LSW_BANK_5 = 24;
    WALK_MINE_LSW_BANK_6 = 25;
    WALK_MINE_LSW_BANK_7 = 26;

    WALK_FISH_DB_1 = 27;
    WALK_FISH_DB_BANK_1 = 28;

    WALK_WC_GE_YEW_1 = 29;
    WALK_WC_GE_YEW_2 = 30;
    WALK_WC_GE_YEW_3 = 31;

    WALK_WC_GE_YEW_BANK_1 = 32;
    WALK_WC_GE_YEW_BANK_2 = 33;
    WALK_WC_GE_YEW_BANK_3 = 34;

    WALK_WC_PS_WILLOW_1 = 35;
    WALK_WC_PS_WILLOW_2 = 36;

    WALK_WC_PS_WILLOW_BANK_1 = 37;
    WALK_WC_PS_WILLOW_BANK_2 = 38;
    Since the color records will be automatically updated, the constants wouldn't really be used except for declaring them in the PathInfo record, so IMO are pointless.
  6. When declaring the color paths I would like to have the arrays of length 2 (start index and end index), a range of the records to use.

  7. // This
    ColorTo := [ 0, 6 ];

    // Instead of this
    ColorTo := [ 0, 1, 2, 3, 4, 5, 6 ];
    This also brings up the length issue again.

Possible Solutions:
  1. It will all work perfectly if we had a setup like this

  2. with PathInfo do
    begin
    TilesTo := [ Point(), Point() ];
    TilesFrom := [ Point(), Point() ];
    ColorTo := [ 0, 1 ];
    ColorFrom := [ 2, 3 ];
    end;
    which we all know isn't ideal because it doesn't solve Markus' suggestion, plus it includes an extra reflection path that isn't necessary. I suppose reflection could be combined in to one, and just have the first index removed to make it the same length as the color path. This also means that Nava and Zeph's methods wouldn't work, which I dislike.
  3. We have three walking methods (which I think is the best solution, but we still need to solve the above issue), color, reflection, and hybrid, and the user has the choice (will use hybrid by default).
  4. We don't have a hybrid option. Only color or reflection. The color points can be generated using my generator; it would just require someone to run it and add the points each time a new path is added. So no automatically updating color records using reflection (because the lengths wouldn't be the same). But if we can find a way around that, great, forget about this option.

I'll add as things come up. :)

Coh3n

2011-01-25 00:27:19

Just got an idea for a reflection MSI_Flag alternative. Simply have it click the next tile as it appears on the minimap. Simple, but effective. Should get rid of any waiting between tiles.

Coh3n

2011-01-26 01:25:34

If I don't get any replies in the next day or two I'm going to go ahead and use solution number 1 (with the tile paths combined). I'll also not use constants for the WalkPoint indexes as they're will be way too many and they will only be used when declaring the TScript record.

Sir R. M8gic1an

2011-01-26 09:12:50

From: Coh3n
Just got an idea for a reflection MSI_Flag alternative. Simply have it click the next tile as it appears on the minimap. Simple, but effective. Should get rid of any waiting between tiles.


Now that is such a great idea, and I've never seen or heard about it before.

And for hybrid walking…….. I have an idea..

IsPointInPath(MMPoint: TPoint; Path: TPointArray)

If the MMColorPoint belongs to Path then we are colour walking with reflection backup to check we are on the right path.

Now, for this function to work it would need quite a bit of maths. If you like the sound of it we could post a request for help up in devs, cus I know that I don't have the required math to pull that one out

Coh3n

2011-01-26 13:36:24

From: Sir R. Magician
Now that is such a great idea, and I've never seen or heard about it before.

And for hybrid walking…….. I have an idea..

IsPointInPath(MMPoint: TPoint; Path: TPointArray)

If the MMColorPoint belongs to Path then we are colour walking with reflection backup to check we are on the right path.

Now, for this function to work it would need quite a bit of maths. If you like the sound of it we could post a request for help up in devs, cus I know that I don't have the required math to pull that one out

I'm not sure how it would work though because the color points are essentially just coordinates, meaning that the coordinates could be the same for a point from VE bank to mine and a point from GE bank to yews (since their in the same direction).

I'm not 100% sure yet, but I think I may be able to make it work declaring the paths like this (we just wouldn't be able to use Nava and Zeph's method).

Reflection := [ Point(), Point (), Point() ];
ColorTo := [ 0, 5 ];
ColorFrom := [ 6, 10 ];

Coh3n

2011-01-27 01:29:18

I've committed and MSI_WaitTile function and from what I tested it works really well. I've also almost finished the color walking which I'll probably commit before I'm finished with the actual hybrid part. I also want to add a setup var for "Walking method" so the user will be able to choose between color, reflection and hybrid.

Coh3n

2011-01-29 03:19:28

So here's what I came up with. I haven't even checked if it compiles, but as far as I can tell, I'm not missing anything. I would love it if someone could review it as I'm leaving for the night. :)

function MSI_HybridWalk(StartLoc, EndLoc: Integer): Boolean;
var
h, hi, i, j: Integer;
cPath: T2DIntegerArray;
rPath: T2DPointArray;
obsSolved: TBooleanArray;
cPoint, rPoint: TPoint;
pointDistance: Integer;
script: TScript;
begin
if (not LoggedIn) then
Exit;

try
MSI_AddHeader('MSI_HybridWalk: '+IntToStr(StartLoc)+' to '+IntToStr(EndLoc));

// Declare the color and reflection paths
cPath := MSI_FillColorPath(MSI_LoadColorPath(StartLoc, EndLoc));
rPath := MSI_LoadTilePath(StartLoc, EndLoc);
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript].Name];
hi := High(rPath);

// Check the length of the paths
if (Length(cPath) <> Length(rPath)) then
begin
MSI_Debug('Path lengths do not match');
MSI_Debug('Generating new color path');

with MSI_Players[CurrentPlayer].Scripts[CurrentScript] do
if (StartLoc = MSI_Scripts[Name].PathInfo.StartLoc) then
MSI_Scripts[Name].PathInfo.ColorTo := MSI_AddWalkPoints(rPath)
else
if (StartLoc = MSI_Scripts[Name].PathInfo.EndLoc) then
MSI_Scripts[Name].PathInfo.ColorFrom := MSI_MirrorATPA(MSI_AddWalkPoints(rPath));

Result := AtLocation(EndLoc);
end;

for i := 0 to hi do
begin
// Check the length of the legs of the paths
if (Length(cPath[i]) <> Length(rPath[i])) then
begin
MSI_Debug('Path leg lengths do not match');
Exit;
end;

for j := 0 to High(rPath[i]) do
begin
// Get the minimap coord for the reflection and color points
cPoint := MSI_GetWalkCoords(MSI_WalkPoints[cPath[i][j]]);
rPoint := TileToMM(rPath[i][j]);

MSI_Debug('Color Point: '+IntToStr(cPoint.x)+', '+IntToStr(cPoint.y));
MSI_Debug('Reflection Point: '+IntToStr(rPoint.x)+', '+IntToStr(rPoint.y));

pointDistance := Distance(cPoint.x, cPoint.y, rPoint.x, rPoint.y);
MSI_Debug('Distance between points: '+IntToStr(pointDistance));

if (pointDistance > 10) then
begin
// Create and set the new color point
MSI_WalkPoints[cPath[i][j]] := MSI_GenerateWalkPoint(rPath[i][j]);

// Walk to the tile
if (not MSI_ClickTile(rPath[i][j])) then
begin
MSI_Debug('Failed to walk leg '+IntToStr(i)+' of script: '+Capitalize(Script.Name));
ReportInfo.FalseReason := 'Failed to walk to ' + MSI_Locations[eLoc].Name;
MSI_Players[CurrentPlayer].Location := LOC_LOST;
Exit;
end else
MSI_Flag(FLAG_DISTANCE);
end else
MSI_WalkToPoint(cPoint, cPath[i][j]);
end;

// Handle the obstacle if there is one
if (MSI_HandleObstacle(script, StartLoc, h)) then
begin
obsSolved[h] := True;
if (h <> obsLen) then
Inc(h);
end;

Result := MSI_AtLocation(EndLoc);
end;

finally
MSI_CloseHeader('MSI_HybridWalk: '+BoolToStr(Result));
end;
end;
E: I've edited it so that if a color path doesn't exist, it will generate it. For this to work to it's fullest, we'll need to make the TScript records automatically "updatable" (save/load them from a file).

E: Got rid of the reflection defines as this won't be called if reflection is broken.

NCDS

2011-01-29 11:39:39

From: Coh3n

E: Got rid of the reflection defines as this won't be called if reflection is broken.


Should still keep it incase someone chooses not to use Reflection, no?

Also, doesn't MSI_Flag use the FLAG_DISTANCE const, or was something recently changed?

Look's pretty good though, I just skimmed through it quick but I've got a few free hours later. :)

Coh3n

2011-01-29 13:24:50

From: NCDS
Should still keep it incase someone chooses not to use Reflection, no?

Yeah that was my original thought, but if they choose not to use reflection, then the color walking methods will be called, not the hybrid ones. In other words, I think the defines will better fit in MSI_PerformWalk.

From: NCDS

Also, doesn't MSI_Flag use the FLAG_DISTANCE const, or was something recently changed?

You mean because of the parameter? Yeah, I changed that a long time ago. There are a few places where MSI_Flag(0) is called, so I've found it pretty useful.

Gu3st...

2011-01-29 13:45:04

From: Coh3n
Yeah that was my original thought, but if they choose not to use reflection, then the color walking methods will be called, not the hybrid ones. In other words, I think the defines will better fit in MSI_PerformWalk.
But if the user hasn't included reflection, then the script will error saying procedure R_FunctionName doesn't exist or something like that

Coh3n

2011-01-29 13:49:25

From: Zyt3x
But if the user hasn't included reflection, then the script will error saying procedure R_FunctionName doesn't exist or something like that

Take a look at Walking_Reflection.simba. ;)

All the function names are declared. The defines are inside the functions so if reflection isn't included, they return false by default. Also, I think the idea of that was to use the defines only for functions that use reflection directly.

Gu3st...

2011-01-29 13:53:24

From: Coh3n
Take a look at Walking_Reflection.simba. ;)

All the function names are declared. The defines are inside the functions so if reflection isn't included, they return false by default. Also, I think the idea of that was to use the defines only for functions that use reflection directly.
I was talking about functions like "TileToMM", that isn't inside Walking_Reflection.simba, but is called in MSI_HybridWalking…

Coh3n

2011-01-29 13:56:34

From: Zyt3x
I was talking about functions like "TileToMM", that isn't inside Walking_Reflection.simba, but is called in MSI_HybridWalking…

Oh yeah my bad. :p I forgot I called it. In that case, I think the whole function should be in defines, like the others.

Coh3n

2011-01-30 02:07:43

This is now committed. :) From what I've tested (and I tested every scenario I could think of) it works really well. I'm surprised actually; I didn't get as frustrated as I thought. :p I also added the option for users to choose between color, reflection, or hybrid walking systems. It will use hybrid if the user didn't specify, and color if reflection is found to be broken.

If you wanna check it out:
http://villavu.com/repositories/msi/MSI/Core/Walking_Color.simba
http://villavu.com/repositories/msi/MSI/Core/Walking_Reflection.simba

MSI_HybridWalk is in Walking_Reflection, the actual generating system is in Walking_Color.