diff --git a/apps_source_code/videopoker/CHANGELOG.md b/apps_source_code/videopoker/CHANGELOG.md index 75afced6..5095307f 100644 --- a/apps_source_code/videopoker/CHANGELOG.md +++ b/apps_source_code/videopoker/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.5 + +- Fix a winning hand at a very large bet overflowing the bank, which could pay out the wrong amount or end the game on the "You have run out of money!" screen +- Cap the bank at $1,000,000,000 so the bet controls cannot overflow either + ## 1.4 - Add Up/Down press to double or halve the bet (replaces Up = all-in; all-in is still reachable by doubling past half the bank or wrapping Left at the minimum) diff --git a/apps_source_code/videopoker/application.fam b/apps_source_code/videopoker/application.fam index 4908c6b9..fde0ac80 100644 --- a/apps_source_code/videopoker/application.fam +++ b/apps_source_code/videopoker/application.fam @@ -11,6 +11,6 @@ App( fap_category="Games", fap_author="@PixlEmly", fap_weburl="https://github.com/PixlEmly", - fap_version="1.4", + fap_version="1.5", fap_description="Video poker is a casino game based on five-card draw poker", ) diff --git a/apps_source_code/videopoker/poker.c b/apps_source_code/videopoker/poker.c index 7e1e8f7e..ef722808 100644 --- a/apps_source_code/videopoker/poker.c +++ b/apps_source_code/videopoker/poker.c @@ -23,6 +23,10 @@ Sometimes duplicate cards will show up. there is a function to test this. I shou #define TAG "Video Poker" +/* Bank ceiling, at roughly half of INT_MAX so the bet arithmetic (+/-10 steps +and doubling) stays inside int - a larger multiplier would need a lower cap */ +#define MAX_BANK 1000000000 + static void Shake(void) { NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION); notification_message(notification, &sequence_single_vibro); @@ -785,9 +789,16 @@ int32_t video_poker_app(void* p) { ->held[poker_player->selected]; //cursed and bad pls replace } else if(poker_player->GameState == 3) { /* accept your fate */ - if(recognize(poker_player) != 9) { - poker_player->score += - poker_player->bet * paytable[recognize(poker_player)]; + int hand_rank = recognize(poker_player); + if(hand_rank != 9) { + /* Both the payout and the new bank total overflow int at very + large bets - as reported that corrupted the score and dropped a + winning hand on the game-over screen. Work the total out in 64 + bits and saturate: a bank this large is already meaningless, and + widening score would ripple through every %d */ + int64_t total = (int64_t)poker_player->score + + (int64_t)poker_player->bet * paytable[hand_rank]; + poker_player->score = total > MAX_BANK ? MAX_BANK : (int)total; } poker_player->GameState = 1; clamp_bet(poker_player);