Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Treba mi za onaj 3ci, jos: BottomVerticalUp, RightHorizontalSearchToRight
- // Bottom - vertical search up
- int bottomI = i + 1;
- int bottomJ = j;
- if (iRange.Contains(bottomI) && jRange.Contains(bottomJ))
- {
- if (ReversiBoard[bottomI, bottomJ].BoardPieceStatus == BoardPieceStatus.EmptyTile)
- {
- int numberOfSpaces = SearchVerticallUp(i, j);
- if (numberOfSpaces > 0)
- {
- numberOfSpacesList.Add(numberOfSpaces);
- availableMoves.Add(ReversiBoard[bottomI, bottomJ]);
- }
- }
- }
- private int SearchVerticallUp(int bottomI, int bottomJ)
- {
- int counter = 0;
- bool activeUserTileFound = false;
- for (int i = bottomI; i > 0; i--)
- {
- if (ReversiBoard[i, bottomJ].BoardPieceStatus == BoardPieceStatus.OpponentOwned)
- {
- counter++;
- }
- if (ReversiBoard[i, bottomJ].BoardPieceStatus == BoardPieceStatus.ActivePlayerOwned)
- {
- activeUserTileFound = true;
- break;
- }
- }
- if (activeUserTileFound)
- return counter;
- return 0;
- }
- // Right - Horizontal search from left to right
- int rightI = i;
- int rightJ = j + 1;
- if (iRange.Contains(rightI) && jRange.Contains(rightJ))
- {
- if (ReversiBoard[rightI, rightJ].BoardPieceStatus == BoardPieceStatus.EmptyTile)
- {
- int numberOfSpaces = HorizontalSearchToRight(i, j);
- if (numberOfSpaces > 0)
- {
- numberOfSpacesList.Add(numberOfSpaces);
- availableMoves.Add(ReversiBoard[rightI, rightJ]);
- }
- }
- }
- private int HorizontalSearchToRight(int leftI, int leftJ)
- {
- int counter = 0;
- bool activeUserTileFound = false;
- for (int j = leftJ; j > 0; j--)
- {
- if (ReversiBoard[leftI, j].BoardPieceStatus == BoardPieceStatus.OpponentOwned)
- {
- counter++;
- }
- if (ReversiBoard[leftI, j].BoardPieceStatus == BoardPieceStatus.ActivePlayerOwned)
- {
- activeUserTileFound = true;
- break;
- }
- }
- if (activeUserTileFound)
- return counter;
- return 0;
- }
- // Just in case - bottom-left horizontal search left up
- int bottomRightI = i + 1;
- int bottomRightJ = j + 1;
- if (iRange.Contains(bottomRightI) && jRange.Contains(bottomRightJ))
- {
- if (ReversiBoard[bottomRightI, bottomRightJ].BoardPieceStatus == BoardPieceStatus.EmptyTile)
- {
- int numberOfSpaces = HorizontalSearchToRight(i, j);
- if (numberOfSpaces > 0)
- {
- numberOfSpacesList.Add(numberOfSpaces);
- availableMoves.Add(ReversiBoard[bottomRightI, bottomRightJ]);
- }
- }
- }
- private int SearchDiagonallyUp(int leftI, int leftJ)
- {
- int counter = 0;
- bool activeUserTileFound = false;
- for (int i = leftI; i > 0; i--)
- {
- for (int j = leftJ; j > 0; j--)
- {
- if (i == j)
- {
- if (ReversiBoard[i, j].BoardPieceStatus == BoardPieceStatus.OpponentOwned)
- {
- counter++;
- }
- if (ReversiBoard[i, j].BoardPieceStatus == BoardPieceStatus.ActivePlayerOwned)
- {
- activeUserTileFound = true;
- break;
- }
- }
- }
- if(activeUserTileFound)
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement