private SquareMove generateSquareToMoveHuman(Player i_CurrentPlayer, eSizeBoard i_SizeOfBoard, List <SquareMove> i_AvaiableVaildMoves, List <SquareMove> i_MustToDoMoves) { SquareMove moveFromClient = null; bool isValidMove = false; while (!isValidMove) { moveFromClient = UIUtilities.getValidSquareToMoveFromClient(i_CurrentPlayer, i_SizeOfBoard); if (moveFromClient == null) { break; } if (i_MustToDoMoves.Count > 0) { isValidMove = i_MustToDoMoves.Contains(moveFromClient); } else { isValidMove = i_AvaiableVaildMoves.Contains(moveFromClient); } } return(moveFromClient); }
internal void perfomSoliderAction(SquareMove i_PlayerChoise) { foreach (Soldier currentSoldier in m_CurrentPlayer.Soldiers) { if (currentSoldier.PlaceOnBoard.Equals(i_PlayerChoise.FromSquare)) { currentSoldier.PlaceOnBoard = i_PlayerChoise.ToSquare; UIUtilities.setCurrentMove(m_CurrentPlayer.PlayerName, currentSoldier.CharRepresent, i_PlayerChoise); checkAndSetKingSolider(currentSoldier); m_SoliderThatNeedToEatNextTurn = null; break; } } if (Math.Abs(i_PlayerChoise.ToSquare.Col - i_PlayerChoise.FromSquare.Col) == 2) { removeOtherPlayerSoliderFromBoard(i_PlayerChoise); setParamatersIfIsSoliderNeedToEatNextTurn(i_PlayerChoise.ToSquare); } if (m_OtherPlayer.Soldiers.Count == 0) { setGameStatus(m_CurrentPlayer); } }
private void removeOtherPlayerSoliderFromBoard(SquareMove i_PlayerChoise) { char rowOfOtherPlayerToRemove = i_PlayerChoise.FromSquare.Row; char colOfOtherPlayerToRemove = i_PlayerChoise.FromSquare.Col; calculateSquareotherPlayerToRemove(i_PlayerChoise.ToSquare.Row, i_PlayerChoise.FromSquare.Row, ref rowOfOtherPlayerToRemove); calculateSquareotherPlayerToRemove(i_PlayerChoise.ToSquare.Col, i_PlayerChoise.FromSquare.Col, ref colOfOtherPlayerToRemove); m_OtherPlayer.RemoveSolider(new Square(rowOfOtherPlayerToRemove, colOfOtherPlayerToRemove)); }
private SquareMove getVaildMoveFromSpesificSide(Soldier i_CurrentSolider, int i_RowMoveUpOrDown, int i_ColMoveRightOrLeft) { char?kingOfCurrentPlayer = null; char?regularOfCurrentPlayer = null; switch (m_CurrentPlayer.NumberOfPlayer) { case eNumberOfPlayer.First: { kingOfCurrentPlayer = Soldier.k_FirstPlayerKing; regularOfCurrentPlayer = Soldier.k_FirstPlayerRegular; break; } case eNumberOfPlayer.Second: { kingOfCurrentPlayer = Soldier.k_SecondPlayerKing; regularOfCurrentPlayer = Soldier.k_SecondPlayerRegular; break; } } SquareMove returnFinalSquareToMove = null; Square squareToMove = new Square((char)(i_CurrentSolider.PlaceOnBoard.Row + i_RowMoveUpOrDown), (char)(i_CurrentSolider.PlaceOnBoard.Col + i_ColMoveRightOrLeft)); char soliderCharOfSquare = whoIsInSquare(squareToMove); ////If the square is empty-> move to this square ////Else if the square is occupied and have the other player solider -> check if he can eat if (soliderCharOfSquare == Soldier.k_EmptySolider) { returnFinalSquareToMove = new SquareMove(i_CurrentSolider.PlaceOnBoard, squareToMove); } else if (soliderCharOfSquare != kingOfCurrentPlayer && soliderCharOfSquare != regularOfCurrentPlayer) { if ((i_RowMoveUpOrDown == m_MovmentOption.MoveDown && i_CurrentSolider.PlaceOnBoard.Row < m_MovmentOption.EndRow - 1) || (i_RowMoveUpOrDown == m_MovmentOption.MoveUp && i_CurrentSolider.PlaceOnBoard.Row > MovementOptions.k_StartRow + 1)) { if ((i_ColMoveRightOrLeft == m_MovmentOption.MoveLeft && i_CurrentSolider.PlaceOnBoard.Col > MovementOptions.k_StartCol + 1) || (i_ColMoveRightOrLeft == m_MovmentOption.MoveRight && i_CurrentSolider.PlaceOnBoard.Col < m_MovmentOption.EndCol - 1)) { squareToMove = new Square((char)(i_CurrentSolider.PlaceOnBoard.Row + (i_RowMoveUpOrDown * 2)), (char)(i_CurrentSolider.PlaceOnBoard.Col + (i_ColMoveRightOrLeft * 2))); soliderCharOfSquare = whoIsInSquare(squareToMove); if (soliderCharOfSquare == Soldier.k_EmptySolider) { returnFinalSquareToMove = new SquareMove(i_CurrentSolider.PlaceOnBoard, squareToMove, true); } } } } return(returnFinalSquareToMove); }
public static SquareMove getValidSquareToMoveFromClient(Player i_Player, eSizeBoard i_SizeOfBoard) { String moveFromClientS; SquareMove moveFromClient = null; Console.WriteLine(i_Player.PlayerName + "'s turn:"); do { moveFromClientS = Console.ReadLine(); if (moveFromClientS.Equals("Q")) { moveFromClient = null; break; } }while (!SquareMove.Parse(moveFromClientS, out moveFromClient, i_SizeOfBoard)); return(moveFromClient); }
private void nextTurn() { List <SquareMove> mustToDoMoves = new List <SquareMove>(); List <SquareMove> availableVaildMoves = generateValidMovesOfPlayer(m_CurrentPlayer); if (!checkValidMove(availableVaildMoves)) { determineResultGame(); } else { initializeForMustMoves(availableVaildMoves, ref mustToDoMoves); SquareMove playerChoise = generateSquareToMove(availableVaildMoves, mustToDoMoves); if (playerChoise == null) { m_GameStatus = eGameStatus.QExit; } else { perfomSoliderAction(playerChoise); } } }
private void performMoveAndSwitchPlayers(CheckerBoard i_Original, out CheckerBoard o_CopyOfCheckerBoard, SquareMove i_SquareToMoveInNewBoard) { o_CopyOfCheckerBoard = new CheckerBoard(i_Original); o_CopyOfCheckerBoard.perfomSoliderAction(i_SquareToMoveInNewBoard); o_CopyOfCheckerBoard.setParamatersForNextTurn(); }
public static void setCurrentMove(String i_PlayerName, char i_RepresentChar, SquareMove i_SquareMove) { MovementStatement = String.Format("{0}'s move was ({1}) : {2}", i_PlayerName, i_RepresentChar, i_SquareMove.ToString()); }