Ejemplo n.º 1
0
        // Initializes the game - players and board size
        public void InitializeGameLogic(
            CheckersGameBoard.eBoardSize i_BoardSize, 
            string i_Player1Name,
            string i_Player2Name,
            bool i_IsPlayer2Human)
        {
            const bool v_Human = true;

            initializeBoard(i_BoardSize);
            m_Player1 = new PlayerInfo(i_Player1Name, v_Human, ePlayerTag.First);
            m_Player2 = new PlayerInfo(i_Player2Name, i_IsPlayer2Human, ePlayerTag.Second);
            m_CurrPlayerTurn = m_Player1;
            buildPlayersPiecesList();
        }
Ejemplo n.º 2
0
 private void addScore(PlayerInfo i_Player)
 {
     i_Player.Score += numOfSoldiers(i_Player) - numOfSoldiers(enemyPlayer(i_Player));
 }
Ejemplo n.º 3
0
 public void ResetGame()
 {
     m_CheckersBoard.InitializePiecesOnBoard();
     buildPlayersPiecesList();
     this.m_CurrPlayerTurn = this.m_Player1;
 }
Ejemplo n.º 4
0
 public GameOverEventArgs(PlayerInfo i_PlayerInfo1, PlayerInfo i_PlayerInfo2, bool i_Tie)
 {
     StrongerPlayer = i_PlayerInfo1;
     WeakerPlayer = i_PlayerInfo2;
     Tie = i_Tie;
 }
Ejemplo n.º 5
0
 private List<Piece> getPlayerPiecesList(PlayerInfo i_Player)
 {
     return i_Player == m_Player1 ? m_Player1PiecesList : m_Player2PiecesList;
 }
Ejemplo n.º 6
0
 // Returns the enemy playerInfo of a current player
 private PlayerInfo enemyPlayer(PlayerInfo i_Player)
 {
     return i_Player == m_Player1 ? m_Player2 : m_Player1;
 }
Ejemplo n.º 7
0
 // Goes through the pieces list and inserts all legal moves of every piece into a list (altogether)
 private void fillLegalMovesList(PlayerInfo i_PlayerForLegalMoves, bool i_OnlyCaptureMoves)
 {
     r_CurrentlyLegalMoves.Clear();
     List<Piece> currList = getPlayerPiecesList(i_PlayerForLegalMoves);
     if (m_FirstMoveThisTurn)
     {
         foreach (Piece piece in currList)
         {
             piece.AddLegalMovesToList(r_CurrentlyLegalMoves, m_CheckersBoard, i_OnlyCaptureMoves);
         }
     }
     else
     {
         m_LastMovingPiece.AddLegalMovesToList(r_CurrentlyLegalMoves, m_CheckersBoard, i_OnlyCaptureMoves);
     }
 }
Ejemplo n.º 8
0
 private void addScore(PlayerInfo i_Player)
 {
     i_Player.Score += numOfSoldiers(i_Player) - numOfSoldiers(enemyPlayer(i_Player));
 }
Ejemplo n.º 9
0
 // Removes the piece from the current game
 private void removePieceFromPosition(PlayerInfo i_CurrPlayerTurn, Position i_PiecePosition)
 {
     List<Piece> playerPieceList = getPlayerPiecesList(i_CurrPlayerTurn);
     Piece pieceToRemove = getPieceByPosition(i_CurrPlayerTurn, i_PiecePosition);
     pieceToRemove.RemovePiece(m_CheckersBoard);
     playerPieceList.Remove(pieceToRemove);
 }
