Exemple #1
0
    public EvaluatedHand evaluateHand(List <Card> cards)
    {
        if (cards.Count <= 2)
        {
            return(null);
        }

        assert(cards);
        string goal   = "X:evaluate(X).";
        string result = UnityExtensionMethods.SolveForParsed(kB, goal).ToString();

        List <Card> EvaluatedCards = new List <Card> ();

        for (int i = 1; i < 6; i++)
        {
            string cardValue = "X:cardValue(X," + i.ToString() + ").";
            string cardSuit  = "Y:cardSuit(Y," + i.ToString() + ").";
            int    v         = int.Parse(UnityExtensionMethods.SolveForParsed(kB, cardValue).ToString());
            var    s         = UnityExtensionMethods.SolveForParsed(kB, cardSuit);
            EvaluatedCards.Add(new Card(v, s.ToString()));
        }

        string straightPotentialCase = "Y:straightPotential(Y).";
        int    straightPotential     = int.Parse(UnityExtensionMethods.SolveForParsed(kB, straightPotentialCase).ToString());

        string flushPotentialCase = "Y:flushPotential(Y).";
        int    flushPotential     = int.Parse(UnityExtensionMethods.SolveForParsed(kB, flushPotentialCase).ToString());

        EvaluatedHand evaluatedhand = new EvaluatedHand(result, EvaluatedCards, straightPotential, flushPotential);

        retract();
        return(evaluatedhand);
    }
Exemple #2
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);
    }