private void assert(PlayerImplementation Player, Context context)
    {
        int    PlayerCount   = context.playersToGetAction.Count;
        int    Pot           = context.CurrentPot;
        int    bigBlind      = context.BigBlind;
        string status        = context.currentAction.ToString();
        float  HandStrength  = Player.HandStrength;
        float  HandPotential = Player.HandPotential;
        string state         = context.state().ToString();
        int    callAmount    = context.CallAmount;
        int    PlayerMoney   = Player.Chips;

        Debug.Log(PlayerCount);
        Debug.Log(Pot);
        Debug.Log(bigBlind);
        Debug.Log(status);
        Debug.Log(HandStrength);
        Debug.Log(HandPotential);
        Debug.Log(state);
        Debug.Log(callAmount);
        Debug.Log(PlayerMoney);
        Debug.Log("*******");

        string goal = "decisionResult(" + PlayerCount + "," +
                      Pot + "," + bigBlind + "," + status + "," + HandStrength + "," +
                      HandPotential + "," + state + "," + callAmount + "," + PlayerMoney + ").";

        UnityExtensionMethods.IsTrueParsed(kB, goal);
    }
 public void evaluateHand(List <Card> cards, PlayerImplementation playerImplementation)
 {
     orders.Enqueue(new EvaluateHandOrder(cards, playerImplementation));
     if (!EvaluationProcess)
     {
         StartCoroutine(evaluateHandProcess());
     }
 }
    IEnumerator makeDecisionProcess(PlayerImplementation player, Context context)
    {
        PlayerAction action = playerDecision.MakeDecision(player, context);

        yield return(new WaitForSeconds(Random.Range(0.2f, 0.7f)));

        player.setAction(action);
        yield return(null);
    }
    public void giveChips(PlayerImplementation player, int chips)
    {
        if (chips < 0)
        {
            throw new UnityException("chips manipulation");
        }
        player.PlayerInstance.gameManager.destroyPotChips();
        player.PlayerInstance.gameManager.soundManager.PlayChipsSound();
        player.PlayerInstance.VisualizeChips(chips);
        int hisChips = Chips [player.Id];

        hisChips         += chips;
        Chips [player.Id] = hisChips;
        ExecuteEvents.Execute <PlayerHandler> (player.PlayerInstance.gameObject, null, (x, y) => x.editChipsText(hisChips));
    }
        public void AceCanBeEleven()
        {
            var testDeck = new DeckMock(new[]
            {
                new Card(CardFace.Jack, Suit.Clubs),
                new Card(CardFace.Ace, Suit.Diamonds),
            });

            var player = new PlayerImplementation(testDeck);

            player.PlayTurn();
            player.PlayTurn();

            Assert.AreEqual(21, player.HandValue());
        }
        public void AceChangesValue()
        {
            var testDeck = new DeckMock(new[]
            {
                new Card(CardFace.Ace, Suit.Clubs),
                new Card(CardFace.Ace, Suit.Diamonds),
                new Card(CardFace.Five, Suit.Hearts),
                new Card(CardFace.Five, Suit.Hearts),
            });

            var player = new PlayerImplementation(testDeck);

            player.PlayTurn();
            player.PlayTurn();

            Assert.AreEqual(12, player.HandValue());
        }
        public void AddThreeAces()
        {
            var testDeck = new DeckMock(new[]
            {
                new Card(CardFace.Ace, Suit.Clubs),
                new Card(CardFace.Ace, Suit.Diamonds),
                new Card(CardFace.Ace, Suit.Hearts),
            });

            var player = new PlayerImplementation(testDeck);

            player.PlayTurn();
            player.PlayTurn();
            player.PlayTurn();

            Assert.Equal(13, player.HandValue());
        }
    // Use this for initialization
    void Start()
    {
        gameManager          = GameObject.Find("GameManager").GetComponent <GameManager> ();
        playerImplementation = new PlayerImplementation(this, gameManager, transform.name);

        CardsHolder  = transform.Find("Cards");
        waitingImage = transform.Find("Image").Find("Waiting").GetComponent <Image> ();
        ChipsPanel   = transform.Find("Chips");
        Transform center = GameObject.Find("Canvas").transform.Find("Center");

        playerMoney = transform.Find("money").Find("ChipsData").GetComponent <Text> ();

        float y     = center.position.y - ChipsPanel.position.y;
        float x     = center.position.x - ChipsPanel.position.x;
        float angle = (Mathf.Atan2(y, x) * Mathf.Rad2Deg) - 90;

        ChipsPanel.Rotate(new Vector3(0, 0, angle));
        ChipsPanel.position += radius * ChipsPanel.TransformDirection(Vector3.up);

        transform.GetComponentInParent <PlayersManager> ().init(this);
    }
