a complicated ArrayList function

Hi there,

i have been working on this function for 5 hours now, and i can't get it to work. It's a little bit complicated so let me first explain what this is about:

1. As a little exam in my studies i have to program a halma console game with KI an stuff.
2. Everything is finished and works except for the Move-Calculation.
3. A Move is a Move from Field a to Field b which a player can perform in one round based on the game rules (Careful: We are not using the standard halma rules, we use different ones).
4. Class Move consists of the Starting Cell where the Figure before the Move stands and a target Cell where the figure will stay on at the Move end. It may include an Array of serveral Cells, the stop cells which the figure passes from start -> target since several jumps can be performed in one Move.

Valid Examples for Moves:
a -> b (From Field a to Field b)
d -> f through g,h,i (From Field d to Field f through the Field g,h,i

My Move Calculation where all possible Moves are calculated for a given figure consists of 2 parts. An expand() function which will generate all possible moves (works perfectly) and a jumpFix() function which isn't working properly. Example:

This is however not finished, because the first 3 Moves are actually 1 Move. Because the player can Move from a -> d in one turn because those 3 are consecutive Move. The fixed Move would look like that:

a -> d through b,c

jumpFix() is also perfectly working for that situation, however there is one specific situation when it doesn't work. Let's say we have this situation.

a -> b
b -> c
c -> d
b -> e
e -> f
f -> g
s -> t

Then the only valid jumpFix() output would be:

a -> d through b,c
a -> g through b,e,f
s -> t

However i can not get it to work yet. Somebody got an idea? Note: It definitely needs to be iterative, not rekursive else i would get an StackoverflowError.

If anybody has a good idea how to implement the special case where a Move splits into 2 or more branches and jumpFix() able to handle this case, i would be very glad. I spent 5 hours on that and can not figure it out at the Moment.

Re: a complicated ArrayList function

How are you trying to debug the code? If you know what the code should be doing, looking at the values of the variables as it executes should help you understand what is wrong.

Or is this a finding the right algorithm problem?

The algorithm is doing what it is programmed for. However when we programmed that function we didn't think of that special case where a Move could split into 2 different Moves. So yes, finding the right algorithm is the problem. I can not think of an iterative way to do it right now. Any help would be appreciated.