All pastes #476094 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-07 21:37 UTC
rendered paste body
private void EliminateDuplicates(List<Node> list, List<Node> states)

		{
			int statesSize = states.Count;

			for( int j = 0; j < statesSize; j++ )

			{
				Console.WriteLine(states.Count);
				Console.WriteLine(j);
				

				Node temp = states[j];

				foreach (Node n in list)
				{

					if (n.NodeState == temp.NodeState) 
					{

						if (n.NodeHeuristic < temp.NodeHeuristic) 
						{

							states.RemoveAt(j);

							break;

						}

						else {

							list.Remove(n);

							break;

						}

					}

				}

			}

		}

My program with this function throws an exception in this function:

Exception data:

Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
  at System.Collections.Generic.List`1[AStar8Puzzle.Node].get_Item (Int32 ) [0x00024] in /build/buildd/mono-1.2.3.1/mcs/class/corlib/System.Collections.Generic/List.cs:546 
  at AStar8Puzzle.AStar8Puzzle.EliminateDuplicates (System.Collections.Generic.List`1 list, System.Collections.Generic.List`1 states) [0x0001f] in /home/bojan/programming/AStar8Puzzle/AStar8Puzzle/Main.cs:65 
  at AStar8Puzzle.AStar8Puzzle.SolvePuzzle (System.String startingConfig, Boolean printAll) [0x000aa] in /home/bojan/programming/AStar8Puzzle/AStar8Puzzle/Main.cs:45 
  at AStar8Puzzle.AStar8Puzzle.Main (System.String[] args) [0x0000c] in /home/bojan/programming/AStar8Puzzle/AStar8Puzzle/Main.cs:137 


However, immediately prior, Console.WriteLine(states.Count) and Console.WriteLine(j) are both 1. So...what exactly is out of range?