Skip to content

Representing cards as bits #10

Open
@andy5995

Description

@andy5995

An alternate implementation to either add or replace the current one

LucasSantos91:

I implemented a poker calculator many years ago, here are some things that I learned.
You can get excellent performance by representing cards as bits. A hand can be composed of 4 u13, each one representing one suit. Bit 0 represents card 2 and bit 12 represents an Ace. Testing for a flush can be done by checking if the pop count of a suit is at least 5. Testing for a straight can be done by or’ing all suits and checking if the set bits are contiguous. Checking for a pair can be done by and’ing each pair of suits and checking if any of these is different from 0

https://ziggit.dev/t/zigpokerhands/3551

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions