public void CanConvertToStringWithoutCards()
        {
            // arrange
            var playerHand = new PlayerHand {Player = "John"};

            // act
            string result = converter.ToString(playerHand);

            // assert
            Assert.Equal("John, <empty hand>", result);
        }
        public void CanConvertToStringWithoutPlayerName()
        {
            // arrange
            var playerHand = new PlayerHand { Cards = new[] {jackH, tenS,}};

            // act
            string result = converter.ToString(playerHand);

            // assert
            Assert.Equal("<player not set>, JH, 10S", result);
        }
        public void CanConvertToString()
        {
            // arrange
            var playerHand =
                new PlayerHand {Player = "John", Cards = new[] {jackH, tenS,}};

            // act
            string result = converter.ToString(playerHand);

            // assert
            Assert.Equal("John, JH, 10S", result);
        }
示例#4
0
文件: Player.cs 项目: Gabino3/socAI
    public Player(int id, bool isAI)
    {
        this.id = id;
        this.isAI = isAI;

        switch (id)
        {
            case 0: color = Color.red; break;
            case 1: color = Color.yellow; break;
            case 2: color = Color.green; break;
            case 3: color = Color.blue; break;
            default: color = Color.black; break;
        }
        roads = new List<Edge> (72);
        structures = new List<Node> (54);
        hand = new PlayerHand (0);//(100); //TODO just testing...
    }
        /// <summary>
        /// Play a hand of 5 card draw.
        /// </summary>
        public void PlayRound()
        {
            Discard = new bool[5] {
                false, false, false, false, false
            };
            string userChoice;
            int    discardMe = 0;

            //deal five cards to player
            for (int n = 0; n < 5; n++)
            {
                PlayerHand.Add(deckOfCards.Deal());
            }

            //discard loop
            do
            {
                ShowPlayerHand();

                Console.WriteLine("Type the number of the card in your hand and hit Enter to toggle between Keep/Discard.");
                Console.Write("Type 'D' to finalize dicard or 'exit' to quit game? ");
                userChoice = Console.ReadLine();

                if (userChoice.ToLower() == "exit")
                {
                    System.Environment.Exit(0);
                }

                //input validation loop
                while (userChoice != "D" && !int.TryParse(userChoice, out discardMe))
                {
                    Console.WriteLine("Invalid choice. Try Again: ");
                    userChoice = Console.ReadLine();
                }

                //toggle element using ternary operator.
                if (userChoice != "D" && discardMe > 0 && discardMe < 6)
                {
                    Discard[discardMe - 1] = Discard[discardMe - 1] == true ? false : true;
                }
            } while (userChoice != "D");

            FinalizeDiscard();
            ShowPlayerHand();
        }//play Round
示例#6
0
        //TODO all card logic here is probably better suited in another class
        private void RecalculateHand()
        {
            // Justian Logic to calculate cards needed; the hand contains positive values for cards required to perform objective
            cardsNeeded = new PlayerHand();

            PlayerHand neededCards = new PlayerHand();

            foreach (Edge road in roads)
            {
                neededCards.brick++;
                neededCards.wood++;
            }
            foreach (Node settlement in settlements)
            {
                neededCards.brick++;
                neededCards.wood++;
                neededCards.grain++;
                neededCards.sheep++;
            }
            foreach (Node city in cities)
            {
                neededCards.ore   += 3;
                neededCards.grain += 2;
            }

            // Kevin Logic to calculate cards needed, a differential between cards-needed-to-build and current player's hand.  Negative
            //      values indicate a lack of cards, positive values indicate a surplus

            cardDifferentialForObjective = player.GetPlayerHand().MakeHandDifferentialFromRequiredResources(neededCards.brick,
                                                                                                            neededCards.ore,
                                                                                                            neededCards.wood,
                                                                                                            neededCards.grain,
                                                                                                            neededCards.sheep);

            // Sets the cardsneeded variable to included only those cards the Player does not yet have
            for (int i = 0; i < 5; i++)
            {
                neededCards.SetResourceQuantity(i, neededCards.GetResourceQuantity(i) - player.GetPlayerHand().GetResourceQuantity(i));

                if (neededCards.GetResourceQuantity(i) > 0)
                {
                    cardsNeeded.SetResourceQuantity(i, neededCards.GetResourceQuantity(i));
                }
            }
        }
示例#7
0
 /// <summary>
 /// Called by a UI card displayer when the player signals they want to use that card.
 /// </summary>
 public void UseCardByUI(ActionCard card)
 {
     if (!TurnActive)
     {
         return;
     }
     else
     {
         currentCard      = card;
         currentCardIndex = PlayerHand.IndexOf(card);
         validPos         = true;
         if (ValidCard(currentCard))
         {
             PlayCard();
             Debug.Log("Used card " + card.cardName);
         }
     }
 }
示例#8
0
        public bool areSequential(PlayerHand player)
        {
            var sortedList  = player.Cards.OrderBy(o => o.CardValue).Select(x => x);
            int currentRank = 0;

            foreach (var card in sortedList)
            {
                if (currentRank > 0)
                {
                    if (card.CardValue != (currentRank + 1))
                    {
                        return(false);
                    }
                }
                currentRank = card.CardValue;
            }
            return(true);
        }
示例#9
0
        public static bool IsFourOfAKind(PlayerHand playerHand)
        {
            bool isFourOfAKind = false;
            var  cards         = playerHand.Hand.Split(" ");

            foreach (var card in cards)
            {
                var cardNumber = card.Trim().Remove(card.Length - 1);
                if (isFourOfAKind)
                {
                    continue;
                }
                var cardCount = cards.Count(c => c.Remove(c.Length - 1) == cardNumber);
                isFourOfAKind = cardCount == 4 ? true : false;
            }

            return(isFourOfAKind);
        }
示例#10
0
        public static string HighCard(PlayerHand playerHand)
        {
            int    highCardIndex = 0;
            string highCard      = "";
            var    cards         = playerHand.Hand.Split(" ");

            foreach (var card in cards)
            {
                var currentCardIndex = DeckOfCards.Cards.IndexOf(card.Remove(card.Length - 1));
                if (currentCardIndex > highCardIndex)
                {
                    highCardIndex = currentCardIndex;
                    highCard      = card;
                }
            }

            return(highCard);
        }
