{"id":3789,"date":"2019-10-12T00:01:08","date_gmt":"2019-10-12T07:01:08","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=3789"},"modified":"2019-10-19T10:18:54","modified_gmt":"2019-10-19T17:18:54","slug":"flush-straight-and-straight-flush-tests-poker-vi","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=3789","title":{"rendered":"Flush, Straight, and Straight Flush Tests (Poker VI)"},"content":{"rendered":"<p>After pulling out any hands arranged in a straight pattern, covered in <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3777\">last week&#8217;s Lesson<\/a>, the next logical test is for a flush. The flush draw is when all cards are of the same suit.<br \/>\n<!--more--><br \/>\nHere is the <em>flush()<\/em> function I wrote to determine when cards in the hand represented by the <em>playing_card<\/em> structure <code>p<\/code> are arranged as a flush draw:<\/p>\n<pre class=\"screen\">\r\n<span class=\"comments\">\/* Determine a flush draw *\/<\/span>\r\nint flush(struct playing_card p[])\r\n{\r\n    wchar_t s;\r\n    int x;\r\n\r\n    <span class=\"comments\">\/* obtain the first card's suit *\/<\/span>\r\n    s = p[0].suit;\r\n    <span class=\"comments\">\/* compare with all the other cards *\/<\/span>\r\n    for( x=1; x&lt;HAND_SIZE; x++ )\r\n    {\r\n        if( s != p[x].suit )\r\n            return(FALSE);\r\n    }\r\n\r\n    return(TRUE);\r\n}<\/pre>\n<p>After the first card&#8217;s suit is obtained (<code>p[0].suit<\/code>), its value is compared with the remaining four cards in the hand. If any other card doesn&#8217;t match, <code>FALSE<\/code> is returned. If the code survives the <em>for<\/em> loop, <code>TRUE<\/code> is returned.<\/p>\n<p>To test the hand drawn, the <em>main()<\/em> function offers a series of <em>if<\/em> tests. The first is for the straight flush test:<\/p>\n<pre class=\"screen\">\r\nif( straight(hand[x]) && flush(hand[x]) )\r\n{\r\n\twprintf(L\" - Straight Flush\\n\");\r\n\tx++;\r\n\tcontinue;\r\n}<\/pre>\n<p>If the hand returns <code>TRUE<\/code> for both the <em>straight()<\/em> and <em>flush()<\/em> functions, the result is a straight flush. Text is output, the looping variable <code>x<\/code> is incremented, and the <em>continue<\/em> statement skips the remaining tests, looping another time.<\/p>\n<p>The next test is for a straight:<\/p>\n<pre class=\"screen\">\r\nif( straight(hand[x]) )\r\n{\r\n\twprintf(L\" - Straight\\n\");\r\n\tx++;\r\n\tcontinue;\r\n}<\/pre>\n<p>Then comes the flush test:<\/p>\n<pre class=\"screen\">\r\nif( flush(hand[x]) )\r\n{\r\n\twprintf(L\" - Flush\\n\");\r\n\tx++;\r\n\tcontinue;\r\n}<\/pre>\n<p><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2019_10_12-Lesson.c\" rel=\"noopener noreferrer\" target=\"_blank\">Click here<\/a> to view the full source code on GitHub.<\/p>\n<p>I modified the <em>playing_card<\/em> <code>hand[][]<\/code> array to feature a flush and straight flush in the samples. Here&#8217;s the program&#8217;s output:<\/p>\n<p><code>Hand 1: 5&#x2666; 5&#x2660; 6&#x2666; 9&#x2666; 9&#x2665;<br \/>\nHand 2: 2&#x2660; 4&#x2660; 6&#x2660; 10&#x2660; K&#x2660; - Flush<br \/>\nHand 3: 6&#x2660; 7&#x2663; 7&#x2665; 9&#x2665; J&#x2666;<br \/>\nHand 4: 4&#x2665; 5&#x2665; 6&#x2665; 7&#x2665; 8&#x2665; - Straight Flush<br \/>\nHand 5: A&#x2665; 3&#x2665; 7&#x2666; K&#x2663; K&#x2665;<br \/>\nHand 6: A&#x2666; 10&#x2663; J&#x2663; Q&#x2665; K&#x2663; - Straight<\/code><\/p>\n<p>In <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3799\">next week&#8217;s Lesson<\/a>, the code is updated further to perform tests for four-of-a-kind, three-of-a-kind, and  a full house. These tests are ordered to process the hands in a logical manner without having to write repetitive code. The final tests, presented later this month, is for one and two pairs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Testing for a flush draw in poker isn&#8217;t complex, but it&#8217;s the second required step in filtering the various hand combinations. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3789\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3789","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3789"}],"version-history":[{"count":7,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3789\/revisions"}],"predecessor-version":[{"id":3814,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3789\/revisions\/3814"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}