Example #1
0
        private void cleanNoEatingMoves(List <Coin> i_CoinsList)
        {
            if (i_CoinsList.Any())
            {
                foreach (Coin currentCoin in i_CoinsList)
                {
                    List <Coordinate> eatingPossibilities = new List <Coordinate>();

                    foreach (Coordinate currentCoordinate in currentCoin.AvailableCoordinates)
                    {
                        if (!currentCoin.IsKing && currentCoin.IsEatingMove(currentCoordinate, out Coordinate o_RivalCoord))
                        {
                            eatingPossibilities.Add(currentCoordinate);
                        }
                        else if (currentCoin is KingCoin)
                        {
                            KingCoin kingCopy = currentCoin as KingCoin;
                            if (kingCopy.IsEatingMove(currentCoordinate, out Coordinate o_RivalCoordinate))
                            {
                                eatingPossibilities.Add(currentCoordinate);
                            }
                        }
                    }
                    currentCoin.AvailableCoordinates = eatingPossibilities;
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method moves the given coin to the desired coordinate.
        /// If the move is invalid, the method will not change any coins location.
        /// </summary>
        /// <param name="i_Coin"></param>
        /// <param name="i_Target"></param>
        /// <returns>Type of move executed (Step, Eat, None)</returns>
        public eMoveType MoveCoin(Coin i_Coin, Coordinate i_Target)
        {
            eMoveType moveType = eMoveType.None;

            if (i_Coin != null && i_Target != null)
            {
                if (i_Coin is KingCoin)
                {
                    KingCoin king = i_Coin as KingCoin;
                    if (king.IsEatingMove(i_Target, out Coordinate rivalCoord) && king.AvailableCoordinates.Contains(i_Target))
                    {
                        moveType = eMoveType.Eat;
                        eatCoin(king, GetCoinFromBoard(rivalCoord));
                    }
                    else if (king.isValidMove(i_Target) && king.AvailableCoordinates.Contains(i_Target))
                    {
                        moveType = eMoveType.Step;
                        moveCoin(king, i_Target);
                    }

                    UpdatePlayersAvailableMoves();
                }
                else
                {
                    if (i_Coin.IsEatingMove(i_Target, out Coordinate rivalCoord) &&
                        i_Coin.AvailableCoordinates.Contains(i_Target))
                    {
                        moveType = eMoveType.Eat;
                        eatCoin(i_Coin, GetCoinFromBoard(rivalCoord));
                    }
                    else if (i_Coin.isValidMove(i_Target) &&
                             i_Coin.AvailableCoordinates.Contains(i_Target))
                    {
                        moveType = eMoveType.Step;
                        moveCoin(i_Coin, i_Target);
                    }
                    // If needs to be turned to a King coin
                    if (hasReachedTheFarSideOfTheBoard(i_Coin))
                    {
                        KingCoin newKing   = i_Coin.MakeKing();
                        Player   coinOwner = GetCoinOwner(i_Coin);
                        Board.RemoveCoinFromBoard(i_Coin);
                        coinOwner.CoinsList.Remove(i_Coin);
                        coinOwner.CoinsList.Add(newKing);
                        Board.SetCoinOnBoard(newKing);
                    }
                }

                UpdatePlayersAvailableMoves();
            }

            return(moveType);
        }