Exemple #1
0
        /// <summary>
        /// Makes move on the table, and flips the active player. A Move can be created using GetMove(command).
        /// </summary>
        public void MakeMove(Move move)
        {
            _moveNo++;
            if (move == null)
            {
                throw new NullReferenceException();
            }
            currentMove = move;
            switch (move.MoveType)
            {
            case MoveTypes.Throwaway:
                GetActivePlayer().RemoveCard(move.CardPlayed);
                CardsOnTable.Add(move.CardPlayed);
                break;

            case MoveTypes.Pickup:
                GetActivePlayer().RemoveCard(move.CardPlayed);
                GetActivePlayer().AddCardsToLocalDeck(move.CardsPickedUp.Concat(new List <byte> {
                    move.CardPlayed
                }).ToList());
                CardsOnTable.RemoveAll(x => move.CardsPickedUp.Contains(x));
                break;

            case MoveTypes.Build: break;

            case MoveTypes.Capture: break;

            default: throw new Exception(Errorstr.NoMove());
            }
            FlipActivePlayer();
        }
Exemple #2
0
            private static Move Throwaway(string[] cmdArgs)
            {
                byte card = 0;

                if (cmdArgs.Length != 2)
                {
                    throw new UnparseableMoveException("Two arguments expected. First argument throwaway, " +
                                                       "second argument the card that is being thrown away.", string.Join(' ', cmdArgs));
                }
                string throwawayCard = cmdArgs[1];

                if (ExtractBuildNamesFromString(ref throwawayCard)?.Count() != 0)
                {
                    throw new UnparseableMoveException("Build names cannot be used when throwing away cards.",
                                                       string.Join(' ', cmdArgs));
                }
                try {
                    card = ExtractCardsFromString(throwawayCard)[0];
                } catch (Exception ex) {
                    if (ex is ArgumentOutOfRangeException || ex is ArgumentNullException || ex is UnparseableMoveException)
                    {
                        throw new UnparseableMoveException(Errorstr.NoMove(), string.Join(' ', cmdArgs));
                    }
                    else
                    {
                        throw ex;
                    }
                }

                card = GetCorrespondingCards(new List <byte> {
                    card
                }, table.GetActivePlayer().Hand,
                                             (table.GetActivePlayer().PlayerNo == Players.One) ? CardLocations.PlayerOneHand : CardLocations.PlayerTwoHand)[0];

                return(new Move(MoveTypes.Throwaway, card));
            }
Exemple #3
0
            private static Move Pickup(string[] cmdArgs)
            {
                if (cmdArgs.Length < 2 || cmdArgs.Length > 3)
                {
                    throw new UnparseableMoveException("Two or three arguments expected. First argument pickup, " +
                                                       "second argument card on table, third argument card in hand.", string.Join(' ', cmdArgs));
                }
                if (cmdArgs.Length == 2)
                {
                    //"pickup 4" should be interpreted as "use the sole 4 in hand to pick up the sole 4 on table"
                    cmdArgs = new string[3] {
                        cmdArgs[0], cmdArgs[1], cmdArgs[1]
                    }
                }
                ;
                string fromTable = cmdArgs[1];
                string fromHand  = cmdArgs[2];

                if (ExtractBuildNamesFromString(ref fromTable)?.Count() != 0 || ExtractBuildNamesFromString(ref fromHand)?.Count() != 0)
                {
                    throw new UnparseableMoveException("Build names cannot be used when picking up cards. Use capture instead.",
                                                       string.Join(' ', cmdArgs));
                }
                List <byte> playOnTableRaw, playOnTable;
                byte        playFromHandRaw, playFromHand;

                playOnTableRaw  = playOnTable = new List <byte>();
                playFromHandRaw = playFromHand = 0;

                try {
                    playOnTableRaw  = ExtractCardsFromString(fromTable);
                    playFromHandRaw = ExtractCardFromString(fromHand);
                } catch (Exception ex) {
                    if (ex is ArgumentOutOfRangeException || ex is ArgumentNullException)
                    {
                        throw new UnparseableMoveException(Errorstr.NoMove(), string.Join(' ', cmdArgs));
                    }
                    else
                    {
                        throw ex;
                    }
                }

                playOnTable  = GetCorrespondingCards(playOnTableRaw, table.CardsOnTable, CardLocations.Table);
                playFromHand = GetCorrespondingCards(new List <byte> {
                    playFromHandRaw
                }, table.GetActivePlayer().Hand,
                                                     (table.GetActivePlayer().PlayerNo == Players.One) ? CardLocations.PlayerOneHand : CardLocations.PlayerTwoHand)[0];

                if (ContainsPictureCard(playOnTable.ToList()))
                {
                    if (playOnTable.Count != 1 || !CardsMatchInValue(playFromHand, playOnTable[0]))
                    {
                        throw new IllegalPickupException(
                                  "Cannot pickup multiple picture cards at once", playFromHand, (byte)GetCardValue(playFromHand));
                    }
                }
                else
                {
                    //if no error, then valid move
                    Build build = new Build(BuildNames.NONE, playOnTable, (byte)GetCardValue(playFromHand));
                }

                return(new Move(MoveTypes.Pickup).PlayCard(playFromHand).PickupCards(playOnTable));
            }