示例#11
0
        public void Test_RegisterRules_ThrowException()
        {
            HandRank invalidHandRank = (HandRank)Enum.Parse(typeof(HandRank), "15");

            Assert.Throws(typeof(InvalidPokerRuleException), delegate {
                Api.RegisterRules(invalidHandRank);
            });
            List <Player> players    = new List <Player>();
            Player        alice      = Api.RegisterPlayer("Alice");
            PlayerHand    playerHand = Api.RegisterPlayerHand("ah,2h,3h,4h,5h");

            alice.PlayerHand = playerHand;
            players.Add(alice);

            Assert.Throws(typeof(InvalidPokerRuleException), delegate {
                Api.GetWinners(players);
            });
        }
示例#12
0
文件: Game.cs 项目: litsungyi/Hanabi
        public PlayCardResult Prompt(Player player, Player partner, CardNumber number)
        {
            if (GameEnd)
            {
                return(PlayCardResult.Invalid);
            }

            IList <Card> cards;

            if (!PlayerHand.TryGetValue(partner.Name, out cards))
            {
                return(PlayCardResult.Invalid);
            }

            if (Tokens[TokenType.Scroll] == 0)
            {
                return(PlayCardResult.Invalid);
            }

            --Tokens[TokenType.Scroll];

            foreach (var card in cards)
            {
                if (card.Number == number)
                {
                    card.Info.PromptIs(number);
                }
                else
                {
                    card.Info.PromptNot(number);
                }
            }

            if (LastRound)
            {
                LastActionPlayers.Remove(player.Name);
                if (LastActionPlayers.Count == 0)
                {
                    GameEnd = true;
                }
            }

            return(PlayCardResult.Success);
        }
示例#13
0
        /**
         * Start game and ask for user input
         */
        public void StartGame()
        {
            string name;
            string cardString;
            Player player;

            do
            {
                DisplayInstruction(PromptForPlayerName());
                name = ReadPlayerInput();
                if (String.IsNullOrEmpty(name))
                {
                    DisplayWinners();
                    continue;
                }

                try
                {
                    player = Api.RegisterPlayer(name);
                    players.Add(player);
                }
                catch (Exception e)
                {
                    DisplayInstruction(e.Message);
                    continue;
                }

                while (true)
                {
                    DisplayInstruction(PromptForCardsString());
                    cardString = ReadPlayerInput();
                    try
                    {
                        PlayerHand playerHand = Api.RegisterPlayerHand(cardString);
                        player.PlayerHand = playerHand;
                        break;
                    }
                    catch (Exception e)
                    {
                        DisplayInstruction(e.Message);
                    }
                }
            } while (!String.IsNullOrEmpty(name));
        }
示例#14
0
        /**
         * Set player's playhand's rank and kickers
         *
         * @param {PlayerHand} playerHand player's hand
         */
        public void SetHandRank(PlayerHand playerHand)
        {
            if (Rules == null || Rules.Count == 0)
            {
                throw new InvalidPokerRuleException();
            }
            HandRank rank = HandRank.HighCard;

            foreach (HandRank rule in Rules)
            {
                switch (rule)
                {
                case HandRank.Flush:
                    if (rank < HandRank.Flush && IsFlush(playerHand))
                    {
                        rank = HandRank.Flush;
                    }
                    break;

                case HandRank.ThreeOfAKind:
                    if (rank < HandRank.ThreeOfAKind && IsThreeOfAKind(playerHand))
                    {
                        rank = HandRank.ThreeOfAKind;
                    }
                    break;

                case HandRank.OnePair:
                    if (rank < HandRank.OnePair && IsOnePair(playerHand))
                    {
                        rank = HandRank.OnePair;
                    }
                    break;

                case HandRank.HighCard:
                    if (rank <= HandRank.HighCard)
                    {
                        playerHand.Cards = playerHand.Cards
                                           .OrderByDescending((card) => card.Rank).ToList();
                        playerHand.HandRank = HandRank.HighCard;
                    }
                    break;
                }
            }
        }
        //resets game
        public void ResetGame()
        {
            lblHumanAttacking.Visible    = true;
            lblComputerAttacking.Visible = false;
            lblHumanPlayer.Text          = myPlayerOne.getName().ToString();
            lblComputerPlayer.Text       = myPlayerTwo.getName().ToString();
            flpDeck.Controls.Clear();
            flpComputerHand.Controls.Clear();
            flpHumanHand.Controls.Clear();
            flpRiver.Controls.Clear();
            flpTrumpCard.Controls.Clear();
            flpDiscardPile.Controls.Clear();
            CardImageControl startingCardControl = new CardImageControl();

            flpDeck.Controls.Add(startingCardControl);
            myDeck               = new GameDeck(deckSize);
            myRiver              = new GameRiver();
            myHandOne            = new PlayerHand();
            myHandTwo            = new PlayerHand();
            myPlayerOne          = new Player("PlayerOne", myHandOne, true, false);
            myPlayerTwo          = new PlayerAI("PlayerTwo", myHandTwo, false, true);
            DeckDisplayList      = new CardList();
            HandOneDisplayList   = new CardList();
            HandTwoDisplayList   = new CardList();
            PlayerOneDisplayList = new CardList();
            PlayerTwoDisplayList = new CardList();
            RiverDisplayList     = new CardList();
            trumpCardDisplayList = new CardList();
            discardDisplayList   = new CardList();
            myDeck.Shuffle(deckSize);

            txtDeckCardsRemaining.Text   = myDeck.getCardsRemaining().ToString();
            txtRiverCardsRemaning.Text   = myRiver.getCardsRemaining().ToString();
            txtDicardCardsRemaining.Text = discardDisplayList.Count().ToString();
            txtRoundNumber.Text          = roundNumber.ToString();

            btnPickUp.Enabled      = false;
            btnCeaseAttack.Enabled = true;

            roundNumber = 0;
            GameLog.Log("\nNEW GAME");
            GameLog.Log("\n PlayerOne Win/Loss Ratio " + playerOneWins.ToString() + "/" + playerOneLosses.ToString());
            GameLog.Log("\n PlayerTwo Win/Loss Ratio " + playerTwoWins.ToString() + "/" + playerTwoLosses.ToString() + "\n");
        }
