Esempio n. 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;
                }
            }
        }
Esempio n. 2
0
        private void eatCoin(Coin i_Coin, Coin i_RivalCoin)
        {
            if (i_Coin != null && i_RivalCoin != null)
            {
                if (i_Coin is KingCoin)
                {
                    KingCoin kingCopy = i_Coin as KingCoin;

                    if (kingCopy.IsAbleToEat(i_RivalCoin.Coordinates, out Coordinate target))
                    {
                        Board.RemoveCoinFromBoard(kingCopy);
                        kingCopy.Coordinates.CopyCoordinates(target);
                        Board.SetCoinOnBoard(kingCopy);
                        Player rivalPlayer = GetCoinOwner(i_RivalCoin);
                        Board.RemoveCoinFromBoard(i_RivalCoin);
                        rivalPlayer.CoinsList.Remove(i_RivalCoin);
                        kingCopy.UpdateMoves();
                    }
                }
                else if (!i_Coin.IsKing && i_Coin.IsAbleToEat(i_RivalCoin.Coordinates, out Coordinate target))
                {
                    Board.RemoveCoinFromBoard(i_Coin);
                    i_Coin.Coordinates.CopyCoordinates(target);
                    Board.SetCoinOnBoard(i_Coin);
                    Player rivalPlayer = GetCoinOwner(i_RivalCoin);
                    Board.RemoveCoinFromBoard(i_RivalCoin);
                    rivalPlayer.CoinsList.Remove(i_RivalCoin);
                    i_Coin.UpdateMoves();
                }
            }
        }
Esempio n. 3
0
        public bool HasEatingMoves(Player i_Player)
        {
            bool hasEatingMoves = false;

            if (i_Player != null)
            {
                foreach (Coin currentCoin in i_Player.CoinsList)
                {
                    if (currentCoin.HasEatingMoves())
                    {
                        hasEatingMoves = !hasEatingMoves; // true
                        break;
                    }
                    else if (currentCoin is KingCoin)
                    {
                        KingCoin kingCopy = currentCoin as KingCoin;
                        if (kingCopy.HasEatingMoves())
                        {
                            hasEatingMoves = !hasEatingMoves; // true
                            break;
                        }
                    }
                }
            }
            return(hasEatingMoves);
        }
Esempio n. 4
0
        public void UpdatePlayersAvailableMoves()
        {
            List <Player> players = new List <Player>();

            players.Add(Player1);
            players.Add(Player2);

            foreach (Player currentPlayer in players)
            {
                foreach (Coin currentCoin in currentPlayer.CoinsList)
                {
                    if (!currentCoin.IsKing)
                    {
                        currentCoin.UpdateMoves();
                    }
                    // If king
                    else if (currentCoin is KingCoin)
                    {
                        KingCoin kingCopy = currentCoin as KingCoin;
                        kingCopy.UpdateMoves();
                    }
                }

                // Clean no eating moves
                if (HasEatingMoves(currentPlayer))
                {
                    cleanNoEatingMoves(currentPlayer.CoinsList);
                }
            }
        }
Esempio n. 5
0
        public KingCoin MakeKing()
        {
            KingCoin newKing = new KingCoin(CoinType, Board);

            newKing.Coordinates.CopyCoordinates(Coordinates);
            return(newKing);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        private List <Coordinate> getNextMovesByDirections(eVerticalDirections i_Vertical, eHorizontalDirections i_Horizontal)
        {
            List <Coordinate> moves = new List <Coordinate>();

            Coordinate prevSquare = new Coordinate();

            prevSquare.CopyCoordinates(Coordinates);

            Coin kingCopy = new KingCoin(CoinType, Board);

            kingCopy.Coordinates.CopyCoordinates(Coordinates);
            Coordinate nextSquare = GetNextSquare(ref kingCopy, i_Vertical, i_Horizontal);

            kingCopy.Coordinates = prevSquare;


            while (Board.IsValid(nextSquare))
            {
                if (Board.IsEmptySquare(nextSquare))
                {
                    moves.Add(nextSquare);
                }
                else if (kingCopy.IsAbleToEat(nextSquare, out Coordinate target))
                {
                    moves.Add(target);
                    break;
                }
                else
                {
                    break;
                }
                prevSquare.CopyCoordinates(nextSquare);
                nextSquare = GetNextSquare(ref kingCopy, i_Vertical, i_Horizontal);
            }

            return(moves);
        }