Example #9
0
    public int compareTwoHands(PlayerImplementation player1, PlayerImplementation player2)
    {
        int rank1 = HandStrengthEvaluater.rank(player1.evaluatedCards.name);
        int rank2 = HandStrengthEvaluater.rank(player2.evaluatedCards.name);

        string cardsEvaluated1 = "[";

        for (int i = 0; i < player1.evaluatedCards.Cards.Count; i++)
        {
            if (i < player1.evaluatedCards.Cards.Count - 1)
            {
                cardsEvaluated1 += player1.evaluatedCards.Cards [i].CardValue + ",";
            }
            else
            {
                cardsEvaluated1 += player1.evaluatedCards.Cards [i].CardValue + "]";
            }
        }

        string cardsEvaluated2 = "[";

        for (int i = 0; i < player2.evaluatedCards.Cards.Count; i++)
        {
            if (i < player2.evaluatedCards.Cards.Count - 1)
            {
                cardsEvaluated2 += player2.evaluatedCards.Cards [i].CardValue + ",";
            }
            else
            {
                cardsEvaluated2 += player2.evaluatedCards.Cards [i].CardValue + "]";
            }
        }

        string query  = "X:result(" + rank1 + "," + rank2 + "," + cardsEvaluated1 + "," + cardsEvaluated2 + ",X).";
        int    result = int.Parse(UnityExtensionMethods.SolveForParsed(kB, query).ToString());

        return(result);
    }
    public PlayerAction MakeDecision(PlayerImplementation Player, Context context)
    {
        PlayerAction playerAction = new PlayerAction();

        assert(Player, context);
        bool   raised = false;
        int    raiseAmount;
        string decision = "Y:finalDecision(Y).";
        string result   = UnityExtensionMethods.SolveForParsed(kB, decision).ToString();

        if (result.Equals("fold"))
        {
            playerAction.set(PlayerAction.Action.Fold);
        }
        if (result.Equals("call"))
        {
            playerAction.set(PlayerAction.Action.Call);
        }
        if (result.Equals("raise"))
        {
            raised = true;
            string raiseAmountQuery = "X:raiseAmount(X).";
            raiseAmount = int.Parse(UnityExtensionMethods.SolveForParsed(kB, raiseAmountQuery).ToString());
            if (raiseAmount == 0)
            {
                playerAction.set(PlayerAction.Action.Check);
            }
            else
            {
                playerAction.raise(new PlayerAction.Raise(raiseAmount));
            }
        }

        retract(raised);

        return(playerAction);
    }
 public int Player(PlayerImplementation player)
 {
     return(Chips [player.Id]);
 }
 public EvaluateHandOrder(List <Card> cards, PlayerImplementation player)
 {
     this.cards  = cards;
     this.player = player;
 }
 public void makeDecision(PlayerImplementation player, Context context)
 {
     StartCoroutine(makeDecisionProcess(player, context));
 }
 public void winnerProcess(PlayerImplementation playerImplementation)
 {
     Debug.Log(playerImplementation.Id + " is the winnner");
 }