Beispiel #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void clear() throws org.maltparser.core.exception.MaltChainedException
        public override void clear()
        {
            //		dependencyGraph.clear();
            ActiveStack.Clear();
            InactiveStack.Clear();
            input.Clear();
            historyNode = null;
        }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            TwoPlanarConfig that = (TwoPlanarConfig)obj;

            if (ActiveStack.Count != that.ActiveStack.Count)
            {
                return(false);
            }
            if (InactiveStack.Count != that.InactiveStack.Count)
            {
                return(false);
            }
            if (input.Count != that.Input.Count)
            {
                return(false);
            }
            if (dependencyGraph.NEdges() != that.DependencyGraph.NEdges())
            {
                return(false);
            }
            for (int i = 0; i < ActiveStack.Count; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                if (ActiveStack.get(i).Index != that.ActiveStack.get(i).Index)
                {
                    return(false);
                }
            }
            for (int i = 0; i < InactiveStack.Count; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                if (InactiveStack.get(i).Index != that.InactiveStack.get(i).Index)
                {
                    return(false);
                }
            }
            for (int i = 0; i < input.Count; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                if (input.get(i).Index != that.Input.get(i).Index)
                {
                    return(false);
                }
            }
            return(dependencyGraph.Edges.Equals(that.DependencyGraph.Edges));
        }
Beispiel #3
0
        public void PopActiveSetting()
        {
            bool was        = (bool)ActiveStack.Pop();
            bool newSetting = (bool)ActiveStack.Peek();

            if (was != newSetting)
            {
                NotifyEnabledChanged();
            }
        }
Beispiel #4
0
        public void PushActiveSetting(bool newSetting)
        {
            bool was = (bool)ActiveStack.Peek();

            ActiveStack.Push(newSetting);
            if (was != newSetting)
            {
                NotifyEnabledChanged();
            }
        }
Beispiel #5
0
        public void CastSpell(int playerId, int CardId, List <Target> targets)
        {
            Card card = FindCard(playerId, CardId);

            ActiveStack.Add(new StackEntry()
            {
                Card    = card,
                OwnerId = playerId,
                Targets = targets
            });
            Player activePlayer = Players.FirstOrDefault(o => o.Stats.Id == playerId);

            activePlayer.Hand.Remove(card);
        }
Beispiel #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize() throws org.maltparser.core.exception.MaltChainedException
        public override void initialize()
        {
            ActiveStack.Push(dependencyGraph.DependencyRoot);
            InactiveStack.Push(dependencyGraph.DependencyRoot);
            for (int i = dependencyGraph.HighestTokenIndex; i > 0; i--)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode node = dependencyGraph.getDependencyNode(i);
                DependencyNode node = dependencyGraph.GetDependencyNode(i);
                if (node != null)
                {
                    input.Push(node);
                }
            }
        }
Beispiel #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize(org.maltparser.parser.ParserConfiguration parserConfiguration) throws org.maltparser.core.exception.MaltChainedException
        public virtual void initialize(ParserConfiguration parserConfiguration)
        {
            if (parserConfiguration != null)
            {
                TwoPlanarConfig planarConfig = (TwoPlanarConfig)parserConfiguration;
                activeStack = planarConfig.activeStack;
                Stack <DependencyNode> sourceActiveStack   = planarConfig.ActiveStack;
                Stack <DependencyNode> sourceInactiveStack = planarConfig.InactiveStack;
                Stack <DependencyNode> sourceInput         = planarConfig.Input;
                DependencyGraph = planarConfig.DependencyGraph;
                for (int i = 0, n = sourceActiveStack.Count; i < n; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    ActiveStack.Push(dependencyGraph.GetDependencyNode(sourceActiveStack.get(i).Index));
                }
                for (int i = 0, n = sourceInactiveStack.Count; i < n; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    InactiveStack.Push(dependencyGraph.GetDependencyNode(sourceInactiveStack.get(i).Index));
                }
                for (int i = 0, n = sourceInput.Count; i < n; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    input.Push(dependencyGraph.GetDependencyNode(sourceInput.get(i).Index));
                }
            }
            else
            {
                ActiveStack.Push(dependencyGraph.DependencyRoot);
                InactiveStack.Push(dependencyGraph.DependencyRoot);
                for (int i = dependencyGraph.HighestTokenIndex; i > 0; i--)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode node = dependencyGraph.getDependencyNode(i);
                    DependencyNode node = dependencyGraph.GetDependencyNode(i);
                    if (node != null)
                    {
                        input.Push(node);
                    }
                }
            }
        }
Beispiel #8
0
        private PlayingCard DrawCard()
        {
            if (DrawingStack.IsEmpty)
            {
                throw new InvalidOperationException(@"[Internal error] The drawing stack is empty.");
            }

            var result = DrawingStack.WithdrawTopCard();

            if (DrawingStack.IsEmpty)
            {
                var refillCards = ActiveStack.WithdrawAllCardsExceptTopCardWithSameRank();
                DrawingStack.Refill(refillCards);
                DrawingStack.Shuffle();

                PointsRatio++;
            }

            return(result);
        }
