poker.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. #include <furi.h>
  2. #include <gui/gui.h>
  3. #include <input/input.h>
  4. #include <stdlib.h>
  5. #include <notification/notification.h>
  6. #include <notification/notification_messages.h>
  7. #include <gui/elements.h>
  8. #include <gui/icon_i.h>
  9. /* Core game logic from
  10. https://github.com/Yaoir/VideoPoker-C
  11. */
  12. /* KNOWN BUGS
  13. This has been converted from a standalone PC console app to flipper
  14. All of the original input/output handing code has been ripped out
  15. Original code also used TONS of defines and everything was a global.
  16. As is, it does what I wanted and doesn't seem to have major issues, so that's pretty good.
  17. Game logic is handled during input and this is a bit of a mess of nested ifs.
  18. Sometimes duplicate cards will show up. there is a function to test this. I should use it better.
  19. */
  20. #define TAG "Video Poker"
  21. static void Shake(void) {
  22. NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
  23. notification_message(notification, &sequence_single_vibro);
  24. furi_record_close(RECORD_NOTIFICATION);
  25. }
  26. typedef struct {
  27. int index; /* cards value, minus 1 */
  28. char* sym; /* text appearance */
  29. int suit; /* card's suit (see just below) */
  30. int gone; /* true if it's been dealt */
  31. int held; /* for hand */
  32. } PokerPlayer_card;
  33. typedef struct {
  34. FuriMutex** model_mutex;
  35. FuriMessageQueue* event_queue;
  36. ViewPort* view_port;
  37. Gui* gui;
  38. PokerPlayer_card hand[5];
  39. PokerPlayer_card shand[5];
  40. PokerPlayer_card deck[52];
  41. int GameType; /* What rules are we using */
  42. int held[5];
  43. int score;
  44. int highscore;
  45. int pot;
  46. int GameState;
  47. int selected;
  48. int bet;
  49. int minbet;
  50. } PokerPlayer;
  51. /* GameState
  52. 0=Splash/help, OK button (later on up/down for rules or settings)
  53. 1=cards down, betting enabled, left/right to change bet, OK to confirm
  54. 2=first hand, holding enabled, left/right to pick card, OK to hold/unhold card, down to confirm
  55. 3=second hand, only confirm to claim rewards
  56. 4=game over/won
  57. 5=WIP saving gamestate
  58. */
  59. /*
  60. #define AllAmerican 0
  61. #define TensOrBetter 1
  62. #define BonusPoker 2
  63. #define DoubleBonus 3
  64. #define DoubleBonusBonus 4
  65. #define JacksOrBetter 5
  66. #define JacksOrBetter95 6
  67. #define JacksOrBetter86 7
  68. #define JacksOrBetter85 8
  69. #define JacksOrBetter75 9
  70. #define JacksOrBetter65 10
  71. #define NUMGAMES 11
  72. */
  73. /*
  74. The game in play. Default is Jacks or Better,
  75. which is coded into initialization of static data
  76. */
  77. const char* gamenames[11] = {
  78. "All American",
  79. "Tens or Better",
  80. "Bonus Poker",
  81. "Double Bonus",
  82. "Double Bonus Bonus",
  83. "Jacks or Better",
  84. "9/5 Jacks or Better",
  85. "8/6 Jacks or Better",
  86. "8/5 Jacks or Better",
  87. "7/5 Jacks or Better",
  88. "6/5 Jacks or Better"};
  89. PokerPlayer_card deck[52] = {
  90. /* index, card name, suit, gone */
  91. /* Clubs:0 Diamonds:1 Hearts: 2 Spades: 3 */
  92. {1, "2", 0, 0, 0}, {2, "3", 0, 0, 0}, {3, "4", 0, 0, 0}, {4, "5", 0, 0, 0},
  93. {5, "6", 0, 0, 0}, {6, "7", 0, 0, 0}, {7, "8", 0, 0, 0}, {8, "9", 0, 0, 0},
  94. {9, "10", 0, 0, 0}, {10, "J", 0, 0, 0}, {11, "Q", 0, 0, 0}, {12, "K", 0, 0, 0},
  95. {13, "A", 0, 0, 0},
  96. {1, "2", 1, 0, 0}, {2, "3", 1, 0, 0}, {3, "4", 1, 0, 0}, {4, "5", 1, 0, 0},
  97. {5, "6", 1, 0, 0}, {6, "7", 1, 0, 0}, {7, "8", 1, 0, 0}, {8, "9", 1, 0, 0},
  98. {9, "10", 1, 0, 0}, {10, "J", 1, 0, 0}, {11, "Q", 1, 0, 0}, {12, "K", 1, 0, 0},
  99. {13, "A", 1, 0, 0},
  100. {1, "2", 2, 0, 0}, {2, "3", 2, 0, 0}, {3, "4", 2, 0, 0}, {4, "5", 2, 0, 0},
  101. {5, "6", 2, 0, 0}, {6, "7", 2, 0, 0}, {7, "8", 2, 0, 0}, {8, "9", 2, 0, 0},
  102. {9, "10", 2, 0, 0}, {10, "J", 2, 0, 0}, {11, "Q", 2, 0, 0}, {12, "K", 2, 0, 0},
  103. {13, "A", 2, 0, 0},
  104. {1, "2", 3, 0, 0}, {2, "3", 3, 0, 0}, {3, "4", 3, 0, 0}, {4, "5", 3, 0, 0},
  105. {5, "6", 3, 0, 0}, {6, "7", 3, 0, 0}, {7, "8", 3, 0, 0}, {8, "9", 3, 0, 0},
  106. {9, "10", 3, 0, 0}, {10, "J", 3, 0, 0}, {11, "Q", 3, 0, 0}, {12, "K", 3, 0, 0},
  107. {13, "A", 3, 0, 0},
  108. };
  109. /*
  110. Image Format
  111. 0x01 = Compressed
  112. 0x00 = Reserved Section
  113. 0xa4,0x01 = 0x1a4, or, 420 - the size of the compressed array, minus this header.
  114. Rest of the data is char array output from heatshrink of the original XBM char array.
  115. Calculated Header: 0x01,0x00,0xa4,0x01
  116. from furi_hal_compress.c:
  117. typedef struct {
  118. uint8_t is_compressed;
  119. uint8_t reserved;
  120. uint16_t compressed_buff_size;
  121. } FuriHalCompressHeader;
  122. */
  123. const uint8_t _I_Splash_128x64_0[] = {
  124. 0x01, 0x00, 0x8a, 0x02, 0x00, 0x78, 0x02, 0x60, 0xe0, 0x54, 0xc0, 0x03, 0x9f, 0xc0, 0x0f, 0x5a,
  125. 0x04, 0x04, 0x1e, 0xdf, 0x08, 0x78, 0x0c, 0x60, 0xc0, 0x21, 0x90, 0x40, 0xa3, 0x00, 0xf5, 0xfe,
  126. 0x61, 0xc1, 0xe9, 0x1e, 0x8e, 0x59, 0xf0, 0x02, 0x24, 0x9f, 0x70, 0xc0, 0x63, 0x03, 0x01, 0x0c,
  127. 0x0b, 0xc1, 0x80, 0xbc, 0x83, 0xd3, 0x3f, 0x63, 0x98, 0x03, 0xcf, 0x88, 0x02, 0x1c, 0x31, 0x5d,
  128. 0x38, 0xf6, 0x19, 0xc0, 0xa0, 0xfc, 0x93, 0x13, 0x12, 0xf0, 0x38, 0x76, 0x08, 0xc7, 0x00, 0x1e,
  129. 0x5e, 0x8b, 0xcc, 0x32, 0x86, 0x0f, 0x4f, 0x0c, 0x80, 0x06, 0x20, 0x72, 0xe4, 0x5e, 0x33, 0xd4,
  130. 0x73, 0xf2, 0x5d, 0xe2, 0x10, 0xef, 0xe6, 0x02, 0x0f, 0x07, 0x84, 0x4c, 0x33, 0xd2, 0x70, 0x79,
  131. 0xd8, 0x2e, 0x11, 0x88, 0x3d, 0xff, 0xc1, 0xc7, 0x83, 0xc4, 0x20, 0x10, 0xc9, 0x18, 0x3d, 0x27,
  132. 0x18, 0x8c, 0x3c, 0xde, 0xe1, 0xe6, 0x87, 0x7e, 0x0c, 0x62, 0x12, 0x10, 0x01, 0xce, 0x31, 0x9c,
  133. 0x39, 0x9c, 0x62, 0x67, 0x0f, 0x83, 0x7f, 0x27, 0xe0, 0xf5, 0x8c, 0x71, 0xbc, 0x31, 0x8c, 0xc4,
  134. 0xe2, 0x1e, 0x62, 0x1e, 0x02, 0xe0, 0x80, 0x05, 0x1c, 0xe1, 0xdc, 0x23, 0x97, 0xc8, 0xe4, 0x5c,
  135. 0x12, 0x50, 0x40, 0x7a, 0x43, 0x38, 0x77, 0x88, 0xf4, 0x36, 0x3d, 0x1f, 0x04, 0x94, 0x20, 0x1e,
  136. 0x98, 0xce, 0x0d, 0xbe, 0x37, 0x0d, 0xcd, 0xbd, 0x0c, 0x7e, 0xbe, 0xce, 0x07, 0x1f, 0xf3, 0xfc,
  137. 0xf8, 0xb2, 0x8d, 0x30, 0x20, 0x53, 0xbe, 0x60, 0x06, 0x03, 0x78, 0xf0, 0x06, 0x4c, 0x1e, 0x34,
  138. 0x10, 0x29, 0x5e, 0x05, 0x0f, 0x00, 0xa0, 0x40, 0x24, 0x20, 0x52, 0x76, 0x88, 0x01, 0xc1, 0xe3,
  139. 0x11, 0x05, 0xc3, 0xe9, 0x20, 0x10, 0x97, 0x01, 0xcf, 0xc1, 0xf2, 0x81, 0x3f, 0xe7, 0xfc, 0x66,
  140. 0xf4, 0x02, 0xf1, 0xc0, 0x3f, 0xdf, 0xf0, 0x30, 0xc6, 0x1e, 0xe5, 0xff, 0x81, 0xf0, 0x3f, 0xe5,
  141. 0xb2, 0x80, 0x7f, 0xc1, 0xe5, 0x1c, 0x03, 0x0f, 0xe3, 0xff, 0x1f, 0xf8, 0x02, 0x48, 0x00, 0x31,
  142. 0xfe, 0x0b, 0xa4, 0x61, 0xcc, 0x62, 0xfc, 0x4f, 0xe3, 0x0f, 0x31, 0x41, 0x0e, 0x02, 0x07, 0x01,
  143. 0x07, 0x8a, 0xb4, 0xa3, 0x84, 0x71, 0x8f, 0xff, 0x20, 0x77, 0x00, 0x78, 0x95, 0x46, 0x06, 0x13,
  144. 0x10, 0x78, 0xef, 0x3f, 0x5f, 0xfc, 0xff, 0xea, 0x07, 0xf0, 0x37, 0x90, 0x3c, 0x78, 0x00, 0xf2,
  145. 0xae, 0x7f, 0x77, 0xf7, 0xaf, 0xec, 0x0f, 0x88, 0x41, 0x1b, 0x06, 0x02, 0x03, 0xc0, 0x02, 0x8c,
  146. 0x08, 0x5c, 0x37, 0xff, 0xa9, 0x3c, 0x7b, 0xcc, 0x52, 0xe0, 0x70, 0x7c, 0x31, 0x89, 0xe4, 0xff,
  147. 0xfb, 0xff, 0xdf, 0x8c, 0x46, 0x03, 0x1f, 0x34, 0x17, 0x83, 0xe1, 0x71, 0x8f, 0x6f, 0xe7, 0xe0,
  148. 0xc1, 0x8f, 0xfd, 0x20, 0x18, 0x65, 0x59, 0x47, 0xaf, 0x9b, 0x8b, 0x9e, 0x6f, 0xe7, 0x1f, 0x16,
  149. 0x0c, 0x3e, 0x3d, 0x00, 0xe4, 0x43, 0xd1, 0xe5, 0x3f, 0xe6, 0x6e, 0xfb, 0x39, 0x88, 0x67, 0xea,
  150. 0xff, 0xc5, 0x22, 0x8f, 0xc0, 0xf0, 0x41, 0x71, 0xe7, 0x76, 0xf9, 0x98, 0x48, 0x64, 0x17, 0x59,
  151. 0x38, 0x05, 0x8f, 0xc0, 0xd0, 0x5f, 0xe8, 0x0f, 0x1a, 0xdb, 0xe6, 0xb1, 0xd1, 0xa0, 0x50, 0x85,
  152. 0x59, 0x7e, 0x16, 0x05, 0x06, 0x80, 0x71, 0xbf, 0xf7, 0x19, 0x85, 0x99, 0x74, 0x6d, 0x31, 0x02,
  153. 0x10, 0x88, 0x7c, 0xdd, 0xdb, 0x84, 0x62, 0x7c, 0x0f, 0x38, 0xe5, 0xf0, 0x1e, 0x97, 0xce, 0x67,
  154. 0xbc, 0xb6, 0x40, 0xa3, 0x98, 0x00, 0xc5, 0x76, 0x53, 0x8c, 0x67, 0x1e, 0x07, 0x0e, 0x63, 0x0a,
  155. 0xe4, 0x9c, 0x62, 0x0f, 0x11, 0x41, 0x95, 0x88, 0x1e, 0x41, 0xd1, 0x8c, 0x49, 0x80, 0xe6, 0x00,
  156. 0x50, 0xb8, 0xa3, 0x07, 0xf1, 0x7f, 0x06, 0xb8, 0x00, 0x61, 0xce, 0xb2, 0x9c, 0x53, 0x01, 0xf3,
  157. 0xf0, 0x55, 0x97, 0xd0, 0x3f, 0x40, 0x03, 0xfd, 0x33, 0xc8, 0x01, 0x71, 0x92, 0x78, 0x80, 0x2f,
  158. 0x80, 0x6f, 0x20, 0x03, 0xff, 0x23, 0xe7, 0x02, 0x02, 0x18, 0x01, 0xa3, 0x91, 0x00, 0x18, 0xc3,
  159. 0x20, 0x91, 0xc0, 0x7c, 0x7f, 0x83, 0x42, 0xaa, 0x1f, 0xe0, 0xbe, 0x60, 0x46, 0xa2, 0x81, 0xe2,
  160. 0x24, 0x21, 0xf9, 0x54, 0x14, 0x18, 0x9e, 0x3f, 0xe4, 0x29, 0x00, 0x12, 0x0e, 0xb0, 0x28, 0x50,
  161. 0x3c, 0x60, 0x50, 0x85, 0xf4, 0x7f, 0xb8, 0x3f, 0xf3, 0xf8, 0x83, 0xe0, 0x00, 0x38, 0x6e, 0x0c,
  162. 0xc3, 0xf2, 0x2f, 0x94, 0x09, 0x07, 0xc7, 0xf7, 0x3f, 0xfe, 0x0d, 0xc4, 0x00, 0xfc, 0x4c, 0x05,
  163. 0x86, 0x15, 0x23, 0x92, 0x03, 0xe7, 0xf9, 0x80, 0x0f, 0x97, 0x52, 0x0c, 0x2f, 0xb1, 0xf8, 0xe3,
  164. 0x01, 0xf3, 0x82, 0x27, 0x8d, 0xe6, 0x41, 0x1c, 0x17, 0xcf, 0xfc, 0x3e, 0x64, 0xf8,
  165. };
  166. const uint8_t* _I_Splash_128x64[] = {_I_Splash_128x64_0};
  167. const Icon I_Splash_128x64 =
  168. {.width = 128, .height = 64, .frame_count = 1, .frame_rate = 0, .frames = _I_Splash_128x64};
  169. /*
  170. const uint8_t _I_BadEnd_128x64_0[] = {
  171. 0x01, 0x00, 0xDF, 0x01, 0x00, 0x2c, 0x12, 0x01, 0x02, 0x80, 0x40, 0x70, 0x10, 0x0a, 0x04, 0x02,
  172. 0x41, 0x3e, 0xcf, 0x63, 0xfb, 0xfe, 0xc8, 0x18, 0x3e, 0x6f, 0xdb, 0xfc, 0xf8, 0x3c, 0x60, 0xe0,
  173. 0xf9, 0xb3, 0x6c, 0xf3, 0x3c, 0x1b, 0x6c, 0x18, 0x5f, 0x40, 0xf1, 0xe7, 0xdb, 0xc1, 0xf4, 0x2f,
  174. 0x10, 0x78, 0xdb, 0xbc, 0xdf, 0xf0, 0x04, 0x59, 0x81, 0xe3, 0xc1, 0xb6, 0x41, 0x83, 0xd1, 0x00,
  175. 0xbf, 0x6c, 0xc9, 0xe6, 0x0f, 0x91, 0xf8, 0x9b, 0xcc, 0x1f, 0x20, 0x06, 0x07, 0xf8, 0x3e, 0x0b,
  176. 0x32, 0x00, 0x50, 0x88, 0xc4, 0x20, 0x10, 0x85, 0xfd, 0x03, 0xfc, 0x1f, 0xe0, 0xff, 0x07, 0xf9,
  177. 0x7f, 0xc3, 0xdc, 0x89, 0x10, 0x7d, 0x00, 0x04, 0x1f, 0xe0, 0xfd, 0xfc, 0x40, 0xc1, 0xfb, 0x07,
  178. 0x8e, 0x2f, 0xf3, 0x9f, 0x00, 0xb0, 0x7f, 0x97, 0xf6, 0x0a, 0x11, 0x10, 0xa3, 0xec, 0x10, 0x21,
  179. 0x32, 0x07, 0xd0, 0x18, 0x40, 0xa2, 0x0f, 0xb0, 0x20, 0x81, 0xc4, 0x1f, 0xeb, 0xfa, 0xbf, 0x84,
  180. 0x86, 0x01, 0xc8, 0x5f, 0xd0, 0x0c, 0x81, 0xe2, 0x05, 0x10, 0x7e, 0xdc, 0xc1, 0xf5, 0x01, 0xe0,
  181. 0x41, 0xf2, 0x17, 0xf0, 0x7d, 0xaf, 0x0a, 0x7e, 0x0f, 0xbf, 0x84, 0x7f, 0x21, 0x1f, 0x2b, 0x8e,
  182. 0x3c, 0xbe, 0xd3, 0xf0, 0x78, 0xc4, 0xfa, 0x0b, 0xf2, 0x00, 0x08, 0x81, 0xa1, 0xf3, 0x08, 0x9f,
  183. 0xc0, 0x1e, 0x57, 0x00, 0x7b, 0x60, 0x60, 0x3e, 0x08, 0x4f, 0x80, 0x1e, 0x59, 0x05, 0xc1, 0x03,
  184. 0xce, 0xc3, 0x00, 0x2f, 0x88, 0x3c, 0xe2, 0x10, 0x20, 0x78, 0xbd, 0xc6, 0xff, 0x7c, 0x8c, 0x0e,
  185. 0x48, 0x1e, 0x90, 0x48, 0x47, 0xe2, 0x06, 0x1b, 0x1e, 0x3c, 0x1c, 0x1e, 0x80, 0x01, 0x93, 0xad,
  186. 0x06, 0x1e, 0x0a, 0x28, 0x04, 0x18, 0x1e, 0x81, 0xe1, 0x90, 0x20, 0x46, 0x49, 0xa9, 0x91, 0x3e,
  187. 0x46, 0xf8, 0x0f, 0xac, 0x48, 0x3c, 0xb0, 0x82, 0x52, 0x07, 0xa1, 0x08, 0x43, 0xe5, 0x72, 0x93,
  188. 0x41, 0x7e, 0x01, 0x01, 0x07, 0xc7, 0x8a, 0x97, 0xa9, 0x39, 0x88, 0xa0, 0x7f, 0x00, 0xf2, 0x08,
  189. 0x0c, 0x03, 0x25, 0x54, 0x88, 0xe9, 0x66, 0x11, 0xc2, 0x99, 0x9e, 0x07, 0xff, 0x13, 0x90, 0x7f,
  190. 0xb2, 0x60, 0xf2, 0xaa, 0x79, 0x1b, 0xe5, 0x01, 0xfe, 0x1f, 0xca, 0x41, 0x08, 0xb0, 0xd4, 0xe2,
  191. 0x33, 0x9c, 0x9f, 0x13, 0xff, 0x07, 0xc0, 0x0c, 0x04, 0x1e, 0x54, 0x08, 0x40, 0x64, 0x80, 0x03,
  192. 0x84, 0xff, 0xc0, 0x68, 0x10, 0x0f, 0x80, 0x3d, 0x13, 0xc2, 0x00, 0x28, 0x25, 0xfa, 0x00, 0x0f,
  193. 0x76, 0x60, 0x83, 0xcc, 0x04, 0x20, 0xc1, 0x07, 0xaf, 0xc8, 0x52, 0x52, 0x00, 0x7a, 0x2f, 0xcc,
  194. 0x16, 0x31, 0x30, 0x49, 0x48, 0x17, 0xe5, 0x20, 0xc0, 0x23, 0xce, 0x81, 0x80, 0x88, 0xe6, 0x24,
  195. 0x7c, 0x69, 0xc0, 0xd0, 0xa2, 0x1c, 0x00, 0x79, 0x85, 0x07, 0xe3, 0xa4, 0xb0, 0x4a, 0x64, 0xa0,
  196. 0xf3, 0x57, 0x9d, 0x82, 0x01, 0x80, 0x84, 0x54, 0xb2, 0x19, 0x48, 0x91, 0x90, 0xa2, 0x1f, 0x00,
  197. 0x79, 0x0f, 0x87, 0x80, 0x0f, 0x44, 0x21, 0x03, 0xd0, 0x3e, 0x26, 0x01, 0xa6, 0x44, 0x2c, 0x79,
  198. 0xc0, 0x79, 0xb3, 0xc4, 0xbe, 0x5e, 0x01, 0x08, 0x80, 0x09, 0x56, 0x20, 0x01, 0x98, 0x03, 0xc4,
  199. 0xfe, 0x51, 0x0b, 0xf8, 0x3c, 0xf8, 0x00, 0x32, 0x9c, 0x7f, 0x01, 0xe8, 0x1f, 0x40, 0x21, 0xd7,
  200. 0x81, 0xfb, 0x80, 0xcf, 0x8f, 0x44, 0x1e, 0x7c, 0x88, 0x38, 0x28, 0x70, 0xe4, 0x92, 0xff, 0xc7,
  201. 0xef, 0x1f, 0x80,
  202. };
  203. const uint8_t* _I_BadEnd_128x64[] = {_I_BadEnd_128x64_0};
  204. const Icon I_BadEnd_128x64 =
  205. {.width = 128, .height = 64, .frame_count = 1, .frame_rate = 0, .frames = _I_BadEnd_128x64};
  206. */ /* space savings until external apps are possible */
  207. const uint8_t _I_Hand_12x10_0[] = {
  208. 0x01, 0x00, 0x11, 0x00, 0x8c, 0x40, 0x25, 0x00, 0x16, 0xb4, 0x40,
  209. 0x35, 0x10, 0x1d, 0x5c, 0x1b, 0x5b, 0x0a, 0x84, 0xc2, 0x80,
  210. };
  211. const uint8_t* _I_Hand_12x10[] = {_I_Hand_12x10_0};
  212. const Icon I_Hand_12x10 =
  213. {.width = 12, .height = 10, .frame_count = 1, .frame_rate = 0, .frames = _I_Hand_12x10};
  214. const uint8_t _I_CardBack_22x35_0[] = {
  215. 0x01, 0x00, 0x23, 0x00, 0xfe, 0x7f, 0xe1, 0xf0, 0x28, 0x04, 0x43, 0xe3, 0xff,
  216. 0x91, 0xea, 0x75, 0x52, 0x6a, 0xad, 0x56, 0x5b, 0xad, 0xd5, 0x4a, 0x80, 0xbe,
  217. 0x05, 0xf0, 0x2f, 0x81, 0x7c, 0x0b, 0x45, 0x32, 0x2c, 0x91, 0x7c, 0x8c, 0xa4,
  218. };
  219. const uint8_t* _I_CardBack_22x35[] = {_I_CardBack_22x35_0};
  220. const Icon I_CardBack_22x35 =
  221. {.width = 22, .height = 35, .frame_count = 1, .frame_rate = 0, .frames = _I_CardBack_22x35};
  222. //uncompressed but lol
  223. const uint8_t _I_club_7x8_0[] = {0x00, 0x08, 0x1c, 0x1c, 0x6b, 0x7f, 0x36, 0x08, 0x1c};
  224. const uint8_t* _I_club_7x8[] = {_I_club_7x8_0};
  225. const Icon I_club_7x8 =
  226. {.width = 7, .height = 8, .frame_count = 1, .frame_rate = 0, .frames = _I_club_7x8};
  227. //uncompressed but lol
  228. const uint8_t _I_diamond_7x8_0[] = {0x00, 0x00, 0x08, 0x1c, 0x3e, 0x7f, 0x3e, 0x1c, 0x08};
  229. const uint8_t* _I_diamond_7x8[] = {_I_diamond_7x8_0};
  230. const Icon I_diamond_7x8 =
  231. {.width = 7, .height = 8, .frame_count = 1, .frame_rate = 0, .frames = _I_diamond_7x8};
  232. //uncompressed
  233. const uint8_t _I_hearts_7x8_0[] = {0x00, 0x00, 0x36, 0x7f, 0x7f, 0x7f, 0x3e, 0x1c, 0x08};
  234. const uint8_t* _I_hearts_7x8[] = {_I_hearts_7x8_0};
  235. const Icon I_hearts_7x8 =
  236. {.width = 7, .height = 8, .frame_count = 1, .frame_rate = 0, .frames = _I_hearts_7x8};
  237. //uncompressed
  238. const uint8_t _I_spade_7x8_0[] = {0x00, 0x08, 0x1c, 0x3e, 0x7f, 0x7f, 0x36, 0x08, 0x1c};
  239. const uint8_t* _I_spade_7x8[] = {_I_spade_7x8_0};
  240. const Icon I_spade_7x8 =
  241. {.width = 7, .height = 8, .frame_count = 1, .frame_rate = 0, .frames = _I_spade_7x8};
  242. // They only included Numeric Profont22 glyphs and I don't want to fuck up the font embeds right now sooo..
  243. const uint8_t _I_King_7x8_0[] = {
  244. 0x01, 0x00, 0x1a, 0x00, 0xc1, 0xc0, 0xf8, 0x70, 0x1f, 0x1c, 0x02, 0xe7, 0x00, 0x9d, 0xc0,
  245. 0x23, 0xf0, 0x08, 0x78, 0x0c, 0x80, 0xe2, 0x0b, 0x10, 0x78, 0x84, 0xc4, 0x2e, 0x20, 0x01,
  246. };
  247. const uint8_t* _I_King_7x8[] = {_I_King_7x8_0};
  248. const Icon I_King_7x8 =
  249. {.width = 10, .height = 14, .frame_count = 1, .frame_rate = 0, .frames = _I_King_7x8};
  250. const uint8_t _I_Queen_7x8_0[] = {
  251. 0x01, 0x00, 0x13, 0x00, 0xfe, 0x40, 0x3f, 0xd0, 0x1c, 0x3c, 0x0c, 0x01,
  252. 0x76, 0x38, 0x1f, 0x8e, 0x07, 0xc7, 0x81, 0x85, 0x47, 0xf9, 0x01,
  253. };
  254. const uint8_t* _I_Queen_7x8[] = {_I_Queen_7x8_0};
  255. const Icon I_Queen_7x8 =
  256. {.width = 10, .height = 14, .frame_count = 1, .frame_rate = 0, .frames = _I_Queen_7x8};
  257. const uint8_t _I_Jack_7x8_0[] = {
  258. 0x01,
  259. 0x00,
  260. 0x0D,
  261. 0x00,
  262. 0x80,
  263. 0x40,
  264. 0xc0,
  265. 0x3a,
  266. 0x00,
  267. 0x5c,
  268. 0x3c,
  269. 0x0f,
  270. 0xfd,
  271. 0x01,
  272. 0xfe,
  273. 0x40,
  274. 0x00,
  275. };
  276. const uint8_t* _I_Jack_7x8[] = {_I_Jack_7x8_0};
  277. const Icon I_Jack_7x8 =
  278. {.width = 10, .height = 14, .frame_count = 1, .frame_rate = 0, .frames = _I_Jack_7x8};
  279. const uint8_t _I_Ace_7x8_0[] = {
  280. 0x01, 0x00, 0x13, 0x00, 0x98, 0x40, 0x2f, 0x00, 0x12, 0xe6, 0x00, 0x4b,
  281. 0x0d, 0x01, 0x00, 0x8c, 0x0e, 0x07, 0xff, 0x00, 0x90, 0x01, 0xc0,
  282. };
  283. const uint8_t* _I_Ace_7x8[] = {_I_Ace_7x8_0};
  284. const Icon I_Ace_7x8 =
  285. {.width = 10, .height = 14, .frame_count = 1, .frame_rate = 0, .frames = _I_Ace_7x8};
  286. const uint8_t _I_Ten_7x8_0[] = {
  287. 0x01, 0x00, 0x29, 0x00, 0x86, 0x7f, 0x00, 0x43, 0xfe, 0x80, 0xc3, 0xf0, 0xf0, 0x38, 0x7e,
  288. 0x0e, 0x07, 0x0c, 0xe1, 0x80, 0x87, 0xc6, 0x02, 0x1b, 0x98, 0x08, 0x67, 0x60, 0x21, 0x8f,
  289. 0x80, 0x86, 0x1e, 0x02, 0x18, 0x38, 0x08, 0x43, 0x43, 0x7f, 0x10, 0x0d, 0xfc, 0x4c, 0x20,
  290. };
  291. const uint8_t* _I_Ten_7x8[] = {_I_Ten_7x8_0};
  292. const Icon I_Ten_7x8 =
  293. {.width = 18, .height = 14, .frame_count = 1, .frame_rate = 0, .frames = _I_Ten_7x8};
  294. const Icon card_suit[4] = {I_diamond_7x8, I_club_7x8, I_hearts_7x8, I_spade_7x8};
  295. const Icon card_face[5] = {I_Ten_7x8, I_Jack_7x8, I_Queen_7x8, I_King_7x8, I_Ace_7x8};
  296. /* Sanity check: check that there are no duplicate cards in hand */
  297. static void playcard(PokerPlayer* app) {
  298. int i, c, crd;
  299. int hold[5];
  300. hold[5] = 2;
  301. // int digit;
  302. c = 1;
  303. c++;
  304. c = hold[5]; /* FIX for unused-but-set-variable */
  305. /* initialize deck */
  306. for(i = 0; i < 52; i++) deck[i].gone = 0;
  307. /* initialize hold[] */
  308. for(i = 0; i < 5; i++) hold[i] = 1;
  309. /* app->score -= bet; */
  310. if(app->score > app->highscore) {
  311. app->highscore = app->score;
  312. } /* record high water mark */
  313. for(i = 0; i < 5; i++) {
  314. /* find a card not already dealt */
  315. do crd = random() % 52;
  316. while(deck[crd].gone);
  317. hold[i] = 1;
  318. deck[crd].gone = 1;
  319. if(!app->held[i]) {
  320. app->hand[i] = deck[crd];
  321. }
  322. }
  323. }
  324. static int check_for_dupes(PokerPlayer* app) {
  325. int i, j;
  326. for(i = 0; i < 5; i++) {
  327. for(j = i + 1; j < 5; j++) {
  328. if(app->hand[i].index == app->hand[j].index && app->hand[i].suit == app->hand[j].suit)
  329. return 0;
  330. }
  331. }
  332. return 1;
  333. }
  334. /* Functions that recognize winning hands */
  335. /*
  336. Flush:
  337. returns 1 if the sorted hand is a flush
  338. */
  339. static int flush(PokerPlayer* app) {
  340. if(app->shand[0].suit == app->shand[1].suit && app->shand[1].suit == app->shand[2].suit &&
  341. app->shand[2].suit == app->shand[3].suit && app->shand[3].suit == app->shand[4].suit)
  342. return 1;
  343. return 0;
  344. }
  345. /*
  346. Straight:
  347. returns 1 if the sorted hand is a straight
  348. */
  349. static int straight(PokerPlayer* app) {
  350. if(app->shand[1].index == app->shand[0].index + 1 &&
  351. app->shand[2].index == app->shand[1].index + 1 &&
  352. app->shand[3].index == app->shand[2].index + 1 &&
  353. app->shand[4].index == app->shand[3].index + 1)
  354. return 1;
  355. /* Ace low straight: Ace, 2, 3, 4, 5 */
  356. if(app->shand[4].index == 13 && app->shand[0].index == 1 && app->shand[1].index == 2 &&
  357. app->shand[2].index == 3 && app->shand[3].index == 4)
  358. return 1;
  359. return 0;
  360. }
  361. /*
  362. Four of a kind:
  363. the middle 3 all match, and the first or last matches those
  364. */
  365. static int four(PokerPlayer* app) {
  366. if((app->shand[1].index == app->shand[2].index &&
  367. app->shand[2].index == app->shand[3].index) &&
  368. (app->shand[0].index == app->shand[2].index || app->shand[4].index == app->shand[2].index))
  369. return 1;
  370. return 0;
  371. }
  372. /*
  373. Full house:
  374. 3 of a kind and a pair
  375. */
  376. static int full(PokerPlayer* app) {
  377. if(app->shand[0].index == app->shand[1].index &&
  378. (app->shand[2].index == app->shand[3].index && app->shand[3].index == app->shand[4].index))
  379. return 1;
  380. if(app->shand[3].index == app->shand[4].index &&
  381. (app->shand[0].index == app->shand[1].index && app->shand[1].index == app->shand[2].index))
  382. return 1;
  383. return 0;
  384. }
  385. /*
  386. Three of a kind:
  387. it can appear 3 ways
  388. */
  389. static int three(PokerPlayer* app) {
  390. if(app->shand[0].index == app->shand[1].index && app->shand[1].index == app->shand[2].index)
  391. return 1;
  392. if(app->shand[1].index == app->shand[2].index && app->shand[2].index == app->shand[3].index)
  393. return 1;
  394. if(app->shand[2].index == app->shand[3].index && app->shand[3].index == app->shand[4].index)
  395. return 1;
  396. return 0;
  397. }
  398. /*
  399. Two pair:
  400. it can appear in 3 ways
  401. */
  402. static int twopair(PokerPlayer* app) {
  403. if(((app->shand[0].index == app->shand[1].index) &&
  404. (app->shand[2].index == app->shand[3].index)) ||
  405. ((app->shand[0].index == app->shand[1].index) &&
  406. (app->shand[3].index == app->shand[4].index)) ||
  407. ((app->shand[1].index == app->shand[2].index) &&
  408. (app->shand[3].index == app->shand[4].index)))
  409. return 1;
  410. return 0;
  411. }
  412. /*
  413. Two of a kind (pair), jacks or better
  414. or if the game is Tens or Better, 10s or better.
  415. */
  416. static int two(PokerPlayer* app) {
  417. int min = 10;
  418. if(app->GameType == 1) min = 9;
  419. if(app->shand[0].index == app->shand[1].index && app->shand[1].index >= min) return 1;
  420. if(app->shand[1].index == app->shand[2].index && app->shand[2].index >= min) return 1;
  421. if(app->shand[2].index == app->shand[3].index && app->shand[3].index >= min) return 1;
  422. if(app->shand[3].index == app->shand[4].index && app->shand[4].index >= min) return 1;
  423. return 0;
  424. }
  425. static int paytable[10] = {
  426. 800, /* royal flush: 800 */
  427. 50, /* straight flush: 50 */
  428. 25, /* 4 of a kind: 25 */
  429. 9, /* full house: 9 */
  430. 6, /* flush: 6 */
  431. 4, /* straight: 4 */
  432. 3, /* 3 of a kind: 3 */
  433. 2, /* two pair: 2 */
  434. 1, /* jacks or better: 1 */
  435. 0 /* nothing */
  436. };
  437. static const char* poker_handname[10] = {
  438. "Royal Flush",
  439. "Straight Flush",
  440. "Four of a Kind",
  441. "Full House",
  442. "Flush",
  443. "Straight",
  444. "Three of a Kind",
  445. "Two Pair",
  446. "Pair",
  447. "Nothing",
  448. };
  449. static int recognize(PokerPlayer* app) {
  450. int i, j, f = 0;
  451. int min = 100;
  452. PokerPlayer_card tmp[5];
  453. int st = 0, fl = 0;
  454. /* Sort hand into sorted hand (app->shand) */
  455. /* make copy of hand */
  456. for(i = 0; i < 5; i++) tmp[i] = app->hand[i];
  457. for(i = 0; i < 5; i++) {
  458. /* put lowest card in hand into next place in app->shand */
  459. for(j = 0; j < 5; j++)
  460. if(tmp[j].index <= min) {
  461. min = tmp[j].index;
  462. f = j;
  463. }
  464. app->shand[i] = tmp[f];
  465. tmp[f].index = 100; /* larger than any card */
  466. min = 100;
  467. }
  468. /* royal and straight flushes, strait, and flush */
  469. fl = flush(app);
  470. st = straight(app);
  471. if(st && fl && app->shand[0].index == 9) return 0;
  472. if(st && fl) return 1;
  473. if(four(app)) return 2;
  474. if(full(app)) return 3;
  475. if(fl) return 4;
  476. if(st) return 5;
  477. if(three(app)) return 6;
  478. if(twopair(app)) return 7;
  479. if(two(app)) return 8;
  480. /* Nothing */
  481. return 9;
  482. }
  483. void poker_draw_callback(Canvas* canvas, void* ctx) {
  484. PokerPlayer* poker_player = ctx;
  485. furi_check(furi_mutex_acquire(poker_player->model_mutex, FuriWaitForever) == FuriStatusOk);
  486. canvas_clear(canvas);
  487. char buffer[30];
  488. canvas_set_color(canvas, ColorBlack);
  489. canvas_set_font(canvas, FontSecondary);
  490. /* Magic Begins */
  491. /* Status Info */
  492. if(poker_player->GameState != 0 && poker_player->GameState != 4) {
  493. snprintf(buffer, sizeof(buffer), "%d", poker_player->score);
  494. canvas_draw_str_aligned(canvas, 127, 0, AlignRight, AlignTop, buffer);
  495. }
  496. /* Start of game. Cards are face down, bet can be changed */
  497. if(poker_player->GameState == 1) {
  498. snprintf(buffer, sizeof(buffer), "Bet:%d", poker_player->bet);
  499. canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, buffer);
  500. snprintf(buffer, sizeof(buffer), "<*> Place Bet");
  501. canvas_draw_str_aligned(canvas, 0, 9, AlignLeft, AlignTop, buffer);
  502. for(int i = 0; i < 5; ++i) {
  503. canvas_draw_icon(canvas, 5 + (i * 24), 18, &I_CardBack_22x35); /* 5, 29, 53, 77, 101 */
  504. }
  505. }
  506. /* Cards are turned face up. Bet is deducted and put in th pot. Show the selector hand */
  507. else if(poker_player->GameState == 2 || poker_player->GameState == 3) {
  508. snprintf(buffer, sizeof(buffer), "Pot:%d", poker_player->bet);
  509. canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, buffer);
  510. snprintf(buffer, sizeof(buffer), "<*> Select Hold");
  511. canvas_draw_str_aligned(canvas, 0, 9, AlignLeft, AlignTop, buffer);
  512. /* Normal or inverse to indicate selection - cards*/
  513. for(int i = 0; i < 5; ++i) {
  514. poker_player->held[i] ? canvas_draw_rbox(canvas, 5 + (i * 24), 18, 22, 35, 3) :
  515. canvas_draw_rframe(canvas, 5 + (i * 24), 18, 22, 35, 3);
  516. }
  517. /* Normal or inverse to indicate selection - card suit and value */
  518. for(int i = 0; i < 5; ++i) {
  519. poker_player->held[i] ? canvas_set_color(canvas, ColorWhite) :
  520. canvas_set_color(canvas, ColorBlack);
  521. canvas_draw_icon(canvas, 18 + (i * 24), 43, &card_suit[poker_player->hand[i].suit]);
  522. }
  523. /* Card Value. Profont_22 does not include letters (AJQK), and "10" is too big. These are bitmaps. */
  524. canvas_set_font(canvas, FontBigNumbers);
  525. for(int i = 0; i < 5; ++i) {
  526. poker_player->held[i] ? canvas_set_color(canvas, ColorWhite) :
  527. canvas_set_color(canvas, ColorBlack);
  528. if(poker_player->hand[i].index >= 1 && poker_player->hand[i].index <= 8) {
  529. snprintf(buffer, sizeof(buffer), "%s", poker_player->hand[i].sym);
  530. canvas_draw_str_aligned(canvas, 8 + (i * 24), 21, AlignLeft, AlignTop, buffer);
  531. } else {
  532. if(poker_player->hand[i].index >= 9 && poker_player->hand[i].index <= 13) {
  533. canvas_draw_icon(
  534. canvas, 7 + (i * 24), 21, &card_face[poker_player->hand[i].index - 9]);
  535. }
  536. }
  537. }
  538. /* Draw the Select hand */
  539. if(poker_player->GameState == 2) {
  540. canvas_set_color(canvas, ColorBlack);
  541. canvas_draw_icon(canvas, 11 + (poker_player->selected * 24), 54, &I_Hand_12x10);
  542. }
  543. } // GameState 2 or 3
  544. canvas_set_color(canvas, ColorBlack);
  545. canvas_set_font(canvas, FontSecondary);
  546. if(poker_player->GameState == 3) {
  547. snprintf(
  548. buffer,
  549. sizeof(buffer),
  550. "%s:%ix",
  551. poker_handname[recognize(poker_player)],
  552. paytable[recognize(poker_player)]);
  553. canvas_draw_str_aligned(canvas, 63, 61, AlignCenter, AlignBottom, buffer);
  554. }
  555. if(poker_player->GameState == 0) {
  556. canvas_draw_icon(canvas, 0, 0, &I_Splash_128x64); /* Initial launch */
  557. }
  558. if(poker_player->GameState == 4) {
  559. /* canvas_draw_icon(canvas, 0, 0, &I_BadEnd_128x64); Just Lost The Game - disabled for now :( */
  560. canvas_set_color(canvas, ColorBlack);
  561. canvas_set_font(canvas, FontSecondary);
  562. snprintf(buffer, sizeof(buffer), "%s", "You have run out of money!");
  563. canvas_draw_str_aligned(canvas, 63, 22, AlignCenter, AlignCenter, buffer);
  564. snprintf(buffer, sizeof(buffer), "%s", "At one point, you had");
  565. canvas_draw_str_aligned(canvas, 63, 32, AlignCenter, AlignCenter, buffer);
  566. snprintf(buffer, sizeof(buffer), "%d dollars", poker_player->highscore);
  567. canvas_draw_str_aligned(canvas, 63, 42, AlignCenter, AlignCenter, buffer);
  568. }
  569. furi_mutex_release(poker_player->model_mutex);
  570. }
  571. void poker_input_callback(InputEvent* input, void* ctx) {
  572. PokerPlayer* poker_player = ctx;
  573. furi_message_queue_put(poker_player->event_queue, input, FuriWaitForever);
  574. }
  575. PokerPlayer* poker_player_alloc() {
  576. PokerPlayer* poker_player = malloc(sizeof(PokerPlayer));
  577. poker_player->score = 1000;
  578. poker_player->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
  579. poker_player->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
  580. poker_player->view_port = view_port_alloc();
  581. poker_player->selected = 0;
  582. poker_player->GameState = 0;
  583. poker_player->bet = 10;
  584. poker_player->minbet = 10;
  585. poker_player->highscore = 1000;
  586. playcard(
  587. poker_player); /* Get things rolling before the player gets into the game. This will preload the hand. */
  588. view_port_draw_callback_set(poker_player->view_port, poker_draw_callback, poker_player);
  589. view_port_input_callback_set(poker_player->view_port, poker_input_callback, poker_player);
  590. poker_player->gui = furi_record_open(RECORD_GUI);
  591. gui_add_view_port(poker_player->gui, poker_player->view_port, GuiLayerFullscreen);
  592. return poker_player;
  593. }
  594. void poker_player_free(PokerPlayer* poker_player) {
  595. view_port_enabled_set(poker_player->view_port, false);
  596. gui_remove_view_port(poker_player->gui, poker_player->view_port);
  597. furi_record_close(RECORD_GUI);
  598. view_port_free(poker_player->view_port);
  599. furi_message_queue_free(poker_player->event_queue);
  600. furi_mutex_free(poker_player->model_mutex);
  601. free(poker_player);
  602. }
  603. int32_t video_poker_app(void* p) {
  604. UNUSED(p);
  605. PokerPlayer* poker_player = poker_player_alloc();
  606. InputEvent event;
  607. for(bool processing = true; processing;) {
  608. FuriStatus status = furi_message_queue_get(poker_player->event_queue, &event, 100);
  609. furi_check(furi_mutex_acquire(poker_player->model_mutex, FuriWaitForever) == FuriStatusOk);
  610. if(status == FuriStatusOk) {
  611. if(event.type == InputTypePress) {
  612. switch(event.key) {
  613. case InputKeyUp:
  614. Shake();
  615. break;
  616. case InputKeyDown:
  617. if(poker_player->GameState == 2) {
  618. playcard(poker_player);
  619. if(check_for_dupes(poker_player) == 0) {
  620. playcard(poker_player);
  621. }
  622. poker_player->GameState = 3;
  623. }
  624. break;
  625. case InputKeyLeft:
  626. if(poker_player->GameState == 1) {
  627. if(poker_player->bet >= poker_player->minbet + 10) {
  628. poker_player->bet -= 10;
  629. }
  630. } else if(poker_player->selected > 0 && poker_player->GameState == 2) {
  631. poker_player->selected--;
  632. } // Move hand left/right
  633. else if(poker_player->selected == 0 && poker_player->GameState == 2) {
  634. poker_player->selected = 4; //wraparound
  635. }
  636. break;
  637. case InputKeyRight:
  638. if(poker_player->GameState == 1) {
  639. if(poker_player->bet < poker_player->score + 10) {
  640. poker_player->bet += 10;
  641. }
  642. }
  643. if(poker_player->selected < 4 && poker_player->GameState == 2) {
  644. poker_player->selected++;
  645. } // Move hand left/right
  646. else if(poker_player->selected == 4 && poker_player->GameState == 2) {
  647. poker_player->selected = 0; //wraparound
  648. }
  649. break;
  650. case InputKeyOk:
  651. /* close splash screen */
  652. if(poker_player->GameState == 0) {
  653. poker_player->GameState = 1;
  654. } else if(poker_player->GameState == 1) {
  655. /* Pledge bet. Bet is subtracted here. Original code subtracts it during playcard
  656. but playcard is called multiple times which would otherwise subtract bet
  657. multiple times */
  658. poker_player->score -= poker_player->bet;
  659. poker_player->GameState = 2;
  660. } else if(poker_player->GameState == 2) {
  661. /* Select or un-select card to be held */
  662. poker_player->held[poker_player->selected] =
  663. !poker_player
  664. ->held[poker_player->selected]; //cursed and bad pls replace
  665. } else if(poker_player->GameState == 3) {
  666. /* accept your fate */
  667. if(recognize(poker_player) != 9) {
  668. poker_player->score +=
  669. poker_player->bet * paytable[recognize(poker_player)];
  670. }
  671. poker_player->GameState = 1;
  672. if(poker_player->bet > poker_player->score) {
  673. poker_player->bet = poker_player->score;
  674. }
  675. poker_player->held[0] = 0;
  676. poker_player->held[1] = 0;
  677. poker_player->held[2] = 0;
  678. poker_player->held[3] = 0;
  679. poker_player->held[4] = 0;
  680. if(poker_player->score <= 0) {
  681. /* lost the game */
  682. poker_player->GameState = 4;
  683. }
  684. playcard(poker_player); // shuffle shuffle
  685. } else if(poker_player->GameState == 4) {
  686. /* escape the summary, return to splash */
  687. Shake();
  688. poker_player->selected = 0;
  689. poker_player->GameState = 0;
  690. poker_player->bet = 10;
  691. poker_player->minbet = 10;
  692. poker_player->highscore = 1000;
  693. poker_player->score = 1000;
  694. poker_player->GameState = 0;
  695. }
  696. break;
  697. case InputKeyBack:
  698. /* if game is not over, we should store the game state. */
  699. processing = false;
  700. break;
  701. default:
  702. break;
  703. }
  704. }
  705. }
  706. furi_mutex_release(poker_player->model_mutex);
  707. view_port_update(poker_player->view_port);
  708. }
  709. poker_player_free(poker_player);
  710. return 0;
  711. }