title: Variable mysteriously keeps changing after recursive algorithm
body: <p>I cant figure out why a completely unrelated variable gets changed after every time I run a recursive algorithm. There is absolutely no place where I in any way assign new values to this variable, but still, the recursive method runs and the variable gets changed.</p>
  
  <p>The program I wrote is playing connect four. It has a 'board' object that stores where the players chips are, and a method that evaluate how many possible connect fours the person can get and assigns a score to that configuration.</p>
  
  <p>The recursive algorithm is designd to find the optimal sequence of chips. It makes a copy of the board. Adds a chip to one of several possible locations (Hence the recursion). And Recurses. Once it reaches the base case it finds the 'score' that the hypothetical configuration of chips would recieve. As it backs out of the algorithm it selects the path that gives the greates number of points.</p>
  
  <p>The problem is that the original copy of the board keeps getting overwritten? The program goes something like this. (generalized)</p>
  
  <pre><code>int[] FindBestPath(Board OrginalBoard, int Depth)
  {
    Board TempBoard = OriginalBoard;
    if(Depth &gt; 0)
      for(x of many possible modifications)
      {
        Tempboard.MakeModification(x);
        Depth--;
        Score = FindBestPath(TempBoard, Depth);
        if(Score &gt; highestScoreYet)
        {
             highestScoreYet = Score;
             BestModification = x;
        }
      }
    else if(Depth == 0)
      Return new int[2] {ConfigurationScore(TempBoard), -1};
  
    return new int[2] {HighestScoreYet, BestModification};
  }
  </code></pre>
  
  <p>Why does the 'Orginal Board' that I pass when I actually call the recursive algorithm get modification 'x' in all possible ways? I didn't add a 'ref' statement or anything so shouldn't the orginal be preserved?</p>
  
  <p>Is there some known oddity about object behavior and recursive algorithms? Can I, in Microsoft C# Express 2010, somehow breakpoint at the currently unknown moment when the orginal board object gets modified?</p>
  
  <p>Thank you.</p>