Tricky Problem! (solved, thanks Betel!)

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

Need a little experienced help on this one. For one thing, it continues to go infinite, so I have a counter to limit the loop, see below for more info.

Code: Select all

(setq mapAlchemyEngine2 (lambda (mapData)
  (block (sysToDo sysProcessedList startSys activeList doCount cond dblList)
	
	(setq startSys (sysGetData "Sys26" "startingPos"))
	(setq activeList (list startSys))
	(setq dblList activeList)
	(setq sysToDo (count activeList))
	
(loop (ls doCount 10)
  (block (sysItem) 
	(setq cond "True")
	(setq doCount (add doCount 1))	
	(setq sysItem (item activeList 0))
   (if (eq sysItem Nil)
	(setq sysToDo 0)
	(block Nil
	(setq sysProcessedList (lnkAppend sysProcessedList sysItem))
	
	(lnkRemove activeList 0 Nil)

	 (enumwhile mapData cond sysInfo
	   (block (infoID)
		(setq infoID (item sysInfo 0))
		(if (eq infoID sysItem)
		  (block (countList thisLink)
		    (setq countList (subtract (count sysInfo) 1))
		    (for i 1 countList
			(block (condT addFlag)
			  (setq condT "True")
			  (setq thisLink (item sysInfo i))
			  (enumwhile sysProcessedList condT checkItem
			    (if (eq checkItem thisLink)
				(block Nil
				(setq addFlag "No")
				(setq condT Nil)
				)
				(block Nil
				(setq addFlag "Yes")
				(setq condT Nil)
				)
			    )
			  )
			(if (eq addFlag "Yes")
			(block Nil
			(lnkAppend activeList thisLink)
			(lnkAppend dblList thisLink)
			)
			)
			)
		    )
		   (setq cond Nil)
		  )
		)
	   )
	 )
	)
  );end control if
  (setq sysToDo (count activeList))
  )
)
(sysSetData "Sys26" "testThis" sysProcessedList)	
mapData
  )

))
ok.. .this is supposed to be tracing a route in a 'map' for system 26.
What it gets is a map that looks something like this:

Code: Select all

mapData: (list
(list "SE" "Node47")
(list "Node47" "SE" "Node78")
(list "Node78" "Node47")


Where item 0 is a system itself, and the other items are linked systems.
So, from that sample SE links to Node47.
Now it is possible that it gets more 'invalid' links, but must trace the actual route or current network from the Start point SE through the links provided by the lists. So it must read SE -> Node 47; Node 47 -> Node 78 and arrive at a list "sysProcessedList" which would show only: (list SE Node47 Node78).

dblList is so I can look at the active list without any of its items removed.


For some reason it is generating multiple entries for sysProcessedList:
SE
47
47
47
78
78
78
78
Or something like that. I need to only put a unique node id on the list once- even if that ID shows up fifty times in the links in the list!
Last edited by Periculi on Sat May 17, 2008 4:41 pm, edited 1 time in total.
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

whoa.. I must be very dense.

how can I turn random lists like these:

(list A A A A B B B C D D D E E E )

(list A A B B B B B B C C C C C D E )

into this:

(list A B C D E)

in other words, how can I get a list with repeating items to only show unique items?

Edit- yippie! I figured that out.

Code: Select all

(setq mapCleanList (lambda (sysProcessedList)
(block (aList)
	(setq aList (list (item sysProcessedList 0)))
	(enum sysProcessedList thisID
		(block (cond flagger)
			(setq cond "True")
			(setq flagger "NoFlag")
			(enumwhile aList cond theSys
			  (if (eq thisID theSys)
				(block Nil
				(setq cond Nil)
				(setq flagger "NoFlag")
				)
				(block Nil
				(setq flagger "AddFlag")
				)
			  )
			)

	(if (eq flagger "AddFlag")
	(lnkAppend aList thisID)
	)

		)
	)
aList
)
))
User avatar
Psycholis
Militia Commander
Militia Commander
Posts: 298
Joined: Sun Mar 05, 2006 8:23 pm
Location: Missouri

Periculi, you're so tweaker.. I like how you solve most of your problems before most of us can even look at them. :)
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

I didn't solve this one yet. I only figured out how to reduce a list to uniques in a brutal fashion.
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

what is the format of mapData?
do you want it to set the processed list somewhere?
What do you want this to return?
I am thinking of making my own function for you. :D
Crying is not a proper retort!
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

Here's a sample with no tricks-

Code: Select all

		(setq mapData (list
		(list "SE" "Node47" "Node48")
		(list "Node47" "SE" "Node48" "Node78")
		(list "Node48" "Node47" "SE")
		(list "Node78" "Node47" "Node109")
		(list "Node109" "Node78")
		))
Maps are a list of lists. Each is (list [node ID] [link ID] [link ID] ...) where the first item is the actual system being defined and the links are the gates in that system.

Every system listed (item 0) would be available. A list of all these systems would be valid because they can all be reached, there aren't any random systems that may or may not be present. The viewer I have now shows this entire list as 'active all' which is to say, all the active systems on a user map.

Here's a sample which better represents the need for tracing the route-

Code: Select all

	(block (mapLevel)
		(setq mapData (list
;these are the starting positions possible
		(list "SE" "Node47")
		(list "Node15" "Node47")
		(list "Node17" "Node47")
;here is the next system that is linked
		(list "Node47" "Cond1" "Cond2")
;these are the next system set
		(list "Node78" "Node47" "Cond3")
		(list "Node79" "Node47" "Cond3")
;these are the next system set
		(list "Node110" "Cond2")
		(list "Node108" "Cond2")
		(list "Node109" "Cond2" "Node140")
;this is a bonus system that only Node109 gets
		(list "Node140" "Node109")
;and that's all
;this map generates a 4-5 system linear result
;with random start system - 1 of 3
;a connecting system 1 of 1
;and a random system - 1 of 2
;then an end system - 1 of 3
		
		))
All the 'Cond' are turned into a decision for which system of a set is used.
In this example a random starting point is chosen from SE, Node15, or Node17. In the game, the map viewer would only show the 'known' systems- so it isn't totally important to trace the network, but I want to figure out the list of systems that were used in order to do several things- A) view the active current systems in the network in a test viewer to inspect the network constructed, and B) know which systems are currently available in the game in order for map information to be sold from vendors.

Here is the system conditionals for that map:

Code: Select all

	(block (nodeLevel)
	(setq mapNodeCond (list 
		(list "Cond1" "getStart")
		(list "Cond2" "getOneEQ" "Node78" "Node79")
		(list "Cond3" "getOneEQ" "Node109" "Node108" "Node110")
		))
	(setq nodeLevel (sysSetData "Sys26" "nodeConds" mapNodeCond))
	)
Cond -itions are set up on a list, with their own unique ID (Cond1) and a conditional operator to make decisions: "getStart" = get the start point, "getOneEQ" = get one from the list that follows with equal odds between them. I am working out more of these, and 'higher' levels of operator decisions that can precede the Node Conds (not important for this discussion, as these all precede the mapData that needs to be traced for the network created)

After the decisions are made for the random links and systems we get the mapData as a 'hard links list'.

This example list then becomes something like:

Code: Select all

	(block (mapLevel)
		(setq mapData (list
		(list "SE" "Node47")
		(list "Node15" "Node47")
		(list "Node17" "Node47")
		(list "Node47" "SE" "Node78")
		(list "Node78" "Node47" "Node109")
		(list "Node79" "Node47" "Node109")
		(list "Node110" "Node78")
		(list "Node108" "Node78")
		(list "Node109" "Node78" "Node140")
		(list "Node140" "Node109")
;and that's all
;this map generates a 4-5 system linear result
;with random start system - 1 of 3
;a connecting system 1 of 1
;and a random system - 1 of 2
;then an end system - 1 of 3
		
		))
Which would play as a linear network [ SE<->Node47<->Node78<->Node109<->Node140 ] if you played it with those random Cond -itions chosen.

So, the network trace needs to start from the start system- let's say SE, which has a connection to Node47 (cond1 is for the start link), Cond2 is for either Node78 or Node79, so I figured that the links could be followed from inside the list to define the network after the Cond -itions are defined.

My viewer shows this entire 'active' list as a filtered set of systems from the Full topology data (all the systems available), which is all the listed systems, or it shows the 'game' view- which only allows you to see known systems (this can be used to accurately map, except you must get the systems known first).

Maps I make use only a few of the systems from the Full set- These are all the ones in the list there, and I call them 'Active' or Active All. But to see what a game is going to actually deliver to the player, I need a Current Network- or the links that are made from the starting point, without adding the 'dead' or unused links in as it does now.

So, this map should be resolved down to a set of systems that simply shows the links from the start point forward- excluding the optional systems that were not chosen. I figured that a loop function that traced the links and systems would work well for this.

Ideally the function will simply produce and save a list such as "currentNetwork" in "Sys26" system. (sysSetData "Sys26" "currentNetwork" theListWeMade) A simple list of the NodeID would suffice: (list "SE" "Node47" "Node78" Node109" "Node140")
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

hmm the cond things can be done before this is called right? (so we only have set links in there for checking)

what do you want to happen if there is more than one path? like (a b c d) and (a b e d) also what do you want to happen if there is a split like (a b c) and (a d e), just list them all in currentNetwork?
Crying is not a proper retort!
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

Well there will be branches and loops, etc., but we ignore the structure in favor of simply getting the links that can be reached from the start point. I believe that it would never matter because-

(list "SE" "Node47" "Node48") which is a branch-

-would define the available systems. As compared to-

(list "SE" "Node46" "Node48")

if they were chosen from the set [46 47 48].

So I don't think the network structure is as important as simply showing which systems of the available systems were used. All the systems used, either in a loop or a line will be unique IDs. We just want to find all the unique IDs connecting from the start point.
Yes?
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

Betelgeuse sent me a recursive function that traces the network map most wonderfully. It will be seen in action in the System26 mod!

Thanks! :D
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Gotta love those recursive functions. Nice work!
Post Reply