poker.c 33 KB

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