Beispiel #9
0
        public void MakeMove([NotNull] Move move)
        {
            if (move is null)
            {
                //// TODO [HarinezumiSama] Use null as 'pass'?
                throw new ArgumentNullException(nameof(move));
            }

            if (RequiredFirstCard.HasValue && move.FirstCard != RequiredFirstCard.Value)
            {
                throw new ArgumentException(
                          $@"The player {CurrentPlayer.Name.ToUIString()} is a dealer and their first card in the first move must be {
                        RequiredFirstCard.Value} (but was {move.FirstCard}).",
                          nameof(move));
            }

            var validMoveCards = GetValidMoveCards();

            if (!validMoveCards.Contains(move.FirstCard))
            {
                var validMoveCardsString = validMoveCards.Select(card => card.ToString()).Join(", ");

                throw new ArgumentException(
                          $@"The player {CurrentPlayer.Name.ToUIString()} cannot make a move with {
                        move.FirstCard} as this card is invalid for the current game state (valid cards: {
                        validMoveCardsString}).",
                          nameof(move));
            }

            if (move.IsBridgeDeclared && !CanDeclareBridgeWith(move))
            {
                throw new ArgumentException(
                          $@"The player {CurrentPlayer.Name.ToUIString()} cannot declare bridge with {move}.",
                          nameof(move));
            }

            var newCurrentPlayerIndex = CurrentPlayerIndex;
            var victimPlayerIndex     = GetNextPlayerIndex(CurrentPlayerIndex);

            void MoveToNextPlayer(bool skipMove)
            {
                GetNextPlayerIndex(ref newCurrentPlayerIndex);

                if (!skipMove)
                {
                    return;
                }

                GetNextPlayerIndex(ref victimPlayerIndex);
                if (victimPlayerIndex == CurrentPlayerIndex)
                {
                    GetNextPlayerIndex(ref victimPlayerIndex);
                }
            }

            void DrawCardsToVictimPlayer(int count)
            {
                if (count <= 0 || count > Constants.Cards.All.Count)
                {
                    throw new ArgumentOutOfRangeException(
                              nameof(count),
                              count,
                              $@"The value is out of the valid range (1 .. {Constants.Cards.All.Count}).");
                }

                for (var index = 0; index < count; index++)
                {
                    var card = DrawCard();

                    var nextPlayer = Players[victimPlayerIndex];
                    nextPlayer.AppendCard(card);
                }
            }

            if (move.FirstCard.Rank != PlayingCardRank.Six)
            {
                MoveToNextPlayer(false);
            }

            for (var index = 0; index < move.Cards.Count; index++)
            {
                var card = move.Cards[index];

                if (!CurrentPlayer.Cards.Contains(card))
                {
                    throw new ArgumentException(
                              $@"The player {CurrentPlayer.Name.ToUIString()} cannot make a move with {
                            card} since they don't have this card in hand.",
                              nameof(move));
                }

                CurrentPlayer.RemoveCard(card);
                ActiveStack.DepositCardOnTop(card);

                switch (card.Rank)
                {
                case PlayingCardRank.Seven:
                    DrawCardsToVictimPlayer(1);
                    break;

                case PlayingCardRank.Eight:
                    DrawCardsToVictimPlayer(2);
                    MoveToNextPlayer(true);
                    break;

                case PlayingCardRank.Six:
                case PlayingCardRank.Nine:
                case PlayingCardRank.Ten:
                case PlayingCardRank.Jack:
                case PlayingCardRank.King:
                    break;

                case PlayingCardRank.Queen:
                    if (card.Suit == PlayingCardSuit.Spades && index == move.Cards.Count - 1)
                    {
                        DrawCardsToVictimPlayer(5);
                        MoveToNextPlayer(true);
                    }

                    break;

                case PlayingCardRank.Ace:
                    MoveToNextPlayer(true);
                    break;

                default:
                    throw card.Rank.CreateEnumValueNotImplementedException();
                }
            }

            if (move.IsBridgeDeclared ||
                (CurrentPlayer.Cards.Count == 0 && move.FirstCard.Rank != PlayingCardRank.Six))
            {
                throw new NotImplementedException("[TODO] Implement end of round.");
            }

            CurrentPlayerIndex = newCurrentPlayerIndex;
            LastMove           = move;
            RequiredFirstCard  = null;
        }
