private static int countHowManyMovesAvailable(GameBoard io_GameBoard, ref bool io_MadeEatMove, ref Piece io_EaterPiece, ref Vector2 io_StartLocation, ref string o_Move) { int numOfAvailableMoves = 0; Vector2 currLocation = new Vector2(0, 0), nextLocation = new Vector2(0, 0); Vector2 eatLocation = new Vector2(0, 0); Piece eaterPiece; for (int i = 0; i < io_GameBoard.BoardHeight; i++) { currLocation.GetRow = i; for (int j = 0; j < io_GameBoard.BoardHeight; j++) { currLocation.GetColumn = j; if (io_GameBoard[currLocation] != null) { if (io_GameBoard[currLocation].GetPieceType == 'O' || io_GameBoard[currLocation].GetPieceType == 'U') { if (i + 1 <= io_GameBoard.BoardHeight - 1 && j - 1 >= 0) { nextLocation.GetColumn = j - 1; nextLocation.GetRow = i + 1; eatLocation.GetColumn = j - 2; eatLocation.GetRow = i + 2; eaterPiece = new Piece(io_GameBoard[currLocation].GetPieceType, currLocation); if (i + 2 <= io_GameBoard.BoardHeight - 1 && j - 2 >= 0) { if (io_GameBoard[eatLocation] == null) { io_MadeEatMove = eaterPiece.TryEat(false, eatLocation, io_GameBoard); } } if (!io_MadeEatMove) { if (io_GameBoard[nextLocation] == null) { ++numOfAvailableMoves; } } else { io_EaterPiece = io_GameBoard[eatLocation]; io_StartLocation = eaterPiece.GetLocation; break; } } if (i + 1 <= io_GameBoard.BoardHeight - 1 && j + 1 <= io_GameBoard.BoardHeight - 1) { nextLocation.GetColumn = j + 1; nextLocation.GetRow = i + 1; eatLocation.GetColumn = j + 2; eatLocation.GetRow = i + 2; eaterPiece = new Piece(io_GameBoard[currLocation].GetPieceType, currLocation); if (i + 2 <= io_GameBoard.BoardHeight - 1 && j + 2 <= io_GameBoard.BoardHeight - 1) { if (io_GameBoard[eatLocation] == null) { io_MadeEatMove = eaterPiece.TryEat(false, eatLocation, io_GameBoard); } } if (!io_MadeEatMove) { if (io_GameBoard[nextLocation] == null) { ++numOfAvailableMoves; } } else { io_EaterPiece = io_GameBoard[eatLocation]; io_StartLocation = eaterPiece.GetLocation; break; } } } } if (io_GameBoard[currLocation] != null) { if (io_GameBoard[currLocation].GetPieceType == 'U') { if (i - 1 >= 0 && j - 1 >= 0) { nextLocation.GetColumn = j - 1; nextLocation.GetRow = i - 1; eatLocation.GetColumn = j - 2; eatLocation.GetRow = i - 2; eaterPiece = new Piece(io_GameBoard[currLocation].GetPieceType, currLocation); if (i - 2 >= 0 && j - 2 >= 0) { if (io_GameBoard[eatLocation] == null) { io_MadeEatMove = eaterPiece.TryEat(false, eatLocation, io_GameBoard); } } if (!io_MadeEatMove) { if (io_GameBoard[nextLocation] == null) { ++numOfAvailableMoves; } } else { io_EaterPiece = io_GameBoard[eatLocation]; io_StartLocation = eaterPiece.GetLocation; break; } } if (i - 1 >= 0 && j + 1 <= io_GameBoard.BoardHeight - 1) { nextLocation.GetColumn = j + 1; nextLocation.GetRow = i - 1; eatLocation.GetColumn = j + 2; eatLocation.GetRow = i - 2; eaterPiece = new Piece(io_GameBoard[currLocation].GetPieceType, currLocation); if (i - 2 >= 0 && j + 2 <= io_GameBoard.BoardHeight - 1) { if (io_GameBoard[eatLocation] == null) { io_MadeEatMove = eaterPiece.TryEat(false, eatLocation, io_GameBoard); } } if (!io_MadeEatMove) { if (io_GameBoard[nextLocation] == null) { ++numOfAvailableMoves; } } else { io_EaterPiece = io_GameBoard[eatLocation]; io_StartLocation = eaterPiece.GetLocation; break; } } } } } if (io_MadeEatMove) { break; } } return(numOfAvailableMoves); }
public static bool CheckMove(Piece i_CurrentPiece, Vector.Vector2 i_Destinition, GameBoard io_GameBoard, ref bool io_HasAnotherEatMove, ref bool o_PrintMustEatError, bool i_IsPcMove, ref Vector2 o_PcMoveLocation) { bool result = false, hasMoved = false, didEat = false, isEatMove, isGenericEatMoveAvailable = false; Vector2 pcStartMoveLocation = new Vector2(-1, -1); o_PrintMustEatError = false; if (!i_IsPcMove) { if (i_CurrentPiece != null) { if (CheckBordersOfMove(i_CurrentPiece.GetLocation, i_Destinition, io_GameBoard.BoardHeight) && i_CurrentPiece.GetGroup == s_currentPlayerGroup) { isEatMove = didEat = i_CurrentPiece.TryEat(false, i_Destinition, io_GameBoard); if (!isEatMove) { isGenericEatMoveAvailable = isEatMoveAvailable(io_GameBoard, (Piece.eSoldierTypes)i_CurrentPiece.GetPieceType); if (isGenericEatMoveAvailable) { o_PrintMustEatError = true; result = false; } } if (!isGenericEatMoveAvailable) { if (didEat) { io_HasAnotherEatMove = isSpecificEatMoveAvailable(io_GameBoard, io_GameBoard[i_Destinition]); if (!io_HasAnotherEatMove) { result = true; } } if ((!io_HasAnotherEatMove || isEatMove) && !didEat) { hasMoved = i_CurrentPiece.Move(i_Destinition, io_GameBoard); result = hasMoved || didEat; } else if (io_HasAnotherEatMove && !isEatMove) { o_PrintMustEatError = true; } if (io_HasAnotherEatMove) { result = !true; } } } } } else { o_PcMoveLocation = MakePcRandomMove(io_GameBoard, ref hasMoved, ref io_HasAnotherEatMove, out pcStartMoveLocation); if (!hasMoved || io_HasAnotherEatMove) { result = false; } else { result = true; } } return(result); }
public static bool ExeAllPcEatMovesAvailableToCurrentLocation(GameBoard i_GameBoard, Piece i_CurrentPiece) { bool result = true; Vector2 currentLocation = i_CurrentPiece.GetLocation; Vector2 dest1, dest2, dest3, dest4; int row, column; row = currentLocation.GetRow; column = currentLocation.GetColumn; dest1 = new Vector2(currentLocation.GetColumn + 2, currentLocation.GetRow + 2); dest2 = new Vector2(currentLocation.GetColumn - 2, currentLocation.GetRow + 2); dest3 = new Vector2(currentLocation.GetColumn + 2, currentLocation.GetRow - 2); dest4 = new Vector2(currentLocation.GetColumn - 2, currentLocation.GetRow - 2); if (i_CurrentPiece.TryEat(!true, dest1, i_GameBoard)) { i_CurrentPiece.GetLocation = dest1; } else if (i_CurrentPiece.TryEat(!true, dest2, i_GameBoard)) { i_CurrentPiece.GetLocation = dest2; } else if (i_CurrentPiece.TryEat(!true, dest3, i_GameBoard)) { i_CurrentPiece.GetLocation = dest3; } else if (i_CurrentPiece.TryEat(!true, dest4, i_GameBoard)) { i_CurrentPiece.GetLocation = dest4; } else { result = !true; } return(result); }