0
// SPDX-License-Identifier: MIT 
pragma solidity ^0.8.0;

contract NoLimitPoker {
    address public dealer;
    address public smallBlind;
    address public bigBlind;
    uint public minBuyIn;
    uint public maxBuyIn;
    uint public smallBlindAmount;
    uint public bigBlindAmount;

    enum Phase {PreFlop, Flop, Turn, River, Showdown}
    Phase public currentPhase;

    struct Player {
        address payable playerAddress;
        uint balance;
        uint bet;
        bool folded;
        bytes2[2] hand;
        bytes5[5] communityCards;
        bytes5 bestHand;
    }

    mapping(address => Player) public players;
    address[] public playerAddresses;

    uint public pot;
    uint public currentBet;
    address public currentBettor;
   
    sortedCards;


    function isStraight(bytes7 cards) private pure returns (bool) {
        bytes7 sortedCards = sortCards(cards);

        for (uint8 i = 0; i < 3; i++) {
            bytes2 card1 = bytes2(sortedCards[i] >> 8);
            bytes2 card2 = bytes2(sortedCards[i + 1] >> 8);
            bytes2 card3 = bytes2(sortedCards[i + 2] >> 8);
            bytes2 card4 = bytes2(sortedCards[i + 3] >> 8);
            bytes2 card5 = bytes2(sortedCards[i + 4] >> 8);

            if (card1 + 1 == card2 &&
                card2 + 1 == card3 &&
                card3 + 1 == card4 &&
                card4 + 1 == card5) {
                return true;
            }
        }

        // Check special case A-2-3-4-5
        if (bytes2(sortedCards[0] >> 8) == 14 && bytes2(sortedCards[1] >> 8) == 5) {
            bytes2 card2 = bytes2(sortedCards[1] >> 8);
            bytes2 card3 = bytes2(sortedCards[2] >> 8);
            bytes2 card4 = bytes2(sortedCards[3] >> 8);
            bytes2 card5 = bytes2(sortedCards[4] >> 8);

            if (card2 + 1 == card3 &&
                card3 + 1 == card4 &&
                card4 + 1 == card5) {
                return true;
            }
        }

        return false;
    }

1 Answer 1

0

You to declare the type of variable for the sortedCards. Like an struct with the suit and value.

Struct Card {
 suit: string;
 value: uint32;
}

Card[] sortedCard;

So you would have an Ace of Spades and so on. This array should have an lenght of 51, and you would need to encode values for for queen, king. I'm not familiar with card games but the logic goes through it.

Also you shouldn't declare the state for the cards outside the game function since it will restart as soon as the game ends. The deck should be immutable and you should sort the index of it using chainlink.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.