Beispiel #10
0
        public void ResolveStack()
        {
            while (ActiveStack.Count > 0)
            {
                StackEntry currentEntry = ActiveStack[ActiveStack.Count - 1];
                ActiveStack.RemoveAt(ActiveStack.Count - 1);
                if (currentEntry.Card.Types.Contains("Land"))
                {
                    ProcessLandIntoPlay(currentEntry.OwnerId, currentEntry.Card);
                }
                else
                {
                    foreach (Effect currentEffect in currentEntry.Card.Effects)
                    {
                        switch (currentEffect.Action)
                        {
                        case Enumerations.Action.AddLife:
                            if (currentEntry.Targets != null && currentEntry.Targets.Count > 0)
                            {
                                foreach (Target currentTarget in currentEntry.Targets)
                                {
                                    if (currentTarget.PlayerId > 0)
                                    {
                                        ProcessAddLifeEffect(currentTarget.PlayerId, currentEffect);
                                    }
                                    else
                                    {
                                        ProcessAddLifeEffect(currentEffect);
                                    }
                                }
                            }
                            else
                            {
                                ProcessAddLifeEffect(currentEffect);
                            }
                            break;

                        case Enumerations.Action.DealDamage:
                            if (currentEntry.Targets != null && currentEntry.Targets.Count > 0)
                            {
                                foreach (Target currentTarget in currentEntry.Targets)
                                {
                                    if (currentTarget.CardId < 1 && currentTarget.PlayerId > 0)
                                    {
                                        ProcessDamageEffect(currentTarget.PlayerId, currentEffect);
                                    }
                                    else if (currentTarget.CardId > 0)
                                    {
                                        ProcessDamageEffect(FindCard(currentTarget.PlayerId, currentTarget.CardId), currentEffect);
                                    }
                                    else
                                    {
                                        ProcessDamageEffect(currentEffect);
                                    }
                                }
                            }
                            else
                            {
                                ProcessDamageEffect(currentEffect);
                            }
                            break;

                        case Enumerations.Action.Destroy:
                            if (currentEntry.Targets != null && currentEntry.Targets.Count > 0)
                            {
                                foreach (Target currentTarget in currentEntry.Targets)
                                {
                                    if (currentTarget.CardId > 0)
                                    {
                                        ProcessDestroyEffect(FindCard(currentTarget.PlayerId, currentTarget.CardId), currentEffect);
                                    }
                                    else
                                    {
                                        ProcessDestroyEffect(currentEffect);
                                    }
                                }
                            }
                            else
                            {
                                ProcessDestroyEffect(currentEffect);
                            }
                            break;

                        case Enumerations.Action.DrawXCards:
                            if (currentEntry.Targets != null && currentEntry.Targets.Count > 0)
                            {
                                foreach (Target currentTarget in currentEntry.Targets)
                                {
                                    if (currentTarget.PlayerId > 0)
                                    {
                                        ProcessDrawXCardsEffect(currentTarget.PlayerId, currentEffect);
                                    }
                                    else
                                    {
                                        ProcessDrawXCardsEffect(currentEffect);
                                    }
                                }
                            }
                            else
                            {
                                ProcessDrawXCardsEffect(currentEffect);
                            }
                            break;

                        case Enumerations.Action.PreventDamage:
                            if (currentEntry.Targets != null && currentEntry.Targets.Count > 0)
                            {
                                foreach (Target currentTarget in currentEntry.Targets)
                                {
                                    if (currentTarget.CardId < 1 && currentTarget.PlayerId > 0)
                                    {
                                        ProcessPreventDamageEffect(currentTarget.PlayerId, currentEffect);
                                    }
                                    else if (currentTarget.CardId > 0)
                                    {
                                        ProcessPreventDamageEffect(FindCard(currentTarget.PlayerId, currentTarget.CardId), currentEffect);
                                    }
                                    else
                                    {
                                        ProcessPreventDamageEffect(currentEffect);
                                    }
                                }
                            }
                            else
                            {
                                ProcessPreventDamageEffect(currentEffect);
                            }
                            break;

                        case Enumerations.Action.Tap:
                            if (currentEntry.Targets != null && currentEntry.Targets.Count > 0)
                            {
                                foreach (Target currentTarget in currentEntry.Targets)
                                {
                                    if (currentTarget.CardId > 0)
                                    {
                                        ProcessTapEffect(FindCard(currentTarget.PlayerId, currentTarget.CardId), currentEffect);
                                    }
                                    else
                                    {
                                        ProcessTapEffect(currentEffect);
                                    }
                                }
                            }
                            else
                            {
                                ProcessTapEffect(currentEffect);
                            }
                            break;

                        case Enumerations.Action.Untap:
                            if (currentEntry.Targets != null && currentEntry.Targets.Count > 0)
                            {
                                foreach (Target currentTarget in currentEntry.Targets)
                                {
                                    if (currentTarget.CardId > 0)
                                    {
                                        ProcessUnTapEffect(FindCard(currentTarget.PlayerId, currentTarget.CardId), currentEffect);
                                    }
                                    else
                                    {
                                        ProcessUnTapEffect(currentEffect);
                                    }
                                }
                            }
                            else
                            {
                                ProcessUnTapEffect(currentEffect);
                            }
                            break;
                        }
                    }
                }
            }
        }