示例#16
0
        /// <summary>Rollback the previous cancellation of this command.</summary>
        public override void Redo()
        {
            if (stackAfter != null)
            {
                preventConflict(stackBefore, stackAfter);
            }
            else
            {
                preventConflict(stackBefore);
            }

            PlayerHand playerHand = (PlayerHand)model.CurrentGameBox.CurrentGame.GetPlayerHand(playerGuid);

            List <IAnimation> animations = new List <IAnimation>(4);

            if (playerHand == null)
            {
                animations.Add(new AddPlayerHandAnimation(playerGuid));
            }

            if (piece is ITerrainPrototype)
            {
                if (clone == null)
                {
                    // nothing to redo (ordering in the hand is not tansactional)
                    return;
                }
            }
            else
            {
                animations.Add(new DetachStacksAnimation(new IStack[] { stackBefore }, new Side[] { sideBefore }));
            }
            animations.Add(new MoveToFrontOfBoardAnimation(stackBefore, piece.CounterSection.CounterSheet));
            animations.Add(new MoveStackToHandAnimation(stackBefore));
            if (stackAfter == null)
            {
                animations.Add(new FillPlayerHandAnimation(playerGuid, stackBefore));
            }
            else
            {
                animations.Add(new MergeStacksAnimation(stackAfter, stackBefore, insertionIndex));
            }
            model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
        }
        private void Stay()
        {
            PlayerHandValue = PlayerHand.handValue();
            DealerHandValue = DealerHand.handValue();

            bool dealerHas5CardsWithValueSmallerThan21 = false;
            int  count = DealerHand.CardsInHand.Count;

            while (!dealerHas5CardsWithValueSmallerThan21 && DealerHandValue < 18)
            {
                DealerHand.AddCard(MyDeck.pick());
                DealerHandValue = DealerHand.handValue();
                count++;
                if (count == 5 && DealerHandValue <= 21)
                {
                    dealerHas5CardsWithValueSmallerThan21 = true;
                }
            }

            string winner = (dealerHas5CardsWithValueSmallerThan21 ||
                             (DealerHandValue >= PlayerHandValue && DealerHandValue <= 21)) ? "Dealer wins!" : "Player wins!";

            if (DealerHandValue == PlayerHandValue && !dealerHas5CardsWithValueSmallerThan21)
            {
                winner = "It's a draw.";
            }

            MessageBoard = $"{winner}";

            if (winner == "Dealer wins!")
            {
                DealerScore++;
            }
            if (winner == "Player wins!")
            {
                PlayerScore++;
            }

            HitButtonVisible         = false;
            StayButtonVisible        = false;
            ShuffleDeckButtonVisible = true;
            DealHandsButtonVisible   = true;
            CardsInDeck = MyDeck.CardsLeft();
        }
示例#18
0
        public static string DetermineHand(PlayerHand playerHand)
        {
            if (IsStaightFlush(playerHand))
            {
                return("Straight Flush");
            }

            if (IsFourOfAKind(playerHand))
            {
                return("Four of a Kind");
            }

            if (IsFullHouse(playerHand))
            {
                return("Full House");
            }

            if (IsFlush(playerHand))
            {
                return("Flush");
            }

            if (IsStraight(playerHand))
            {
                return("Straight");
            }

            if (IsThreeOfAKind(playerHand))
            {
                return("Three of a Kind");
            }

            if (IsTwoPair(playerHand))
            {
                return("Two Pair");
            }

            if (IsPair(playerHand))
            {
                return("Pair");
            }

            return(HighCard(playerHand));
        }
示例#19
0
        public void OnePairShowdownRule_Winners_OneWinner()
        {
            // Act
            var bobsHand = new PlayerHand(new Player("Bob"), new List <Card>
            {
                new Card(CardSuitEnum.Spade, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Heart, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Diamond, 4),
                new Card(CardSuitEnum.Club, 6),
                new Card(CardSuitEnum.Spade, 5)
            });
            var stacysHand = new PlayerHand(new Player("Stacy"), new List <Card>
            {
                new Card(CardSuitEnum.Club, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Diamond, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Heart, 5),
                new Card(CardSuitEnum.Heart, 6),
                new Card(CardSuitEnum.Club, 2)
            });

            var challengers = new List <PlayerHandChallengedCards>
            {
                new PlayerHandChallengedCards(bobsHand)
                {
                    ChallengedCards = new List <Card> {
                        new Card(CardSuitEnum.Spade, (int)CardValueEnum.Jack),
                        new Card(CardSuitEnum.Heart, (int)CardValueEnum.Jack)
                    }
                },
                new PlayerHandChallengedCards(stacysHand)
                {
                    ChallengedCards = new List <Card> {
                        new Card(CardSuitEnum.Club, (int)CardValueEnum.Jack),
                        new Card(CardSuitEnum.Diamond, (int)CardValueEnum.Jack)
                    }
                }
            };

            var actualResult = _rule.BreakTie(challengers);

            // Assert
            actualResult.Count().Should().Be(1);
            actualResult.First().PlayerInfo.Name.Should().Be("Bob");
        }
