First off - apologies if this has been answered before or if it's obvious. I'm a programmer who codes in IBM RPG/iSeries so the class/method/oop syntax is all very new to me (and it's hard to teach an old dog new tricks).
I'm trying to reproduce the A*/star algorithm in Cerberus. I've just about succeeded (in an extremely inefficient and clunky way) using object arrays for my open & closed lists but feel that this is perhaps the wrong tool for the job, especially as it's difficult to delete an array entry so there are less rows to read when trying to find the record I want.
So instead I thought about about using object lists and making use of the various Sort/Contains/Remove methods that lists have. I've been able to manipulate lists in this way when they are just straight forward Int or String lists, but can't figure out the syntax for searching or sorting by a particular field within my object/class.
For example, my object is something like this:
Class workList
Field x:Int = 0
Field y:Int = 0
Field g:Int = 0
Field h:Int = 0
Field f:Int = 0
End
Global openList:List<workList> = New List<workList>
openList.AddLast(New workList(1,3,1,2,3))
openList.AddLast(New workList(3,7,1,1,7))
openList.AddLast(New workList(8,3,2,6,3))
openList.AddLast(New workList(0,3,1,9,1))
openList.AddLast(New workList(4,9,0,8,6))
openList.AddLast(New workList(99,1,0,2,3))
openList.AddLast(New workList(2,3,2,3,3))
And I want to be able to check if the "x" field in openList.Contains(99), or to openList.Sort() by the "f" field. Is this possible or do I have to manually do these tests by reading through the lists using an Eachin For loop?
Any help would be gratefully received.
Thanks
I'm trying to reproduce the A*/star algorithm in Cerberus. I've just about succeeded (in an extremely inefficient and clunky way) using object arrays for my open & closed lists but feel that this is perhaps the wrong tool for the job, especially as it's difficult to delete an array entry so there are less rows to read when trying to find the record I want.
So instead I thought about about using object lists and making use of the various Sort/Contains/Remove methods that lists have. I've been able to manipulate lists in this way when they are just straight forward Int or String lists, but can't figure out the syntax for searching or sorting by a particular field within my object/class.
For example, my object is something like this:
Class workList
Field x:Int = 0
Field y:Int = 0
Field g:Int = 0
Field h:Int = 0
Field f:Int = 0
End
Global openList:List<workList> = New List<workList>
openList.AddLast(New workList(1,3,1,2,3))
openList.AddLast(New workList(3,7,1,1,7))
openList.AddLast(New workList(8,3,2,6,3))
openList.AddLast(New workList(0,3,1,9,1))
openList.AddLast(New workList(4,9,0,8,6))
openList.AddLast(New workList(99,1,0,2,3))
openList.AddLast(New workList(2,3,2,3,3))
And I want to be able to check if the "x" field in openList.Contains(99), or to openList.Sort() by the "f" field. Is this possible or do I have to manually do these tests by reading through the lists using an Eachin For loop?
Any help would be gratefully received.
Thanks