Ejemplo n.º 10
0
        private void makeMachineMove()
        {
            const bool v_OnlyCaptureMoves = true;
            if (m_FirstMoveThisTurn)
            {
                // int the middle of capture moves series
                fillLegalMovesList(m_CurrPlayerTurn, v_OnlyCaptureMoves);
                if (!r_CurrentlyLegalMoves.Any())
                {
                    fillLegalMovesList(m_CurrPlayerTurn, !v_OnlyCaptureMoves);
                }
            }
            else
            {
                m_LastMovingPiece.AddLegalMovesToList(r_CurrentlyLegalMoves, m_CheckersBoard, v_OnlyCaptureMoves);
            }

            if (r_CurrentlyLegalMoves.Any())
            {
                int randomListIndex = new Random().Next(0, r_CurrentlyLegalMoves.Count);
                Move machineCurrMove = r_CurrentlyLegalMoves.ElementAt(randomListIndex);
                eAction lastAction = applyMove(machineCurrMove);
                r_CurrentlyLegalMoves.Clear();
                m_LastMovingPiece.AddLegalMovesToList(r_CurrentlyLegalMoves, m_CheckersBoard, v_OnlyCaptureMoves);
                if (lastAction == eAction.Capture && r_CurrentlyLegalMoves.Any())
                {
                    m_FirstMoveThisTurn = false;
                    makeMachineMove();
                }
                else
                {
                    m_FirstMoveThisTurn = true;
                    m_CurrPlayerTurn = enemyPlayer(m_CurrPlayerTurn);
                }
            }
        }
Ejemplo n.º 11
0
        public void PlayRound(Move i_MoveToApply)
        {
	        if (isMoveValid(i_MoveToApply))
	        {
	            const bool v_OnlyCaptureMoves = true;
	            eAction lastAction = applyMove(i_MoveToApply);
                r_CurrentlyLegalMoves.Clear();
                m_LastMovingPiece.AddLegalMovesToList(r_CurrentlyLegalMoves, m_CheckersBoard, v_OnlyCaptureMoves);
	            if (lastAction == eAction.Capture && r_CurrentlyLegalMoves.Any()) 
	            {
                    // the player keeping the turn, but we update that it will not be the first move, as in series of capture moves
	                m_FirstMoveThisTurn = false;
	            }
	            else
	            {
                    // turn goes to the next player
	                m_CurrPlayerTurn = enemyPlayer(m_CurrPlayerTurn);
	                m_FirstMoveThisTurn = true;
	                if (!m_CurrPlayerTurn.Human)
	                {
	                    makeMachineMove();
	                }
	            }

	            if(gameOver())
		        {
			        handleGameOver();
		        }
	        }
	        else
	        {
	            OnInvalidMoveGiven(new EventArgs()); // show prompt dialog "Move is not Valid"
	        }
        }
Ejemplo n.º 12
0
        private bool areLegalMovesExistForPlayer(
            PlayerInfo i_PlayerToCheckMoves,
            bool i_OnlyCaptureMoves)
        {
            fillLegalMovesList(i_PlayerToCheckMoves, i_OnlyCaptureMoves);

            return r_CurrentlyLegalMoves.Any();
        }
Ejemplo n.º 13
0
        // considering king more soldiers
        private uint numOfSoldiers(PlayerInfo i_Player)
        {
            uint soldiersNumber = 0;
            List<Piece> pieceList = getPlayerPiecesList(i_Player);

            foreach (Piece piece in pieceList)
            {
                soldiersNumber += piece.PieceValue();
            }

            return soldiersNumber;
        }
Ejemplo n.º 14
0
 // Returns the enemy playerInfo of a current player
 private PlayerInfo enemyPlayer(PlayerInfo i_Player)
 {
     return(i_Player == m_Player1 ? m_Player2 : m_Player1);
 }
Ejemplo n.º 15
0
 // Finds the piece in the list using given position coordinates
 private Piece getPieceByPosition(PlayerInfo i_Player, Position i_Position)
 {
     List<Piece> playerPieceList = getPlayerPiecesList(i_Player);
     Piece wantedPiece = null;
     foreach (Piece currentPiece in playerPieceList)
     {
         if (currentPiece.CurrPosition.Equals(i_Position))
         {
             wantedPiece = currentPiece;
             break;
         }
     }
     
     return wantedPiece;
 }
Ejemplo n.º 16
0
 private List <Piece> getPlayerPiecesList(PlayerInfo i_Player)
 {
     return(i_Player == m_Player1 ? m_Player1PiecesList : m_Player2PiecesList);
 }
Ejemplo n.º 17
0
 public void ResetGame()
 {
     m_CheckersBoard.InitializePiecesOnBoard();
     buildPlayersPiecesList();
     this.m_CurrPlayerTurn = this.m_Player1;
 }