Created
November 6, 2017 17:31
-
-
Save wallabra/556fc0d9dddf416988e67800ecb6f310 to your computer and use it in GitHub Desktop.
A* search (beta) in Unreal Tournament (1999)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PriorityQueue extends Actor; | |
var float QCost; | |
var BreadcrumbII QData; | |
var bool bOccupied; | |
var bool bUsedUp; | |
var PriorityQueue nextQueue; | |
function bool InsertHere(float cost, BreadcrumbII data) | |
{ | |
local PriorityQueue exNext; | |
if ( bOccupied ) | |
{ | |
if ( nextQueue != none ) | |
exNext = nextQueue; | |
nextQueue = Spawn(class'PriorityQueue', self); | |
nextQueue.insert(cost, data); | |
if ( exNext != none ) | |
nextQueue.nextQueue = exNext; | |
} | |
else | |
{ | |
QCost = cost; | |
QData = data; | |
bOccupied = true; | |
return false; | |
} | |
return true; | |
} | |
function Insert(float cost, BreadcrumbII data) | |
{ | |
local PriorityQueue current; | |
local PriorityQueue previous; | |
for ( current = self; current != none && current.QCost <= cost; current = current.nextQueue ) | |
previous = current; | |
while ( previous.bUsedUp ) | |
previous = previous.nextQueue; | |
previous.InsertHere(cost, data); | |
} | |
function BreadcrumbII Poll() | |
{ | |
local PriorityQueue q; | |
if ( bUsedUp ) | |
{ | |
for ( q = self; q != none; q = q.nextQueue ) | |
if ( q.bOccupied && !q.bUsedUp ) | |
return q.Poll(); | |
return none; | |
} | |
bUsedUp = true; | |
return QData; | |
} | |
function int Length() | |
{ | |
local PriorityQueue current; | |
local int res; | |
res = 0; | |
for ( current = self; current != none; current = current.nextQueue ) | |
if ( !current.bUsedUp ) | |
res += 1; | |
return res; | |
} | |
defaultproperties | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment