Now, justbefore I gettoostuckintoexplainingthealgorithm, you'llnoticealsothatthisseemstobequite a highresolution, andthat's because I'm doingitinthepixelgameengineinsteadoftheconsolegameengineon.
I wantedthehighresolutiontodemonstrateaneffectlateron.
Andforthefirsttimeeverin a onelonecodevideo, I'm goingtomake a littlepersonalannouncement.
I'vehad a surprisingnumberofrequeststhatpeoplewouldinsomewayliketosupportme.
As a result, I'vecreated a patrioticpage.
Youcanfindthelinktothepantryonbelowonwhat I willsayisitisentirelyuptoyou.
Thereisnoobligationatall, I probablywroteBeproducinganyexclusivecontent, anditisunlikelythat I'llevenmentionyournamesinanyvideos.
Butifyou'd liketobuyme a cupoftea, thenpoponovertothepantryonpage.
When I lookedatthe A staralgorithm, oneofthefundamentalassumptionswemadewasthatthelocations, thewaypoints, didn't necessarilyhavetobeorganizedinanyparticularway.
Wejusthad a graphoffinterconnectednotes, andsothealgorithmwasreallytaskedwithtryingtofindtheshortestpathfromonenotetotheother, knowingsomesortofheuristicontothedistancebetweenthenotes.
The A staralgorithmitselfwascomputational.
Quitesimple, butconceptuallyitwas a littletricky.
Andaspartofthatdemonstration, I madeanotherfundamentalassumption.
Eventhoughwecoulduse a starongenericgraphslikethat.
Infact, whatwedidwashaveroutinelypositionnodesin a gridondhe.
Ifyoueverusedthefloodfilltoolinpaintorinphotoshoporgimp, thenyouhaveused a formoffwavepropagationfundamentallyWhatwe'retryingtoachieveisthetransmissionoffinformationfrom a startingpointacrossthearrayonthiswayfrontcarriestheinformation.
I'm goingtocodethisoneupprettyquicklybecausewe'vealreadydonesomethingsimilarwiththe A staralgorithm.
Isthatthistime I'm doingitinthepixelgameengine.
I'm goingtostartwith a basicpixelgameenginetemplate, and I created a classderivedfromthepixelgameenginecalledPathFindingFlowfields, and I'm creating a gameengineof 5 12 pixelswideby 4 80 pixelshighoneachpixelinthegame.
Spaceistwopixelsonyourscreen, solet's getsomeoftheboilerplateouttheway I know I'm goingtoneed a twodimensionalmap.
We'llhavemapwitandmapheightvariables.
I wantthemaptolooklike a grid, soweknowwhichcellswereselecting.
So I'm goingtohave a cellsizevariable, and I won't have a thickness, whichrepresentstheborderbetweenthecells.
Soifwespecifycellsizeof 32 on, wehaveaboardwidthoftotheactualdrawncellsizeis 30 pixelson.
I'm goingtoneedmyfirstarray, whichyou'regoingtobe a BooleanarraycalledBeObstaclemap.
Andit's goingtobetrueforanobstacleexistsandfalseforDoesn't ourpopulatethesevariablesintheonusercreatefunctionthereweretospecify, tohave a borderwidthoffourin a cellsizeof 32 on I'm goingtomakethemapwidthandheight.
Variablesdependonhowbigthegameenginescreenhasbeencreatedinthefirstplace, and I'llalsocreatemyarray, havedefinedthearraytobedefaultedtofalse.
Inournewsupdate, I wanttodrawthearray, includingtheobstacles.
Now I'm goingtoalsodraw a fewofthethingsaswellasthevideoprogresses.
Buttostartwith.
I wanttojustclearthisscreenandthen I'llcreatetwonestedfourloops, whichit a ratethroughallofthecellsinourmap.
Thedefaultcolorfor a cellisgoingtobeblueandfridgecelllocation.
Andthistimeit's goingtobeanintegerarecolicflowfieldzedandmightbewonderingwhy I saidthatthisrepresentsthedevaluethatwe'vejustseenwhenwecalculateditbyhandon.
Inmanyways, thatdevaluecanbeconsideredtheheightoffthemapatthatlocation, so I'm goingtocreateanarrayoffheights.
Andso I'm goingtodothisbyhavingagaintwonestedfourloopsand I wanttosettominusonethecorrespondinglocationinourflowfieldmap.
Ifwe'reontheborderorthereisanobstacleinthatlocationtothebordersaffiliatedtocheckforif X or Y isequaltozero, thenit's goingtobeanobstacle.
Likewise, if X or Y isequaltothedimensionsofthemapminusone, that's theothersideandfinallywilldipintotheobstaclemaparrayitselfthearrayofbillionsatLocation X y.
Andsoitseemsonlyfittingthatwillmodern c++ thisapplicationtodeath?
I'm goingtocreate a listofftopplesTherewegoon, wecanseethelistishereonthelistwillcontain a typetoppleonthetoppleitselfisoftypeintintintwherethefirstinterviewisthe X coordinateoffthenewnodethatwe'veaddedThesecondinterviewisthe Y coordinateofthanyouknowthatwe'veaddedontothethirdinterviewisthedistanceofthenewnodethatwe'veadded.
Remember, wehavethecolumnsontherightandscreen X y d thosecorrespondtothesethreeinterviewsandsothisisgoingtobeourlistoffdiscoverednoteon.
So I'm goingtouse a littleautofourlooptodothat, justsothingscanremainslightlyreadableforthevideo, I'm goingtoactuallyextract X, Y and D independentlyfromthetopple.
Andyoudothat.
Usingthesestandardgetfunctiononthefirststageofthealgorithmistowritethecurrentdevaluetothatlocationsowecandothatwith a singleline.
Thatis, ofcourse, theonetotheright, but I don't wanttogooutofbounds, Sothefirstthing I'm goingtocheckforisthecurrent X locationplusone, a validlocationtobesamplingfromourRafer.
Andthenicethingaboutitisit.
It's guaranteedtoexecutetheseconditionsinorder, soifanyofthemfailtheyearfourfailstraightawaythatmeans I canperthisupwithHonore.
Checkonthiswillallowmetosafelycheckthisarrayregardlessofwhatthe X and Y coordinatesaregoingtobe.
Sointhiscase, ifthisreturnstrue, then I wanttopushthisnodebackontomynewnodeslist, whichiscurrentlyempty, and I'm goingtopushitbackwiththecorrectlocation X plusoneandwhy?
Andifyouremember, wetakethecurrent D andaddonetoitin a verysimilarway.
I cancheckthewesternneighbor, exceptthistime I'm checkingtoseethattheWesternneighboris, ofcourse, equaltoormorethanzero.
AnditgoeswithoutsayingthatNorthandSouthneighborsarealsoverysimilarindeed, Sothisautofullloophasnowgonethroughallofthenodesinournodelisttobeprocessedandcreated a wholebunchofnewnotes.
I'm justcheckingtoseeifsomethingislessthansomethingelseonthatsomethingisactuallygoingtobetheresultofour P Lambdafunction, whichwestartedwithatthebeginningonthearguments I'm goingtopasstothatofthe X and Y locationsforthatspecifictopplethat's comein.
Andthereason I'm doingthisisthattheTopplewillhavean X and y coordinate.
I can't comparethoseveryreadily, butwhat I candoisconverttheminto a uniqueone.
Devalueon.
I cancomparethoseonedevalueswiththelessthanoperator.
So I dothatforbothsidesofthatoperatorcorrespondingtobothtopplesandyoumightthink, Well, whatkindofnonsensesortisthison?
Thetruthis, I don't reallycarewhattheorderisoncethey'vebeensorted.
What I careaboutisthattheyarestackedupinthisparticularpattern, appealedtoassumeit s soitdoesn't matterhowmessythingsareoncethesortisfinished.
Notesthataresimilararegroupedtogether, and I wantthemgroupedinthatparticularwaybecause I'm goingtouseanothermodern c++ miracle.
Itallowedmetoexplorethesefunctionsin a littlebitofdetail.
Nowthat I know I'vegot a uniquelistofnewlydiscoverednodes, I'm goingtoclearthelistofnodesthatwe'vejustbeenprocessingandreplacethatlistwiththenewlydiscoveredsortednotelist.
Andtodothis, I needto, firstlyextractthefirstpointseparately, which I dohere.
So I haveanoriginal X andanoriginal.
Whyvalue?
Becausethelistofpointsisreally a listofpearsthistimeandnot a topple.
I canaccessthe X coordinatewiththefirstparameteronthe Y.
Coordinatewiththesecondparameter.
I onlywanttodothisfortheveryfirstpointbecause I need a startingpointformyline.
Theremainingpoints.
I couldjustusethepointfromthepreviousiterationofthisloopthat's allusedthedrawlinefunctiontohelpmedojustthisonitisgoingtobe a littlebitof a mouthfulforeachcoordinatesimplybecause I wantto.
Firstly, scale.
Don't forget, thiswillbeinsortofnodespace, sothisis a verysmallcoordinatesystem.
Anita's nowscaleittothisscreenappropriately, so I'lltakemyexlocation.
Whichofthestartoftheline I wanttomultiplyitbycellsizetogetitupintoscreenspace.
Butthen I wanttooffsetitbyhalfthecellsizeminustheborderwithbecause I wanttodrawitfromthemiddlelocationoffthecell.
That's forthe X coordinate.
Doexactlythesameforthe Y Coordinateon.
I doexactlythesameforthenewcourtIt, exceptthistime I'm usingthecurrentpointsfirstandsecondparameters.
It's importantthat I remembertoupdatemy O X and A Y valueswiththoseparametersforthenextiteration.
Andfinally, ontopofallthat, I amgoingtodraw a bigyellowcircletoshowwhichcellhasbeenpath.
Solet's take a lookwell, wecanseethepathhasbeendiscovered.
Thisiswhatwesawatthestartofthevideo.
Exceptthistime, we'veonlygotfourwayconnectiveity.
Nowthatmightbedesirableincertainapplicationswhereyouwantthingstobehavein a verycellularmanner.
And I canalsopropagatethewaveoutwardstoseethepaththatwaschoseneightwakenactivityisquite a simpleaddition.
Andindeed, whyhave I evencalledsomeofmyvariablesfieldtheinformationthatwecurrentlyhaveinourheightmapisenoughtostartgivingussomeGradyINTsinthe X and Y directions, so I'm goingtocreatetwoadditionalmapsflowField X andflowfield.
Why, actually, I wanttocreatethesetobethesamesizeastherestofthemapsandinitializethemtozerobylookingattheheightvaluesintheheightmap, wecanextractinformationaboutlocalradiance.
Andso, for a givencell, I canworkout a resultantvectorwhichrepresentstheGradyintothatlocation.
It's a zerointhe X appearwe'vegottheplusoneintheUAEAnddownherewe'vegot a plusoneintheWhyIfwecallthisoneleftonthisonerightonthisoneuponthisonedown, wecanseethatwegetthe D X valuewouldbeequaltoourminus.
L A.
D y valuewouldbeequaltodown, minusup.
Soforthisparticularcell, wecouldsaythat D X isequaltominusoneon D Y isequaltozero.
It's a ratethroughourheightmap, but I'm goingtoignoretheboundaries.
I don't wanttogetintoanyboundaryissuesthistime.
I'm doingthisin a slightlylongwindedmanner, but I'm goingtocreatetheindividual x and Y componentsonsomethemupnowbecause I don't wanttoincludeminusones.
I'm goingtoassumethatmyarrowfitsinto a circledrawnbythatdashline.
Therewithradiusarenowthat I knowtheateronour I canusesomesimplemodificationstocosignandsignfunctionstogivemethecoordinatesofthesefourpointsofmyarrow, betweenwhich I willdrawthearrowlines.
So I usedtheAtento F functiontocalculatetheangleofthefieldatthatparticularlocationusingtheDeacsentiWhycomponentsontheradiusis a functionoffthecellsizeandborderwidth.
I wouldn't liketousethisalgorithmin a situationwhere I'vegotmultipleagentstryingtoreachmultipledestinationssimplybecause I'd havetocreatetheentirewavepropagatedfieldmapforeverysingleunit I'd preferinthatcase, tousesomethinglike a starsimplybecause a staris a guidedversionof
hello, andit's been a longtimesince I'vedoneanyofthis, but I thoughtit's timefor a part.
Subtitles and vocabulary
Click the word to look it upClick the word to find further inforamtion about it