Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps_source_code/videopoker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps_source_code/videopoker/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
17 changes: 14 additions & 3 deletions apps_source_code/videopoker/poker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading