Advertisement
waqar_107

Untitled

Dec 2nd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. int linearConflict(node u, node g)
  2. {
  3. int cnt=0, tj, tk;
  4. bool f;
  5. pp temp[u.n * u.n];
  6.  
  7. for(int i = 0; i< u.n; i++)
  8. {
  9. for(int j=0 ; j < u.n; j++)
  10. temp[g.board[i][j]] = {i, j};
  11. }
  12.  
  13. //conflict counting in the rows
  14. for(int i = 0; i< u.n; i++)
  15. {
  16. for(int j = 0; j < u.n - 1; j++)
  17. {
  18. tj = u.board[i][j];
  19. if(tj == 0)
  20. continue;
  21.  
  22. for(int k = j + 1; k < u.n; k++)
  23. {
  24. tk = u.board[i][k];
  25. if(tk == 0)
  26. continue;
  27.  
  28. //check if tj and tk are in goal row, then if tj is in right of tk
  29. if(temp[tj].first == i && temp[tk].first == i && temp[tj].second > temp[tk].second)
  30. cnt++;
  31. }
  32. }
  33.  
  34. }
  35.  
  36. //conflict counting in the columns
  37. for(int i = 0; i< u.n; i++)
  38. {
  39. for(int j = 0; j < u.n - 1; j++)
  40. {
  41. tj = u.board[j][i];
  42. if(tj == 0)
  43. continue;
  44.  
  45. for(int k = j + 1; k < u.n; k++)
  46. {
  47. tk = u.board[k][i];
  48. if(tk == 0)
  49. continue;
  50.  
  51. //check if tj and tk are in goal column, then if tj is downwards wrt tk
  52. if(temp[tj].second == i && temp[tk].second == i && temp[tj].first > temp[tk].first)
  53. cnt++;
  54. }
  55. }
  56. }
  57.  
  58. return cnt;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement