Logic Problem

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
I've got a logic problem, which I am obviously just not looking at correctly.

I've got a chain of buildings. Building A is replaced by building B and building C. Building B is replaced by building C.

A graphic representation:

Code:
Building A ---> Building B ---> Building C
             \ ----------------/
Now I need a function that will return TRUE or FALSE if the building is the next in the sequence in the chain. Given A, it should return TRUE for B and FALSE for C. Sounds easy? Let me complicate it with a new example:

Building A is replaced by Building B, Building C, Building D, and Building E. Building B is replaced by Building D. Building C is replaced by Building E.

graphic:

Code:
            / ---------------\
Building A ---> Building B ---> Building D
            \ ---> Building C ---> Building E
             \ ----------------/

This function given A should return TRUE for both Buildings B and C and FALSE for D and E.

I'm sure I should be able to work it out, but's half past midnight and I'm tired. Solutions to this problem would be appreciated.
 
Building A is replaced by building B and building C. Building B is replaced by building C. [...] Now I need a function that will return TRUE or FALSE if the building is the next in the sequence in the chain. Given A, it should return TRUE for B and FALSE for C.

I am confused. A is replaced by C; why should the function return false? I don't know what pointers you have, but if your buildings have a PrereqBuilding, then you just test if the second building has a PrereqBuilding which is the first building.
 
I am confused. A is replaced by C; why should the function return false? I don't know what pointers you have, but if your buildings have a PrereqBuilding, then you just test if the second building has a PrereqBuilding which is the first building.

I wish it was that simple, but they don't always have the prereq building. :sad:

Building B and C can be built w/o A.
 
How are you storing your data? If the later building doesn't have a pointer to the earlier one, then the earlier building must have a pointer to the later one. In that case it is even easier, because the next building in the sequence is whatever the earlier building is pointing to. I guess there is some complexity which hasn't come out in your post yet.
 
How are you storing your data? If the later building doesn't have a pointer to the earlier one, then the earlier building must have a pointer to the later one. In that case it is even easier, because the next building in the sequence is whatever the earlier building is pointing to. I guess there is some complexity which hasn't come out in your post yet.

The earlier building is pointing to ALL of the later buildings.
 
x = 0
List[0] = [Pointers from Param1]

While (List[x] != Empty) {
x++
List[x] = [Pointers from List[x-1]]
}

While (x > 0) {
List[0] = List[0] - List[x]
x--
}

Return (List[0].Contains(Param2))
 
Top Bottom