/** * This method receives a Move object and if the move is valid then it moves the soldier from the current location to the target location * of the move, if the soldier is supposed to be a king then it turns the soldier into a king, handles jumping of the soldier over another soldier * and finally updates the winner's score if the opponent does not have any moves left. */ public void MakeMove(Move i_Move) { if (IsMoveValid(i_Move)) { Soldier soldier = m_CheckersBoard.GetSoldierAt(i_Move.CurrentLocation); m_CheckersBoard.MoveSoldier(i_Move); // Moving the soldier to the target location in the board. // If the move object's player is null, then we set that the move was played by the current player (relevant to the next move validation). if (i_Move.Player == null) { i_Move.Player = GetCurrentPlayer(); } if (ShouldBecomeKing(soldier)) { soldier.MakeKing(); i_Move.Player.CurrentGameScore += k_KingScore - k_NormalSoldierScore; } m_LastMove = i_Move; // Setting the last played move to be the current move. validJumpMoveHandler(i_Move); // If the move was a jump move then we should handle everything that is related to it. OnMoved(i_Move); Player opponentPlayer = i_Move.Player == m_PlayerOne ? m_PlayerTwo : m_PlayerOne; // If the opponent player doesn't have moves left then the game has ended. if (!PlayerHasMoves(opponentPlayer)) { // If the current player has moves, then it means that the current player has won. if (PlayerHasMoves(i_Move.Player)) { UpdateWinnerScore(i_Move.Player); } OnGameEnded(); } } }