示例#20
0
        public void OnePairShowdownRule_FairMode_MultipleWinners()
        {
            // Act
            var bobsHand = new PlayerHand(new Player("Bob"), new List <Card>
            {
                new Card(CardSuitEnum.Spade, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Heart, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Diamond, 4),
                new Card(CardSuitEnum.Club, 6),
                new Card(CardSuitEnum.Spade, 5)
            });
            var stacysHand = new PlayerHand(new Player("Stacy"), new List <Card>
            {
                new Card(CardSuitEnum.Club, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Diamond, (int)CardValueEnum.Jack),
                new Card(CardSuitEnum.Heart, 5),
                new Card(CardSuitEnum.Heart, 6),
                new Card(CardSuitEnum.Club, 4)
            });

            var challengers = new List <PlayerHandChallengedCards>
            {
                new PlayerHandChallengedCards(bobsHand)
                {
                    ChallengedCards = new List <Card> {
                        new Card(CardSuitEnum.Spade, (int)CardValueEnum.Jack),
                        new Card(CardSuitEnum.Heart, (int)CardValueEnum.Jack)
                    }
                },
                new PlayerHandChallengedCards(stacysHand)
                {
                    ChallengedCards = new List <Card> {
                        new Card(CardSuitEnum.Club, (int)CardValueEnum.Jack),
                        new Card(CardSuitEnum.Diamond, (int)CardValueEnum.Jack)
                    }
                }
            };

            var actualWinners = _rule.BreakTie(challengers);

            // Assert
            actualWinners.Count().Should().Be(2);
        }
        public override void doCommand(RecognitionResult speechResult)
        {
            base.doCommand(speechResult);
            if (speechResult.Semantics["item"].Value.ToString().Contains("NPC"))
            {
                Creature newCreature = Catalog.current.GetData <CreatureData>(speechResult.Semantics["item"].Value.ToString().Replace(" NPC", "")).Spawn(Player.local.head.transform.position + 0.5f * Player.local.body.transform.right, Quaternion.identity, false);
                return;
            }
            Debug.Log("Spawning you a " + speechResult.Semantics["item"].Value);
            Item       item = Catalog.current.GetData <ItemData>(speechResult.Semantics["item"].Value.ToString(), true).Spawn(true, null);
            PlayerHand hand = speechResult.Semantics["optional"].Value.ToString().Contains("left") ? Player.local.handLeft : Player.local.handRight;

            item.transform.position = hand.transform.position;
            if (Creature.player.body.GetHand(hand.side).interactor.grabbedHandle)
            {
                Creature.player.body.GetHand(hand.side).interactor.UnGrab(true);
            }
            Creature.player.body.GetHand(hand.side).interactor.Grab(item.GetMainHandle(hand.side));
        }
示例#22
0
文件: Player.cs 项目: KRLacey/socAI
    private TradeOffer BuildTradeWithBank(PlayerHand cardDifferential)
    {
        int[] resourceRequest = new int[5];
        int[] resourceSurplus = new int[5];

        bool needsSomeCards   = false;
        bool canTradeWithBank = false;

        for (int i = 0; i < 5; i++)
        {
            int cards = cardDifferential.GetResourceQuantity(i);

            if (cards < 0)
            {
                resourceRequest[i] = -cards;
                needsSomeCards     = true;
            }
            else
            {
                resourceSurplus[i] = (cards / 4) * 4;

                if (resourceSurplus[i] > 0)
                {
                    canTradeWithBank = true;
                }
            }
        }

        if (canTradeWithBank && needsSomeCards)
        {
            // This TradeOffer constructor is specifically for bank trades; auto-equalizes to a 1:4 ratio
            return(new TradeOffer(this, resourceSurplus, resourceRequest));
        }
        else
        {
            if (debugMessages)
            {
                GameEngine.print("NOT ENOUGH RESOURCES TO TRADE WITH BANK");
            }

            return(null);
        }
    }
示例#23
0
        public async Task AddCardsToPlayerHand(long playerId, IEnumerable <long> cardIds, long sessionId)
        {
            List <PlayerHand> playerHands = new List <PlayerHand>();

            foreach (var id in cardIds)
            {
                var playerHand = new PlayerHand
                {
                    PlayerId  = playerId,
                    CardId    = id,
                    SessionId = sessionId
                };
                playerHands.Add(playerHand);
            }
            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                await db.InsertAsync(playerHands);
            }
        }
示例#24
0
        private static (PlayerHand hand, string error) BuildPlayerHand(string handText)
        {
            var playerHandLine = handText.Split(" ", StringSplitOptions.RemoveEmptyEntries);

            if (playerHandLine.Length != 4)
            {
                return(null, $"The following line line was improperly formatted: {Environment.NewLine } {handText}");
            }
            if (!int.TryParse(playerHandLine[0], out int playerNumber))
            {
                return(null, $"Player number could not be determiend on line: {handText}");

                throw new ArgumentException();
            }
            var cards      = playerHandLine.Skip(1).Select(CardFactory.BuildCard);
            var playerHand = new PlayerHand(playerNumber, cards);

            return(playerHand, string.Empty);
        }
示例#25
0
    public void StartCombatEncounter(BaseEnemy enemy, PlayerHand hand, ComboCardCreator comboMaker)
    {
        _playerHand = hand;
        _playerHand.AttachMethodToEvent(HandleCardEffectPropagation);
        _playerHand.InitDebugStuff();

        _currentCombatTarget = enemy;
        enemy.InitialiseThingForCombat(100.0f);
        enemy.CombatAI.inCombat = true;
        Debug.Log(enemy.CharacterHealth.ToString());
        var temp = Root.GetComponentFromRoot <UIHandler>().CurrentActivePanel.GetComponentInChildren <EnemyUIPanel>();

        temp.InitPanel(enemy);


        _cardCreator = comboMaker;

        StartNewPlayerTurn(hand);
    }
示例#26
0
    List <PlayerHand> LookForPlayerHand(List <RaycastResult> raycastResults)
    {
        List <PlayerHand> playerHandsFound = new List <PlayerHand>();

        foreach (var r in raycastResults)
        {
            if (r.gameObject.GetComponent <CardInHand>() != null)
            {
                PlayerHand playerHandFound = r.gameObject.GetComponent <CardInHand>().GetComponentInParent <PlayerHand>();

                if (!playerHandsFound.Contains(playerHandFound))
                {
                    playerHandsFound.Add(playerHandFound);
                }
            }
        }

        return(playerHandsFound);
    }
        private static List <IPlayer> GetSinglePlayerCollectionContaining(List <ICard> cards)
        {
            var playerHand = new PlayerHand {
                Outcome = HandOutcome.InProgress, Bet = 0
            };

            playerHand.Cards.AddRange(cards);
            var playerHandList = new List <IPlayerHand> {
                playerHand
            };
            var mockPlayer = new Mock <IPlayer>();

            mockPlayer.Setup(mp => mp.CurrentHands).Returns(playerHandList);
            var players = new List <IPlayer> {
                mockPlayer.Object
            };

            return(players);
        }
    public void CreateLocalAvatar(int playerNum)
    {
        GameObject head = PhotonNetwork.Instantiate(this.headPrefab.name, headAnchor.position, headAnchor.rotation, 0);

        head.transform.parent = headAnchor;

        localPlayerTarget = head.GetComponent <PlayerHead>();
        localPlayerTarget.photonView.RPC("Initialize", RpcTarget.All, playerNum);

        localPlayerLeftHand  = CreateHand(leftHandAnchor, false, playerNum);
        localPlayerRightHand = CreateHand(rightHandAnchor, true, playerNum);

        GameObject torso = PhotonNetwork.Instantiate(torsoPrefab.name, head.transform.position, Quaternion.identity);

        localPlayerTarget.SetTorso(torso);
        torso.GetComponent <PlayerTorso>().photonView.RPC("Initialize", RpcTarget.All, playerNum);

        photonView.RPC("SyncPlayerInfoWithMaster", RpcTarget.All);
    }
