using u16 = unsigned short;
using uu = unsigned int;
enum SHAPE : u16
{
C = 1 << 0,
H = 1 << 1,
D = 1 << 2,
S = 1 << 3,
};
struct CARD
{
u16 number;
SHAPE shape;
};
using hand_t = std::array< CARD, 7 >;
// A 2 3 4 5 6 7 8 9 10 J Q K A
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// return straight position
auto is_straight( const hand_t& hand, const int shared = 0 )
{
u16 checker = shared;
for( auto card : hand )
checker |= 1 << card.number;
checker |= ( checker & 0b10 ) << 13;
const u16 top = 0b0111110000000000;
for( int count = 10; checker; checker <<= 1, --count )
if( ( checker & top ) == top ) return count;
return 0;
}
int main()
{
hand_t hand
{ {
{ 2, S }, { 3, S }, { 10, S }, { 11, S }, { 12, S },
{ 13, S }, { 1, S },
} };
cout << is_straight( hand ) << endl;
getchar();
return 0;
}
잠깐 찾아보니 텍사스 홀덤은 공유카드 5장에 자기카드 2장 들고 합으로 보는듯 해서,
공유든, 아니면 점진적인 판단이든 가능하게 shared 를 넣었음.
10 부터 시작하는 스트레이트일 경우 10
1 부터 시작하는 스트레이트일 경우 1
없을 경우 0 을 리턴하게 됨
코세님이... 주석을 쓴다고?? - 엔타로 하스켈!
원래 true false 를 리턴하려다 그러면 양측다 스트레이트일 경우 비교가 안될듯 하여 위치를 리턴하게 되었는데 함수명은 귀찮아서 안바꿈.
헉헉 감사하옵니다ㅜㅜ
단순하고 적절한 코드네요.