poker.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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++)
  307. deck[i].gone = 0;
  308. /* initialize hold[] */
  309. for(i = 0; i < 5; i++)
  310. hold[i] = 1;
  311. /* app->score -= bet; */
  312. if(app->score > app->highscore) {
  313. app->highscore = app->score;
  314. } /* record high water mark */
  315. for(i = 0; i < 5; i++) {
  316. /* find a card not already dealt */
  317. do
  318. crd = random() % 52;
  319. while(deck[crd].gone);
  320. hold[i] = 1;
  321. deck[crd].gone = 1;
  322. if(!app->held[i]) {
  323. app->hand[i] = deck[crd];
  324. }
  325. }
  326. }
  327. static int check_for_dupes(PokerPlayer* app) {
  328. int i, j;
  329. for(i = 0; i < 5; i++) {
  330. for(j = i + 1; j < 5; j++) {
  331. if(app->hand[i].index == app->hand[j].index && app->hand[i].suit == app->hand[j].suit)
  332. return 0;
  333. }
  334. }
  335. return 1;
  336. }
  337. /* Functions that recognize winning hands */
  338. /*
  339. Flush:
  340. returns 1 if the sorted hand is a flush
  341. */
  342. static int flush(PokerPlayer* app) {
  343. if(app->shand[0].suit == app->shand[1].suit && app->shand[1].suit == app->shand[2].suit &&
  344. app->shand[2].suit == app->shand[3].suit && app->shand[3].suit == app->shand[4].suit)
  345. return 1;
  346. return 0;
  347. }
  348. /*
  349. Straight:
  350. returns 1 if the sorted hand is a straight
  351. */
  352. static int straight(PokerPlayer* app) {
  353. if(app->shand[1].index == app->shand[0].index + 1 &&
  354. app->shand[2].index == app->shand[1].index + 1 &&
  355. app->shand[3].index == app->shand[2].index + 1 &&
  356. app->shand[4].index == app->shand[3].index + 1)
  357. return 1;
  358. /* Ace low straight: Ace, 2, 3, 4, 5 */
  359. if(app->shand[4].index == 13 && app->shand[0].index == 1 && app->shand[1].index == 2 &&
  360. app->shand[2].index == 3 && app->shand[3].index == 4)
  361. return 1;
  362. return 0;
  363. }
  364. /*
  365. Four of a kind:
  366. the middle 3 all match, and the first or last matches those
  367. */
  368. static int four(PokerPlayer* app) {
  369. if((app->shand[1].index == app->shand[2].index &&
  370. app->shand[2].index == app->shand[3].index) &&
  371. (app->shand[0].index == app->shand[2].index || app->shand[4].index == app->shand[2].index))
  372. return 1;
  373. return 0;
  374. }
  375. /*
  376. Full house:
  377. 3 of a kind and a pair
  378. */
  379. static int full(PokerPlayer* app) {
  380. if(app->shand[0].index == app->shand[1].index &&
  381. (app->shand[2].index == app->shand[3].index && app->shand[3].index == app->shand[4].index))
  382. return 1;
  383. if(app->shand[3].index == app->shand[4].index &&
  384. (app->shand[0].index == app->shand[1].index && app->shand[1].index == app->shand[2].index))
  385. return 1;
  386. return 0;
  387. }
  388. /*
  389. Three of a kind:
  390. it can appear 3 ways
  391. */
  392. static int three(PokerPlayer* app) {
  393. if(app->shand[0].index == app->shand[1].index && app->shand[1].index == app->shand[2].index)
  394. return 1;
  395. if(app->shand[1].index == app->shand[2].index && app->shand[2].index == app->shand[3].index)
  396. return 1;
  397. if(app->shand[2].index == app->shand[3].index && app->shand[3].index == app->shand[4].index)
  398. return 1;
  399. return 0;
  400. }
  401. /*
  402. Two pair:
  403. it can appear in 3 ways
  404. */
  405. static int twopair(PokerPlayer* app) {
  406. if(((app->shand[0].index == app->shand[1].index) &&
  407. (app->shand[2].index == app->shand[3].index)) ||
  408. ((app->shand[0].index == app->shand[1].index) &&
  409. (app->shand[3].index == app->shand[4].index)) ||
  410. ((app->shand[1].index == app->shand[2].index) &&
  411. (app->shand[3].index == app->shand[4].index)))
  412. return 1;
  413. return 0;
  414. }
  415. /*
  416. Two of a kind (pair), jacks or better
  417. or if the game is Tens or Better, 10s or better.
  418. */
  419. static int two(PokerPlayer* app) {
  420. int min = 10;
  421. if(app->GameType == 1) min = 9;
  422. if(app->shand[0].index == app->shand[1].index && app->shand[1].index >= min) return 1;
  423. if(app->shand[1].index == app->shand[2].index && app->shand[2].index >= min) return 1;
  424. if(app->shand[2].index == app->shand[3].index && app->shand[3].index >= min) return 1;
  425. if(app->shand[3].index == app->shand[4].index && app->shand[4].index >= min) return 1;
  426. return 0;
  427. }
  428. static int paytable[10] = {
  429. 800, /* royal flush: 800 */
  430. 50, /* straight flush: 50 */
  431. 25, /* 4 of a kind: 25 */
  432. 9, /* full house: 9 */
  433. 6, /* flush: 6 */
  434. 4, /* straight: 4 */
  435. 3, /* 3 of a kind: 3 */
  436. 2, /* two pair: 2 */
  437. 1, /* jacks or better: 1 */
  438. 0 /* nothing */
  439. };
  440. static const char* poker_handname[10] = {
  441. "Royal Flush",
  442. "Straight Flush",
  443. "Four of a Kind",
  444. "Full House",
  445. "Flush",
  446. "Straight",
  447. "Three of a Kind",
  448. "Two Pair",
  449. "Pair",
  450. "Nothing",
  451. };
  452. static int recognize(PokerPlayer* app) {
  453. int i, j, f = 0;
  454. int min = 100;
  455. PokerPlayer_card tmp[5];
  456. int st = 0, fl = 0;
  457. /* Sort hand into sorted hand (app->shand) */
  458. /* make copy of hand */
  459. for(i = 0; i < 5; i++)
  460. tmp[i] = app->hand[i];
  461. for(i = 0; i < 5; i++) {
  462. /* put lowest card in hand into next place in app->shand */
  463. for(j = 0; j < 5; j++)
  464. if(tmp[j].index <= min) {
  465. min = tmp[j].index;
  466. f = j;
  467. }
  468. app->shand[i] = tmp[f];
  469. tmp[f].index = 100; /* larger than any card */
  470. min = 100;
  471. }
  472. /* royal and straight flushes, strait, and flush */
  473. fl = flush(app);
  474. st = straight(app);
  475. if(st && fl && app->shand[0].index == 9) return 0;
  476. if(st && fl) return 1;
  477. if(four(app)) return 2;
  478. if(full(app)) return 3;
  479. if(fl) return 4;
  480. if(st) return 5;
  481. if(three(app)) return 6;
  482. if(twopair(app)) return 7;
  483. if(two(app)) return 8;
  484. /* Nothing */
  485. return 9;
  486. }
  487. void poker_draw_callback(Canvas* canvas, void* ctx) {
  488. PokerPlayer* poker_player = ctx;
  489. furi_check(furi_mutex_acquire(poker_player->model_mutex, FuriWaitForever) == FuriStatusOk);
  490. canvas_clear(canvas);
  491. char buffer[30];
  492. canvas_set_color(canvas, ColorBlack);
  493. canvas_set_font(canvas, FontSecondary);
  494. /* Magic Begins */
  495. /* Status Info */
  496. if(poker_player->GameState != 0 && poker_player->GameState != 4) {
  497. snprintf(buffer, sizeof(buffer), "%d", poker_player->score);
  498. canvas_draw_str_aligned(canvas, 127, 0, AlignRight, AlignTop, buffer);
  499. }
  500. /* Start of game. Cards are face down, bet can be changed */
  501. if(poker_player->GameState == 1) {
  502. snprintf(buffer, sizeof(buffer), "Bet:%d", poker_player->bet);
  503. canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, buffer);
  504. snprintf(buffer, sizeof(buffer), "<*> Place Bet");
  505. canvas_draw_str_aligned(canvas, 0, 9, AlignLeft, AlignTop, buffer);
  506. for(int i = 0; i < 5; ++i) {
  507. canvas_draw_icon(canvas, 5 + (i * 24), 18, &I_CardBack_22x35); /* 5, 29, 53, 77, 101 */
  508. }
  509. }
  510. /* Cards are turned face up. Bet is deducted and put in th pot. Show the selector hand */
  511. else if(poker_player->GameState == 2 || poker_player->GameState == 3) {
  512. snprintf(buffer, sizeof(buffer), "Pot:%d", poker_player->bet);
  513. canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, buffer);
  514. snprintf(buffer, sizeof(buffer), "<*> Select Hold");
  515. canvas_draw_str_aligned(canvas, 0, 9, AlignLeft, AlignTop, buffer);
  516. /* Normal or inverse to indicate selection - cards*/
  517. for(int i = 0; i < 5; ++i) {
  518. poker_player->held[i] ? canvas_draw_rbox(canvas, 5 + (i * 24), 18, 22, 35, 3) :
  519. canvas_draw_rframe(canvas, 5 + (i * 24), 18, 22, 35, 3);
  520. }
  521. /* Normal or inverse to indicate selection - card suit and value */
  522. for(int i = 0; i < 5; ++i) {
  523. poker_player->held[i] ? canvas_set_color(canvas, ColorWhite) :
  524. canvas_set_color(canvas, ColorBlack);
  525. canvas_draw_icon(canvas, 18 + (i * 24), 43, &card_suit[poker_player->hand[i].suit]);
  526. }
  527. /* Card Value. Profont_22 does not include letters (AJQK), and "10" is too big. These are bitmaps. */
  528. canvas_set_font(canvas, FontBigNumbers);
  529. for(int i = 0; i < 5; ++i) {
  530. poker_player->held[i] ? canvas_set_color(canvas, ColorWhite) :
  531. canvas_set_color(canvas, ColorBlack);
  532. if(poker_player->hand[i].index >= 1 && poker_player->hand[i].index <= 8) {
  533. snprintf(buffer, sizeof(buffer), "%s", poker_player->hand[i].sym);
  534. canvas_draw_str_aligned(canvas, 8 + (i * 24), 21, AlignLeft, AlignTop, buffer);
  535. } else {
  536. if(poker_player->hand[i].index >= 9 && poker_player->hand[i].index <= 13) {
  537. canvas_draw_icon(
  538. canvas, 7 + (i * 24), 21, &card_face[poker_player->hand[i].index - 9]);
  539. }
  540. }
  541. }
  542. /* Draw the Select hand */
  543. if(poker_player->GameState == 2) {
  544. canvas_set_color(canvas, ColorBlack);
  545. canvas_draw_icon(canvas, 11 + (poker_player->selected * 24), 54, &I_Hand_12x10);
  546. }
  547. } // GameState 2 or 3
  548. canvas_set_color(canvas, ColorBlack);
  549. canvas_set_font(canvas, FontSecondary);
  550. if(poker_player->GameState == 3) {
  551. snprintf(
  552. buffer,
  553. sizeof(buffer),
  554. "%s:%ix",
  555. poker_handname[recognize(poker_player)],
  556. paytable[recognize(poker_player)]);
  557. canvas_draw_str_aligned(canvas, 63, 61, AlignCenter, AlignBottom, buffer);
  558. }
  559. if(poker_player->GameState == 0) {
  560. canvas_draw_icon(canvas, 0, 0, &I_Splash_128x64); /* Initial launch */
  561. }
  562. if(poker_player->GameState == 4) {
  563. /* canvas_draw_icon(canvas, 0, 0, &I_BadEnd_128x64); Just Lost The Game - disabled for now :( */
  564. canvas_set_color(canvas, ColorBlack);
  565. canvas_set_font(canvas, FontSecondary);
  566. snprintf(buffer, sizeof(buffer), "%s", "You have run out of money!");
  567. canvas_draw_str_aligned(canvas, 63, 22, AlignCenter, AlignCenter, buffer);
  568. snprintf(buffer, sizeof(buffer), "%s", "At one point, you had");
  569. canvas_draw_str_aligned(canvas, 63, 32, AlignCenter, AlignCenter, buffer);
  570. snprintf(buffer, sizeof(buffer), "%d dollars", poker_player->highscore);
  571. canvas_draw_str_aligned(canvas, 63, 42, AlignCenter, AlignCenter, buffer);
  572. }
  573. furi_mutex_release(poker_player->model_mutex);
  574. }
  575. void poker_input_callback(InputEvent* input, void* ctx) {
  576. PokerPlayer* poker_player = ctx;
  577. furi_message_queue_put(poker_player->event_queue, input, FuriWaitForever);
  578. }
  579. PokerPlayer* poker_player_alloc() {
  580. PokerPlayer* poker_player = malloc(sizeof(PokerPlayer));
  581. poker_player->score = 1000;
  582. poker_player->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
  583. poker_player->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
  584. poker_player->view_port = view_port_alloc();
  585. poker_player->selected = 0;
  586. poker_player->GameState = 0;
  587. poker_player->bet = 10;
  588. poker_player->minbet = 10;
  589. poker_player->highscore = 1000;
  590. playcard(
  591. poker_player); /* Get things rolling before the player gets into the game. This will preload the hand. */
  592. view_port_draw_callback_set(poker_player->view_port, poker_draw_callback, poker_player);
  593. view_port_input_callback_set(poker_player->view_port, poker_input_callback, poker_player);
  594. poker_player->gui = furi_record_open(RECORD_GUI);
  595. gui_add_view_port(poker_player->gui, poker_player->view_port, GuiLayerFullscreen);
  596. return poker_player;
  597. }
  598. void poker_player_free(PokerPlayer* poker_player) {
  599. view_port_enabled_set(poker_player->view_port, false);
  600. gui_remove_view_port(poker_player->gui, poker_player->view_port);
  601. furi_record_close(RECORD_GUI);
  602. view_port_free(poker_player->view_port);
  603. furi_message_queue_free(poker_player->event_queue);
  604. furi_mutex_free(poker_player->model_mutex);
  605. free(poker_player);
  606. }
  607. int32_t video_poker_app(void* p) {
  608. UNUSED(p);
  609. PokerPlayer* poker_player = poker_player_alloc();
  610. InputEvent event;
  611. for(bool processing = true; processing;) {
  612. FuriStatus status = furi_message_queue_get(poker_player->event_queue, &event, 100);
  613. furi_check(furi_mutex_acquire(poker_player->model_mutex, FuriWaitForever) == FuriStatusOk);
  614. if(status == FuriStatusOk) {
  615. if(event.type == InputTypePress) {
  616. switch(event.key) {
  617. case InputKeyUp:
  618. if(poker_player->GameState == 1) {
  619. poker_player->bet = poker_player->score;
  620. }
  621. Shake();
  622. break;
  623. case InputKeyDown:
  624. if(poker_player->GameState == 2) {
  625. playcard(poker_player);
  626. if(check_for_dupes(poker_player) == 0) {
  627. playcard(poker_player);
  628. }
  629. poker_player->GameState = 3;
  630. }
  631. break;
  632. case InputKeyLeft:
  633. if(poker_player->GameState == 1) {
  634. if(poker_player->bet >= poker_player->minbet + 10) {
  635. poker_player->bet -= 10;
  636. } else {
  637. poker_player->bet = poker_player->score;
  638. }
  639. } else if(poker_player->selected > 0 && poker_player->GameState == 2) {
  640. poker_player->selected--;
  641. } // Move hand left/right
  642. else if(poker_player->selected == 0 && poker_player->GameState == 2) {
  643. poker_player->selected = 4; //wraparound
  644. }
  645. break;
  646. case InputKeyRight:
  647. if(poker_player->GameState == 1) {
  648. if(poker_player->bet < poker_player->score) {
  649. poker_player->bet += 10;
  650. } else {
  651. poker_player->bet = poker_player->minbet;
  652. }
  653. }
  654. if(poker_player->selected < 4 && poker_player->GameState == 2) {
  655. poker_player->selected++;
  656. } // Move hand left/right
  657. else if(poker_player->selected == 4 && poker_player->GameState == 2) {
  658. poker_player->selected = 0; //wraparound
  659. }
  660. break;
  661. case InputKeyOk:
  662. /* close splash screen */
  663. if(poker_player->GameState == 0) {
  664. poker_player->GameState = 1;
  665. } else if(poker_player->GameState == 1) {
  666. /* Pledge bet. Bet is subtracted here. Original code subtracts it during playcard
  667. but playcard is called multiple times which would otherwise subtract bet
  668. multiple times */
  669. poker_player->score -= poker_player->bet;
  670. poker_player->GameState = 2;
  671. } else if(poker_player->GameState == 2) {
  672. /* Select or un-select card to be held */
  673. poker_player->held[poker_player->selected] =
  674. !poker_player
  675. ->held[poker_player->selected]; //cursed and bad pls replace
  676. } else if(poker_player->GameState == 3) {
  677. /* accept your fate */
  678. if(recognize(poker_player) != 9) {
  679. poker_player->score +=
  680. poker_player->bet * paytable[recognize(poker_player)];
  681. }
  682. poker_player->GameState = 1;
  683. if(poker_player->bet > poker_player->score) {
  684. poker_player->bet = poker_player->score;
  685. }
  686. poker_player->held[0] = 0;
  687. poker_player->held[1] = 0;
  688. poker_player->held[2] = 0;
  689. poker_player->held[3] = 0;
  690. poker_player->held[4] = 0;
  691. if(poker_player->score <= 0) {
  692. /* lost the game */
  693. poker_player->GameState = 4;
  694. }
  695. playcard(poker_player); // shuffle shuffle
  696. } else if(poker_player->GameState == 4) {
  697. /* escape the summary, return to splash */
  698. Shake();
  699. poker_player->selected = 0;
  700. poker_player->GameState = 0;
  701. poker_player->bet = 10;
  702. poker_player->minbet = 10;
  703. poker_player->highscore = 1000;
  704. poker_player->score = 1000;
  705. poker_player->GameState = 0;
  706. }
  707. break;
  708. case InputKeyBack:
  709. /* if game is not over, we should store the game state. */
  710. processing = false;
  711. break;
  712. default:
  713. break;
  714. }
  715. }
  716. }
  717. furi_mutex_release(poker_player->model_mutex);
  718. view_port_update(poker_player->view_port);
  719. }
  720. poker_player_free(poker_player);
  721. return 0;
  722. }