示例#29
0
        public void Test_CompareTo()
        {
            List <Card> cardsA = new List <Card>
            {
                new Card(CardRank.Ace, CardSuit.HEART),
                new Card(CardRank.Four, CardSuit.SPADE),
            };
            List <Card> cardsB = new List <Card>
            {
                new Card(CardRank.King, CardSuit.CLUB),
                new Card(CardRank.Four, CardSuit.HEART),
            };
            PlayerHand playerHandA = new PlayerHand(cardsA);
            PlayerHand playerHandB = new PlayerHand(cardsB);

            Assert.IsTrue(playerHandA.CompareTo(playerHandB) == 1);
            Assert.IsTrue(playerHandA.CompareTo(playerHandA) == 0);
            Assert.IsTrue(playerHandB.CompareTo(playerHandA) == -1);
        }
示例#30
0
        /// <summary>Called once when time is EndTimeInMicroseconds.</summary>
        protected override sealed void SetFinalState(IModel model)
        {
            if (model.CurrentSelection != null && model.CurrentSelection.Stack == stack)
            {
                model.CurrentSelection = null;
            }

            PlayerHand playerHand = (PlayerHand)model.CurrentGameBox.CurrentGame.GetPlayerHand(playerGuid);

            if (playerHand == null)
            {
                playerHand = (PlayerHand)model.CurrentGameBox.CurrentGame.AddPlayerHand(playerGuid);
            }
            if (stack.Board != null)
            {
                ((Board)stack.Board).RemoveStack(stack);
            }
            playerHand.Stack = (Stack)stack;
        }
示例#31
0
        public void DrawNewHand(Texture2D enemyTex, Texture2D eventTex, Texture2D merchantTex,
                                Texture2D restingTex, Texture2D trapTex, Texture2D treasureTex, Texture2D bossTex, Texture2D cardBack, Dictionary <string, Button> buttons,
                                Dictionary <string, Die> combatDice, Dictionary <string, SoundEffect> dieSounds, Dictionary <string, Texture2D> dieTextures)
        {
            playerHand.Add(new Enemy("Enemy", enemyTex, cardBack, buttons, combatDice, dieSounds));

            playerHand.Add(new EventCard("EventCard", eventTex, cardBack, buttons, combatDice, dieSounds, dieTextures));

            playerHand.Add(new Merchant("Merchant", merchantTex, cardBack, buttons, dieTextures));

            playerHand.Add(new Resting("Resting", restingTex, cardBack, buttons));

            playerHand.Add(new Trap("Trap", trapTex, cardBack, buttons, dieTextures, dieSounds));

            playerHand.Add(new Treasure("Treasure", treasureTex, cardBack, buttons, dieTextures, dieSounds));

            ShuffleHand();

            PlayerHand.Add(new Boss("Boss", bossTex, cardBack, buttons, combatDice, dieTextures, dieSounds));

            Card1 = playerHand[0];
            Card2 = playerHand[1];
            Card3 = playerHand[2];
            Card4 = playerHand[3];
            Card5 = playerHand[4];
            Card6 = playerHand[5];
            Card7 = playerHand[6];

            Card1.LevelXpos = 191;
            Card1.LevelYPos = 260;
            Card2.LevelXpos = 416;
            Card2.LevelYPos = 100;
            Card3.LevelXpos = 416;
            Card3.LevelYPos = 410;
            Card4.LevelXpos = 641;
            Card4.LevelYPos = 260;
            Card5.LevelXpos = 866;
            Card5.LevelYPos = 100;
            Card6.LevelXpos = 866;
            Card6.LevelYPos = 410;
            Card7.LevelXpos = 1091;
            Card7.LevelYPos = 260;
        }
示例#32
0
文件: Game.cs 项目: litsungyi/Hanabi
        public PlayCardResult DiscardCard(Player player, int cardId)
        {
            if (GameEnd)
            {
                return(PlayCardResult.Invalid);
            }

            IList <Card> cards;

            if (!PlayerHand.TryGetValue(player.Name, out cards))
            {
                return(PlayCardResult.Invalid);
            }

            var card = cards.Where(c => c.CardId == cardId).FirstOrDefault();

            if (card == null)
            {
                return(PlayCardResult.Invalid);
            }

            cards.Remove(card);
            DiscardPile.Add(card);

            ++Tokens[TokenType.Scroll];
            if (Tokens[TokenType.Scroll] > Rule.GetMaxScroll(Difficultly))
            {
                Tokens[TokenType.Scroll] = Rule.GetMaxScroll(Difficultly);
            }

            if (LastRound)
            {
                LastActionPlayers.Remove(player.Name);
                if (LastActionPlayers.Count == 0)
                {
                    GameEnd = true;
                }
            }

            DrawCard(player);
            return(PlayCardResult.Success);
        }
    public void SyncPlayerInfoWithMaster()
    {
        if (!PhotonNetwork.IsMasterClient)
        {
            return;
        }
        int i = 0;
        int j = 0;

        for (i = 0; i < playerTargets.Count; i++)
        {
            if (playerTargets[i] != null)
            {
                playerTargets[i].photonView.RPC("Initialize", RpcTarget.All, i);
            }
        }
        for (i = 0; i < playerTorsos.Count; i++)
        {
            if (playerTorsos[i] != null)
            {
                playerTorsos[i].photonView.RPC("Initialize", RpcTarget.All, i);
            }
        }
        for (i = 0; i < playerHands.Count; i++)
        {
            for (j = 0; j < playerHands[i].hands.Count; j++)
            {
                PlayerHand weapon = playerHands[i].hands[j];
                if (weapon != null)
                {
                    weapon.photonView.RPC("Initialize", RpcTarget.All, i, j == 0);
                }
            }
        }
        for (i = 0; i < playerTargets.Count; i++)
        {
            if (playerTargets[i] != null)
            {
                photonView.RPC("SetPlayerColor", RpcTarget.All, i);
            }
        }
    }
示例#34
0
    // Use this for initialization
    void Start()
    {
        oppAI    = opp.GetComponent <AI>();
        opp2AI   = opp2.GetComponent <AI>();
        friendAI = friend.GetComponent <AI>();

        List <int> sample  = new List <int>();
        List <int> sample1 = new List <int>();
        List <int> sample2 = new List <int>();
        List <int> sample3 = new List <int>();

        for (int i = 0; i < 4; i++)
        {
            sample.Add(0);
            sample1.Add(0);
            sample2.Add(0);
            sample3.Add(0);
        }
        boresh.Add(sample);
        boresh.Add(sample1);
        boresh.Add(sample2);
        boresh.Add(sample3);
        List <CardScript> cardSample  = new List <CardScript>();
        List <CardScript> cardSample2 = new List <CardScript>();
        List <CardScript> cardSample3 = new List <CardScript>();
        List <CardScript> cardSample4 = new List <CardScript>();

        outCards.Add(cardSample);
        outCards.Add(cardSample2);
        outCards.Add(cardSample3);
        outCards.Add(cardSample4);
        main        = GameObject.Find("Background").GetComponent <MainScript>();
        pHand       = GameObject.Find("Background").GetComponent <PlayerHand>();
        inGameCards = new List <GameObject>(cards);
        for (int i = 0; i < 52; i++)
        {
            cards[i].GetComponent <CardScript>().rank = cards[i].GetComponent <CardScript>().value;
        }


        //StartCoroutine(chooseHakem());
    }
示例#35
0
    // Use this for initialization
    void Start()
    {
        gameplay = this;

        _MainCamera = (Camera)gameObject.GetComponent("Camera");

        _SelectionListWindow = new SelectionListWindow(Screen.width / 2, Screen.height / 2 + 100);

        _AbilityManagerList = new SelectionListGenericWindow(Screen.width / 2, Screen.height / 2 + 100);

        _SelectionCardNameWindow = new SelectionCardNameWindow(Screen.width / 2 - 50, Screen.height / 2);
        _SelectionCardNameWindow.CreateCardList();
        _SelectionCardNameWindow.SetGame(this);

        _DecisionWindow = new DecisionWindow(Screen.width / 2, Screen.height / 2 + 100);
        _DecisionWindow.SetGame(this);

        _NotificationWindow = new NotificacionWindow(Screen.width / 2, Screen.height / 2 + 100);
        _NotificationWindow.SetGame(this);

        FromHandToBindList = new List<Card>();

        AttackedList = new List<Card>();

        UnitsCalled = new List<Card>();

        EnemySoulBlastQueue = new List<Card>();

        _PopupNumber = new PopupNumber();

        _MouseHelper = new MouseHelper(this);
        GameChat = new Chat();

        opponent = PlayerVariables.opponent;

        playerHand = new PlayerHand();
        enemyHand = new EnemyHand();

        field = new Field(this);
        enemyField = new EnemyField(this);
        guardZone = new GuardZone();
        guardZone.SetField(field);
        guardZone.SetEnemyField(enemyField);
        guardZone.SetGame(this);

        fieldInfo = new FieldInformation();
        EnemyFieldInfo = new EnemyFieldInformation();

        Data = new CardDataBase();
        List<CardInformation> tmpList = Data.GetAllCards();
        for(int i = 0; i < tmpList.Count; i++)
        {
            _SelectionCardNameWindow.AddNewNameToTheList(tmpList[i]);
        }

        //camera = (CameraPosition)GameObject.FindGameObjectWithTag("MainCamera").GetComponent("CameraPosition");
        //camera.SetLocation(CameraLocation.Hand);

        LoadPlayerDeck();
        LoadEnemyDeck();

        gamePhase = GamePhase.CHOOSE_VANGUARD;

        bDrawing = true;
        bIsCardSelectedFromHand = false;
        bPlayerTurn = false;

        bDriveAnimation = false;
        bChooseTriggerEffects = false;
        DriveCard = null;

        //Texture showed above a card when this is selected for an action (An attack, for instance)
        CardSelector = GameObject.FindGameObjectWithTag("CardSelector");
        _CardMenuHelper = (CardHelpMenu)GameObject.FindGameObjectWithTag("CardMenuHelper").GetComponent("CardHelpMenu");
        _GameHelper = (GameHelper)GameObject.FindGameObjectWithTag("GameHelper").GetComponent("GameHelper");

        bPlayerTurn = PlayerVariables.bFirstTurn;

        //ActivePopUpQuestion(playerDeck.DrawCard());
        _CardMenu = new CardMenu(this);

        _AbilityManager = new AbilityManager(this);
        _AbilityManagerExt = new AbilityManagerExt();

        _GameHelper.SetChat(GameChat);
        _GameHelper.SetGame(this);

        EnemyTurnStackedCards = new List<Card>();

        dummyUnitObject = new UnitObject();
        dummyUnitObject.SetGame(this);

        stateDynamicText = new DynamicText();
    }
示例#36
0
        /* Deals a card from Dealer to Player */
        public static void Deal(GameClient dealer, GameClient player, bool up)
        {
            PlayerHand hand;
            DealerDeck deck;
            Card c;

            if (!dealer.Player.Group.IsInTheGroup(player.Player))
            { dealer.Out.SendMessage(player.Player.Name + " must be in your group to play cards!", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; }
            if(!IsDealer(dealer))
            { dealer.Out.SendMessage("You must use /shuffle to prepare cards before dealing!", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; }
            if(!IsPlayer(player))
            {
                hand = new PlayerHand(player);
                m_playerHands.Add(player.Player.DBCharacter.ObjectId, hand);
            }
            else
            {
                hand = (PlayerHand)m_playerHands[player.Player.DBCharacter.ObjectId];
            }
            deck = (DealerDeck)m_dealerDecks[dealer.Player.DBCharacter.ObjectId];
            if(!deck.HasCard()) { return; }
            c = deck.GetCard();
            if (c == null)
            {
                dealer.Out.SendMessage("There are no cards left in the deck. Use /shuffle to prepare a new deck.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }
            hand.AddCard(c, up);
            foreach (GamePlayer Groupee in dealer.Player.Group.GetPlayersInTheGroup())
            {
                if (Groupee == dealer.Player)
                    dealer.Out.SendMessage("You deal " + (player == dealer ? "yourself" : player.Player.Name) + (up ? " the " + c.Name : " a card face down") + ".", eChatType.CT_Emote, eChatLoc.CL_SystemWindow);
                else if (Groupee == player.Player)
                    player.Out.SendMessage(dealer.Player.Name + " deals you the " + c.Name + ".", eChatType.CT_Emote, eChatLoc.CL_SystemWindow);
                else
                    Groupee.Client.Out.SendMessage(dealer.Player.Name + " deals " + (player == dealer ? "themself" : player.Player.Name) + (up ? " the " + c.Name : " a card face down") + ".", eChatType.CT_Emote, eChatLoc.CL_SystemWindow);
            }
            return;
        }
示例#37
0
 void INumberState.OnHandCollide(PlayerHand hand)
 {
 }
示例#38
0
        private bool ConsiderSplitOffer(IPlayerHand playerHand, IBlackjackCard dealerFaceUpCard)
        {
            if (!playerHand.EligibleForSplit)
            {
                return false;
            }

            // Using simple logic for now
            var hand = new PlayerHand();
            Balance -= Ante;
            hand.Bet = new AnteBet(Ante);
            _hands.Add(hand);

            playerHand.SplitInto(hand);

            return true;
        }
示例#39
0
 public void PlaceBet()
 {
     var hand = new PlayerHand();
     Balance -= Ante;
     hand.Bet = new AnteBet(Ante);
     _hands.Add(hand);
 }
示例#40
0
文件: AIEngine.cs 项目: Gabino3/socAI
 public Objective(Player player, GameState gamestate)
 {
     this.player = player;
     this.gamestate = gamestate;
     roads = new List<Edge>();
     settlements = new List<Node>();
     cities = new List<Node>();
     score = 0;
     cardsNeeded = new PlayerHand();
     curLongestRoad = Board.LongestRoadOfPlayer(player);
 }
示例#41
0
文件: Player.cs 项目: Gabino3/socAI
    private TradeOffer BuildTradeWithBank(PlayerHand cardDifferential)
    {
        int[] resourceRequest = new int[5];
        int[] resourceSurplus = new int[5];

        bool needsSomeCards = false;
        bool canTradeWithBank = false;
        for(int i = 0; i < 5; i++)
        {
            int cards = cardDifferential.GetResourceQuantity(i);

            if(cards < 0)
            {
                resourceRequest[i] = - cards;
                needsSomeCards = true;
            }
            else
            {
                resourceSurplus[i] = (cards / 4) * 4;

                if(resourceSurplus[i] > 0)
                {
                    canTradeWithBank = true;
                }
            }
        }

        if(canTradeWithBank && needsSomeCards)
        {
            // This TradeOffer constructor is specifically for bank trades; auto-equalizes to a 1:4 ratio
            return new TradeOffer(this, resourceSurplus, resourceRequest);
        }
        else
        {
            if(debugMessages)
            {
                GameEngine.print ("NOT ENOUGH RESOURCES TO TRADE WITH BANK");
            }

            return null;
        }
    }
示例#42
0
文件: Player.cs 项目: Gabino3/socAI
    // Returns a fair trade proposal
    private TradeOffer BuildFairTrade(int currentTurn, PlayerHand cardDifferential)
    {
        int[] resourceRequest = new int[5];
        int[] resourceSurplus = new int[5];

        for(int i = 0; i < 5; i++)
        {
            int cards = cardDifferential.GetResourceQuantity(i);

            if(cards < 0)
            {
                resourceRequest[i] = - cards;
            }
            else
            {
                resourceSurplus[i] = cards;
            }
        }

        TradeOffer trade = new TradeOffer (this, currentTurn, resourceSurplus, resourceRequest);

        trade.EqualizeTrade ();

        return trade;
    }
示例#43
0
    public void ExecuteTradeWithBank(TradeOffer offer, Player tradeHost)
    {
        PlayerHand hostHand = tradeHost.GetPlayerHand ();
        PlayerHand bankHand = new PlayerHand ();

        if (debugMessages)
        {
            GameEngine.print ("HOST TRADES:\n" +
                              offer.giveBrick + "|" + offer.giveOre + "|" + offer.giveWood + "|" + offer.giveGrain + "|" + offer.giveSheep);
            GameEngine.print ("FOR:\n" +
                              offer.getBrick + "|" + offer.getOre + "|" + offer.getWood + "|" + offer.getGrain + "|" + offer.getSheep);
        }

        if(debugMessages)
        {
            GameEngine.print ("HOSTHAND BEFORE:\n" +
                              hostHand.brick + " BRICK\n" +
                              hostHand.ore + " ORE\n" +
                              hostHand.wood + " WOOD\n" +
                              hostHand.grain + " GRAIN\n" +
                              hostHand.sheep + " SHEEP");

            GameEngine.print ("BANK BEFORE:\n" +
                              bankHand.brick + " BRICK\n" +
                              bankHand.ore + " ORE\n" +
                              bankHand.wood + " WOOD\n" +
                              bankHand.grain + " GRAIN\n" +
                              bankHand.sheep + " SHEEP");
        }

        performResourceExchangeBetweenPlayers(hostHand, bankHand, offer);

        if(debugMessages)
        {
            GameEngine.print ("HOSTHAND AFTER:\n" +
                              hostHand.brick + " BRICK\n" +
                              hostHand.ore + " ORE\n" +
                              hostHand.wood + " WOOD\n" +
                              hostHand.grain + " GRAIN\n" +
                              hostHand.sheep + " SHEEP");

            GameEngine.print ("BANK AFTER:\n" +
                              bankHand.brick + " BRICK\n" +
                              bankHand.ore + " ORE\n" +
                              bankHand.wood + " WOOD\n" +
                              bankHand.grain + " GRAIN\n" +
                              bankHand.sheep + " SHEEP");
        }
    }
示例#44
0
文件: AIEngine.cs 项目: Gabino3/socAI
        //TODO all card logic here is probably better suited in another class
        private void RecalculateHand()
        {
            // Justian Logic to calculate cards needed; the hand contains positive values for cards required to perform objective
            cardsNeeded = new PlayerHand ();

            PlayerHand neededCards = new PlayerHand();
            foreach (Edge road in roads) {
                neededCards.brick++;
                neededCards.wood++;
            }
            foreach (Node settlement in settlements) {
                neededCards.brick++;
                neededCards.wood++;
                neededCards.grain++;
                neededCards.sheep++;
            }
            foreach (Node city in cities) {
                neededCards.ore+=3;
                neededCards.grain+=2;
            }

            // Kevin Logic to calculate cards needed, a differential between cards-needed-to-build and current player's hand.  Negative
            // 		values indicate a lack of cards, positive values indicate a surplus

            cardDifferentialForObjective = player.GetPlayerHand ().MakeHandDifferentialFromRequiredResources (neededCards.brick,
                                                                                                              neededCards.ore,
                                                                                                              neededCards.wood,
                                                                                                              neededCards.grain,
                                                                                                              neededCards.sheep);

            // Sets the cardsneeded variable to included only those cards the Player does not yet have
            for (int i = 0; i < 5; i++)
            {
                neededCards.SetResourceQuantity(i, neededCards.GetResourceQuantity(i) - player.GetPlayerHand ().GetResourceQuantity(i));

                if (neededCards.GetResourceQuantity(i) > 0)
                {
                    cardsNeeded.SetResourceQuantity(i, neededCards.GetResourceQuantity(i));
                }
            }
        }
示例#45
0
 void moveHandAction(PlayerHand hand, BaseEntity to)
 {
     Actions.AddAction(new TweenPositionToEntity(hand, to, new Point(15, 30), 1f, Linear.EaseIn), true);
 }
示例#46
0
    public bool HandsOverlap(PlayerHand hand)
    {
        for(int i = 0; i < 5; i++)
        {
            if(this.GetResourceQuantity(i) < 0 && hand.GetResourceQuantity(i) > 0)
            {
                return true;
            }
        }

        return false;
    }
 void Awake() {
     playerHand = GetComponentInChildren<PlayerHand>();
 }
示例#48
0
 public Hand(PlayerHand player)
 {
     this.player = player;
     handCards = new Card[handSize];
 }
示例#49
0
 protected void Awake()
 {
     Instance = this;
 }
示例#50
0
    private void performResourceExchangeBetweenPlayers(PlayerHand hostHand, PlayerHand withHand, TradeOffer offer)
    {
        hostHand.brick = hostHand.brick + offer.getBrick - offer.giveBrick;
        withHand.brick = withHand.brick - offer.getBrick + offer.giveBrick;

        hostHand.ore = hostHand.ore + offer.getOre - offer.giveOre;
        withHand.ore = withHand.ore - offer.getOre + offer.giveOre;

        hostHand.wood = hostHand.wood + offer.getWood - offer.giveWood;
        withHand.wood = withHand.wood - offer.getWood + offer.giveWood;

        hostHand.grain = hostHand.grain + offer.getGrain - offer.giveGrain;
        withHand.grain = withHand.grain - offer.getGrain + offer.giveGrain;

        hostHand.sheep = hostHand.sheep + offer.getSheep - offer.giveSheep;
        withHand.sheep = withHand.sheep - offer.getSheep + offer.giveSheep;
    }
示例#51
0
 void moveHandAction(PlayerHand hand, Point to)
 {
     Actions.AddAction(new TweenPositionTo(hand, new Vector2(to.X + 15, to.Y + 30), 1f, Linear.EaseIn), true);
 }
示例#52
0
    public bool IsFairTrade(PlayerHand a, PlayerHand b)
    {
        PlayerHand get = a;
        PlayerHand give = b;

        bool fairTrade = Mathf.Abs ((float)(get.ValueOfHand () - give.ValueOfHand ())) <= AIEngine.AverageValue ();
        return fairTrade;
    }
示例#53
0
    // Use this for initialization
    void Start()
    {
        tileGenerator = GetComponent<TileGenerator>();
        playerHand = GetComponent<PlayerHand>();
        moveSlider = GameObject.FindGameObjectWithTag("MoveSlider");

        moveSliderTextTextComponent = GameObject.FindGameObjectWithTag("SliderText").GetComponent<Text>();

        movePanel = GameObject.FindGameObjectWithTag("SelectAmountToMovePanel");
        movePanel.SetActive(false); // Since you cant find gameobjects that arent active, this must be done first

        endTurnButton = GameObject.FindGameObjectWithTag("EndTurnButton");
        endTurnButton.SetActive(false);
    }
示例#54
0
文件: AIEngine.cs 项目: Gabino3/socAI
        private Objective(Player player, GameState gamestate, List<Edge> roads, List<Node> settlements, List<Node> cities, double score, PlayerHand hand, int curLongestRoad)
        {
            List<Edge> roadsCopy = new List<Edge>();
            List<Node> settlementsCopy = new List<Node>();
            List<Node> citiesCopy = new List<Node>();

            foreach(Edge road in roads) {
                roadsCopy.Add (road);
            }
            foreach(Node settlement in settlements) {
                settlementsCopy.Add (settlement);
            }
            foreach(Node city in cities) {
                citiesCopy.Add (city);
            }

            this.player = player;
            this.gamestate = gamestate;
            this.roads = roadsCopy;
            this.settlements = settlementsCopy;
            this.cities = citiesCopy;
            this.score = score;
            this.cardsNeeded = hand;
            this.curLongestRoad = curLongestRoad;
        }