Advertisement
Guest User

Untitled

a guest
May 26th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /// <summary>
  2. /// Calculate the delta on the evaluation value for this sudoku, were we to swap the value located at (x0,y0) with
  3. /// the value located at (x1,y1). This method will not actually swap anything yet.
  4. /// </summary>
  5. /// <param name="x0">X-coordinate for the first value</param>
  6. /// <param name="y0">Y-coordinate for the first value</param>
  7. /// <param name="x1">X-coordinate for the second value</param>
  8. /// <param name="y1">Y-coordinate for the second value</param>
  9. /// <returns>The evaluation difference between the sudoku and a sudoku where the values have been swapped</returns>
  10. public int CalculateSwapEvaluation(int x0, int y0, int x1, int y1)
  11. {
  12. //First we put everything in arrays so that, before the swap, v[i] resides at (x[i],y[i]) for i in {0,1}.
  13. //After the swap, for i in {0,1}, v[1-i] resides at (x[i],y[i]).
  14. int[] v = new int[2] { Data[x0, y0].Value, Data[x1, y1].Value };
  15. int[] x = new int[2] { x0, x1 };
  16. int[] y = new int[2] { y0, y1 };
  17. int d = 0;
  18. for(int i = 0; i < 2; i++)
  19. {
  20. d += (--dc[x[i]][v[i]] == 0) ? 1 : 0;
  21. d += (--dr[y[i]][v[i]] == 0) ? 1 : 0;
  22. d -= (++dc[x[i]][v[1 - i]] == 1) ? 1 : 0;
  23. d -= (++dr[y[i]][v[1 - i]] == 1) ? 1 : 0;
  24. }
  25. for(int i = 0; i < 2; i++)
  26. {
  27. dc[x[i]][v[i]]++;
  28. dr[y[i]][v[i]]++;
  29. dc[x[i]][v[1 - i]]--;
  30. dc[y[i]][v[1 - i]]--;
  31. }
  32. return d;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement