Randomization

05/16/2020 19:05 ooklaba#1
hi all

i'm trying to work on my own scripts

can anyone help me with how to randomize paths? i am not sure where to begin. i have seen people using dice rolls for changing districts, could this apply to choosing one path vs another?

is there a way to make the path always differ by a few points each time?

thanks for all and any advice/help
05/17/2020 00:25 list comprehension#2
If you are using GWA2 the MoveTo function by default adds a random offset of + or -50 to the x and y coordinates when moving. This makes them relatively unique while being pretty accurate to a path.

A very common tactic for more random like pathing is to take a bots movement route and break it into subsections and then make multiple variations on each sub system. So when the pathing enters each one it generates a random number to select that sub path in a switch statement.

You can go much crazier to randomize pathing than that but its generally more than enough.
05/17/2020 05:12 phat34#3
Good points... Other options are possible of course...

If the map has a big open pattern you can even use the moveto with a random element at the end such as ….

Moveto( X, Y, Random( 0 , 300, 50)) this will greatly increase the randomness of the destination coordinate between 0, 50, 100, 150, 200, 250, or 300...

I think you might be looking for a way to deal with forks in the maps and have a random run of a map in this case you can either use a for next loop method or you can use the
Random(1, 4, 1) presented in an earlier message with if or case statements to determine the set of waypoints that will be run based on your number....
for it to work in a for next loop you would still have to use a random number generation statement to decide if this is the fork you would choose with an exitloop statement to leave the for next loop...
05/17/2020 11:14 JohnyDee#4
A long time ago I wrote this (it was used for exiting outposts)

Code:
; This func creates a random path for exiting outposts. It needs the coords of a spot
; in front of the exit-portal and the coords of a spot outside the portal for exiting.
; You may need to play around with the $aRandom to see which number fits you best.
Func RandomPath($PortalPosX, $PortalPosY, $OutPosX, $OutPosY, $aRandom = 50, $StopsMin = 1, $StopsMax = 5, $NumberOfStops = -1) ; do not change $NumberOfStops

	If $NumberOfStops = -1 Then $NumberOfStops = Random($StopsMin, $StopsMax, 1)

	Local $lAgent = GetAgentByID(-2)
	Local $MyPosX = DllStructGetData($lAgent, 'X')
	Local $MyPosY = DllStructGetData($lAgent, 'Y')
	Local $Distance = ComputeDistance($MyPosX, $MyPosY, $PortalPosX, $PortalPosY)

	If $NumberOfStops = 0 Or $Distance < 200 Then
		MoveTo($PortalPosX, $PortalPosY, (2 * $aRandom)) ; Made this last spot a bit broader
		Move($OutPosX + Random(-$aRandom, $aRandom, 1), $OutPosY + Random(-$aRandom, $aRandom, 1))
	Else
		Local $m = Random(0, 1)
		Local $n = $NumberOfStops - $m
		Local $StepX = (($m * $PortalPosX) + ($n * $MyPosX)) / ($m + $n)
		Local $StepY = (($m * $PortalPosY) + ($n * $MyPosY)) / ($m + $n)

		MoveTo($StepX, $StepY, $aRandom)
		RandomPath($PortalPosX, $PortalPosY, $OutPosX, $OutPosY,  $aRandom, $StopsMin, $StopsMax, $NumberOfStops - 1)
	EndIf
EndFunc
05/17/2020 15:21 RiflemanX#5
I have used a few methods in the past to randomize my paths. When opening up your path with a modified MoveTo() you just really need to make sure that there is nothing nearby that you can get stuck on and so for that reason I just use pre-scripted coords with perhaps a minimum +50 randomness to the path or whats some call the "Dice Roll". Below is an example of 20 random paths that I created and then I extended the MoveTo from +50 up to +100.

Code:
Func MoveRandom()
   Out("Random Movement")
   Switch (Random(1, 20, 1))    ;<<<<<<<<<<<<<<<<<<<<<<<< NOTICE:  MAKE SURE TO CHANGE THIS TO THE NUMBER OF RANDOM PATHS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
   Case 1
	     Out("Random Move-1")
		 MoveTo(-3921, 17481, 100)
	  Case 2
		 Out("Random Move-2")
		 MoveTo(-3872, 17407, 100)
	  Case 3
		 Out("Random Move-3")
		 MoveTo(-4030, 17267, 100)
	  Case 4
		 Out("Random Move-4")
		 MoveTo(-4318, 17257, 100)
	  Case 5
		 Out("Random Move-5")
		 MoveTo(-4517, 17140, 100)
		 MoveTo(-3298, 17703, 100)
	  Case 6
		 Out("Random Move-6")
		 MoveTo(-3604, 17680, 100)
	  Case 7
		 Out("Random Move-7")
		 MoveTo(-3110, 17908, 100)
	  Case 8
		 Out("Random Move-8")
		 MoveTo(-3041, 18051, 100)
	  Case 9
		 Out("Random Move-9")
		 MoveTo(-2958, 18041, 100)
	  Case 10
	     Out("Random Move-10")
		 MoveTo(-3349, 17643, 100)
	  Case 11
	     Out("Random Move-11")
		 MoveTo(-4217, 16914, 100)
	  Case 12
		 Out("Random Move-12")
		 MoveTo(-4210, 17072, 100)
		 MoveTo(-3729, 17264, 100)
	  Case 13
	     Out("Random Move-13")
		 MoveTo(-4776, 17714, 100)
		 MoveTo(-2989, 18115, 100)
	  Case 14
	     Out("Random Move-14")
		 MoveTo(-4207, 17233, 100)
		 Sleep(GetPing()+250)
		 MoveTo(-3316, 17795, 100)
	  Case 15
	     Out("Random Move-15")
		 MoveTo(-5347, 18281, 100)
		 Sleep(GetPing()+350)
		 MoveTo(-4764, 18646, 100)
		 Sleep(GetPing()+350)
		 MoveTo(-3655, 17592, 100)
		 MoveTo(-3050, 17958, 100)
	  Case 16
	     Out("Random Move-16")
		 MoveTo(-3724, 17171, 100)
		 Sleep(GetPing()+350)
	  Case 17
	     Out("Random Move-17")
		 MoveTo(-5063, 19388, 100)
		 Sleep(GetPing()+5550)
		 MoveTo(-3902, 17738, 100)
		 Sleep(GetPing()+350)
		 MoveTo(-3757, 17694, 100)
		 MoveTo(-3614, 17697, 100)
		 MoveTo(-3614, 17697, 100)
		 MoveTo(-3400, 17779, 100)
	  Case 18
	     Out("Random Move-18")
		 MoveTo(-4667, 17195, 100)
		 MoveTo(-4667, 17195, 100)
		 MoveTo(-3935, 17277, 100)
	  Case 19
	     Out("Random Move-19")
		 MoveTo(-4110, 17172, 100)
		 ReverseDirection()
		 Sleep(GetPing()+1550)
		 ReverseDirection()
		 Sleep(GetPing()+1550)
		 MoveTo(-3471, 17634, 100)
	  Case 20
	     Out("Random Move-20")
		 MoveTo(-4601, 17762, 100)
		 Sleep(GetPing()+1550)
		 ReverseDirection()
		 Sleep(GetPing+1550)
		 ReverseDirection()
		 MoveTo(-4196, 17809, 100)
		 MoveTo(-3476, 17772, 100)
	EndSwitch
EndFunc   ;Move to 1 of 20 random spots
05/19/2020 03:05 ooklaba#6
thank you for all the replies, will be trying out!
05/20/2020 01:13 phat34#7
Oh one more thing when modifying the MoveTo's third argument... by the portal...

Make sure you portal cord is that amount inside the portal or you may end up not making it to through the portal... in other words if the portal cords are 250,250 and your inside point is 0,0 then your moveto argument should be MoveTo( 350, 350, 100)…
05/20/2020 17:23 Dany7376#8
Quote:
Originally Posted by phat34 View Post
Oh one more thing when modifying the MoveTo's third argument... by the portal...

Make sure you portal cord is that amount inside the portal or you may end up not making it to through the portal... in other words if the portal cords are 250,250 and your inside point is 0,0 then your moveto argument should be MoveTo( 350, 350, 100)…
You don't want to use the GWA2 "MoveTo" function to go through a portal. The only advice, if you really want to give one, is to not put a number too high as third parameter for the last MoveTo before the portal.

The MoveTo function calls the Move function, and it does until you are close to the destination. If you MoveTo inside a portal, the coordinates are (0,0) during the loading, so it will call the Move function, and it will result in a crash.
05/20/2020 19:07 LamaChoco#9
Quote:
Originally Posted by Dany7376 View Post
You don't want to use the GWA2 "MoveTo" function to go through a portal. The only advice, if you really want to give one, is to not put a number too high as third parameter for the last MoveTo before the portal.

The MoveTo function calls the Move function, and it does until you are close to the destination. If you MoveTo inside a portal, the coordinates are (0,0) during the loading, so it will call the Move function, and it will result in a crash.
Agreed, you should use the Move function when going out of a portal, otherwise it will crash and/or result in your character going backward into the portal if you load fast enough.

As for the randomization of paths, as said earlier the MoveTo function already adds in some randomization that you can increase/decrease depending on what you want to do.
If you want to randomize between two different paths, the best way is to have your waypoints stored in two arrays, and to randomly load one of them when your run starts
05/22/2020 09:13 phat34#10
My bad... I was only using the portal as an example. But, yes I do recall, now and thanks... If you try to move while the map is loading you will cause a crash. Good of you guys to point that out. I stand corrected.