Advertisement
uraharadono

Treci graph

Apr 9th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 KB | None | 0 0
  1. // Treba mi za onaj 3ci, jos: BottomVerticalUp, RightHorizontalSearchToRight
  2.  
  3. // Bottom - vertical search up
  4. int bottomI = i + 1;
  5. int bottomJ = j;
  6. if (iRange.Contains(bottomI) && jRange.Contains(bottomJ))
  7. {
  8.     if (ReversiBoard[bottomI, bottomJ].BoardPieceStatus == BoardPieceStatus.EmptyTile)
  9.     {
  10.         int numberOfSpaces = SearchVerticallUp(i, j);
  11.         if (numberOfSpaces > 0)
  12.         {
  13.             numberOfSpacesList.Add(numberOfSpaces);
  14.             availableMoves.Add(ReversiBoard[bottomI, bottomJ]);
  15.         }
  16.     }
  17. }
  18.  
  19. private int SearchVerticallUp(int bottomI, int bottomJ)
  20. {
  21.     int counter = 0;
  22.     bool activeUserTileFound = false;
  23.     for (int i = bottomI; i > 0; i--)    
  24.     {
  25.         if (ReversiBoard[i, bottomJ].BoardPieceStatus == BoardPieceStatus.OpponentOwned)
  26.         {
  27.             counter++;
  28.         }
  29.         if (ReversiBoard[i, bottomJ].BoardPieceStatus == BoardPieceStatus.ActivePlayerOwned)
  30.         {
  31.             activeUserTileFound = true;
  32.             break;
  33.         }
  34.     }
  35.  
  36.     if (activeUserTileFound)
  37.         return counter;
  38.     return 0;
  39. }
  40.  
  41. // Right - Horizontal search from left to right
  42. int rightI = i;
  43. int rightJ = j + 1;
  44. if (iRange.Contains(rightI) && jRange.Contains(rightJ))
  45. {
  46.     if (ReversiBoard[rightI, rightJ].BoardPieceStatus == BoardPieceStatus.EmptyTile)
  47.     {
  48.         int numberOfSpaces = HorizontalSearchToRight(i, j);
  49.         if (numberOfSpaces > 0)
  50.         {
  51.             numberOfSpacesList.Add(numberOfSpaces);
  52.             availableMoves.Add(ReversiBoard[rightI, rightJ]);
  53.         }
  54.     }
  55. }
  56.  
  57. private int HorizontalSearchToRight(int leftI, int leftJ)
  58. {
  59.     int counter = 0;
  60.     bool activeUserTileFound = false;
  61.  
  62.     for (int j = leftJ; j > 0; j--)
  63.     {
  64.         if (ReversiBoard[leftI, j].BoardPieceStatus == BoardPieceStatus.OpponentOwned)
  65.         {
  66.             counter++;
  67.         }
  68.         if (ReversiBoard[leftI, j].BoardPieceStatus == BoardPieceStatus.ActivePlayerOwned)
  69.         {
  70.             activeUserTileFound = true;
  71.             break;
  72.         }
  73.     }
  74.            
  75.     if (activeUserTileFound)
  76.         return counter;
  77.     return 0;
  78. }
  79.  
  80.  
  81. // Just in case - bottom-left horizontal search left up
  82. int bottomRightI = i + 1;
  83. int bottomRightJ = j + 1;
  84. if (iRange.Contains(bottomRightI) && jRange.Contains(bottomRightJ))
  85. {
  86.     if (ReversiBoard[bottomRightI, bottomRightJ].BoardPieceStatus == BoardPieceStatus.EmptyTile)
  87.     {
  88.         int numberOfSpaces = HorizontalSearchToRight(i, j);
  89.         if (numberOfSpaces > 0)
  90.         {
  91.             numberOfSpacesList.Add(numberOfSpaces);
  92.             availableMoves.Add(ReversiBoard[bottomRightI, bottomRightJ]);
  93.         }
  94.     }
  95. }
  96.  
  97. private int SearchDiagonallyUp(int leftI, int leftJ)
  98. {
  99. int counter = 0;
  100. bool activeUserTileFound = false;
  101.  
  102. for (int i = leftI; i > 0; i--)
  103. {
  104.     for (int j = leftJ; j > 0; j--)
  105.     {
  106.         if (i == j)
  107.         {
  108.             if (ReversiBoard[i, j].BoardPieceStatus == BoardPieceStatus.OpponentOwned)
  109.             {
  110.                 counter++;
  111.             }
  112.             if (ReversiBoard[i, j].BoardPieceStatus == BoardPieceStatus.ActivePlayerOwned)
  113.             {
  114.                 activeUserTileFound = true;
  115.                 break;
  116.             }
  117.         }
  118.     }
  119.     if(activeUserTileFound)
  120.         break;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement