Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Calculate the delta on the evaluation value for this sudoku, were we to swap the value located at (x0,y0) with
- /// the value located at (x1,y1). This method will not actually swap anything yet.
- /// </summary>
- /// <param name="x0">X-coordinate for the first value</param>
- /// <param name="y0">Y-coordinate for the first value</param>
- /// <param name="x1">X-coordinate for the second value</param>
- /// <param name="y1">Y-coordinate for the second value</param>
- /// <returns>The evaluation difference between the sudoku and a sudoku where the values have been swapped</returns>
- public int CalculateSwapEvaluation(int x0, int y0, int x1, int y1)
- {
- //First we put everything in arrays so that, before the swap, v[i] resides at (x[i],y[i]) for i in {0,1}.
- //After the swap, for i in {0,1}, v[1-i] resides at (x[i],y[i]).
- int[] v = new int[2] { Data[x0, y0].Value, Data[x1, y1].Value };
- int[] x = new int[2] { x0, x1 };
- int[] y = new int[2] { y0, y1 };
- int d = 0;
- for(int i = 0; i < 2; i++)
- {
- d += (--dc[x[i]][v[i]] == 0) ? 1 : 0;
- d += (--dr[y[i]][v[i]] == 0) ? 1 : 0;
- d -= (++dc[x[i]][v[1 - i]] == 1) ? 1 : 0;
- d -= (++dr[y[i]][v[1 - i]] == 1) ? 1 : 0;
- }
- for(int i = 0; i < 2; i++)
- {
- dc[x[i]][v[i]]++;
- dr[y[i]][v[i]]++;
- dc[x[i]][v[1 - i]]--;
- dc[y[i]][v[1 - i]]--;
- }
- return d;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement