Example #1
0
        public gameEngineReturnMessage Poll(string accessToken)
        {
            pollResponse returnMessage = new pollResponse();

            game associatedGame = FindGameByPlayer(accessToken);

            if (associatedGame == null)
            {
                return(null);
            }

            returnMessage.gameName = associatedGame.GetId();
            returnMessage.status   = associatedGame.GetStatus();

            List <string> names = associatedGame.GetPlayersNames();

            foreach (var n in names)
            {
                int?          rerollCount   = associatedGame.GetPlayerByName(n).GetRerollCount();
                pokerDiceHand handClaim     = associatedGame.GetPlayerByName(n).GetHandClaim();
                bool          handClaimMade = handClaim != null;
                int           livesLeft     = associatedGame.GetPlayerByName(n).GetLivesRemaining();
                returnMessage.playerStatusLines.Add(new playerStatusLine(n, livesLeft, handClaimMade, handClaim, rerollCount));
            }

            returnMessage.awaitingActionFromPlayerName = associatedGame.GetPlayerNameWithActionAwaited();

            //Decide whether or not to reveal actual hand to the calling player
            if (associatedGame.GetPlayerById(accessToken).GetName() == associatedGame.GetPlayerNameCurrentlyHoldingTheHand())
            {
                returnMessage.SetHandToView(associatedGame.GetActualHand());
            }
            return(returnMessage);
        }
Example #2
0
        private pokerDiceHand GetPreviousPlayerHandClaim()
        {
            int           previousPlayerIndex = GetIndexOfPlayerPreviousTo(playerToActIndex);
            player        previousPlayer      = playersList[previousPlayerIndex];
            pokerDiceHand pdh = previousPlayer.GetHandClaim();

            return(pdh);
        }
Example #3
0
        private bool StalemateDetected() //Use only within accept hand function
        {
            pokerDiceHand AAAAA = new pokerDiceHand("AAAAA");

            if (AAAAA == GetPreviousPlayerHandClaim())
            {
                return(true);
            }

            return(false);
        }
Example #4
0
        public bool Equals(pokerDiceHand obj)
        {
            if (ReferenceEquals(obj, null))
            {
                return(false);
            }

            if (obj.faces == faces)
            {
                return(true);
            }
            return(false);
        }
Example #5
0
        public pokerDiceHand GetNewHand()
        {
            string fiveFacesString = "";

            for (int i = 0; i < 5; i++)
            {
                fiveFacesString += mDieRoller.Roll(showAsString.y);
            }

            pokerDiceHand pdh = new pokerDiceHand(fiveFacesString);

            return(pdh);
        }
Example #6
0
        public bool DeclareHand(string playerId, pokerDiceHand hand)
        {
            player p = null;

            if ((!ConfirmPlayerIsWithActionAwaited(playerId, ref p)) ||
                (this.status != gameStatus.awaitingPlayerToClaimHandRank))
            {
                return(false);
            }
            p.SetHandClaim(hand);
            MoveTurnToNextPlayer();
            status = gameStatus.awaitingPlayerDecisionAcceptOrCallLiar;
            return(true);
        }
Example #7
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            pokerDiceHand p = obj as pokerDiceHand;

            if ((System.Object)p == null)
            {
                return(false);
            }

            return(faces == p.faces);
        }
Example #8
0
 public playerStatusLine
     (string name,
     int livesRemaining,
     bool handClaimMade      = false,
     pokerDiceHand handClaim = null,
     int?rerolledDiceCount   = null)
 {
     mName  = name;
     mClaim = null;
     if (handClaimMade)
     {
         mClaim = handClaim;
     }
     rerollDiceCount = rerolledDiceCount;
     mLivesRemaining = livesRemaining;
 }
Example #9
0
        private static bool gt(pokerDiceHand lhs, pokerDiceHand rhs)
        {
            if (lhs.handKind != rhs.handKind)
            {
                return(lhs.handKind < rhs.handKind);
            }

            if (lhs.primaryFace != rhs.primaryFace)
            {
                return(lhs.primaryFace > rhs.primaryFace);
            }
            if (lhs.secondaryFace != rhs.secondaryFace)
            {
                return(lhs.secondaryFace > rhs.secondaryFace);
            }
            return(lhs.hashcode > rhs.hashcode);
        }
Example #10
0
        public bool ReRoll(string playerId, string facesToReRoll)
        {
            player p = null;

            if ((!ConfirmPlayerIsWithActionAwaited(playerId, ref p)) ||
                (this.status != gameStatus.awaitingPlayerToChooseDiceToReRollOrNone))
            {
                return(false);
            }
            status = gameStatus.awaitingPlayerToClaimHandRank;
            p.SetRerollCount(facesToReRoll.Length);

            pokerDiceHand newHand = reroller.Reroll(currentActualHand, facesToReRoll);

            currentActualHand = newHand;
            return(true);
        }
Example #11
0
        public pokerDiceHand Reroll(pokerDiceHand oldHand, string facesToReRoll)
        {
            string oldFaces           = oldHand.getFacesOrderedByRank();
            bool   remainderFoundOkay = false;
            string retainedFaces      = Remainder(oldFaces, facesToReRoll, ref remainderFoundOkay);

            if (!remainderFoundOkay)
            {
                return(new pokerDiceHand("xxxxx"));
            }
            string newFaces = retainedFaces;
            string newRoll;

            for (int i = 0; i < facesToReRoll.Length; i++)
            {
                newRoll   = mDieRoller.Roll(showAsString.y);
                newFaces += newRoll;
            }
            pokerDiceHand pdh = new pokerDiceHand(newFaces);

            return(pdh);
        }
Example #12
0
        public permutationsCalculator()
        {
            const int diceCount = 5;

            diceFaceTicker[] tickerArray = new diceFaceTicker[diceCount];
            for (int i = 0; i < diceCount; i++)
            {
                tickerArray[i] = new diceFaceTicker();
            }
            for (int j = diceCount - 1; j >= 1; j--)
            {
                tickerArray[j - 1].AddNeighbour(tickerArray[j]);
            }
            do
            {
                pokerDiceHand pdh = new pokerDiceHand(tickerArray[0].GetString());
                string        diceFacesOrderedByRank = pdh.getFacesOrderedByRank();
                if (duplicatesCountTable.ContainsKey(diceFacesOrderedByRank))
                {
                    int oldCount = duplicatesCountTable[diceFacesOrderedByRank];
                    duplicatesCountTable[diceFacesOrderedByRank] = oldCount + 1;
                }
                else
                {
                    duplicatesCountTable.Add(diceFacesOrderedByRank, 1);
                }
                tickerArray[0].Tick();
            }while (tickerArray[diceCount - 1].hasOverflowed() == false);

            int debugNumberEntriesInDuplicatesCountTable = duplicatesCountTable.Count;

            this.permutationTable = "|";
            foreach (var pair in duplicatesCountTable)
            {
                this.permutationTable += pair.ToString() + "|";
            }
        }
Example #13
0
        public gameEngineReturnMessage DeclareHand(string accessToken, pokerDiceHand hand)
        {
            game         associatedGame = FindGameByPlayer(accessToken);
            boolResponse returnMsg      = new boolResponse();

            if (associatedGame == null)
            {
                returnMsg.okay = false;
                return(returnMsg);
            }

            bool declareAccepted = associatedGame.DeclareHand(accessToken, hand);

            if (declareAccepted)
            {
                returnMsg.okay = true;
            }
            else
            {
                returnMsg.okay = false;
            }

            return(returnMsg);
        }
Example #14
0
 public void SetHandClaim(pokerDiceHand hand)
 {
     claim = hand;
 }
Example #15
0
 public void SetHandToView(pokerDiceHand h)
 {
     hand = h;
     handIsViewableSet = true;
 }