From 4f049b1c4a945c7dbdd4030c0660ee90bf063756 Mon Sep 17 00:00:00 2001 From: dub_zn Date: Thu, 31 Oct 2024 22:17:33 -0300 Subject: [PATCH 1/2] add challenge points --- src/constants/challenge.cairo | 10 ++++++++- src/models/status/round/challenge.cairo | 27 +++++++++++++++++++------ src/tests/test_challenge.cairo | 3 +++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/constants/challenge.cairo b/src/constants/challenge.cairo index 15bb87e..165fb86 100644 --- a/src/constants/challenge.cairo +++ b/src/constants/challenge.cairo @@ -32,6 +32,10 @@ const CHALLENGE_ACE: u32 = 29; const CHALLENGE_JOKER: u32 = 30; +const CHALLENGE_500_POINTS: u32 = 31; +const CHALLENGE_1000_POINTS: u32 = 32; +const CHALLENGE_2000_POINTS: u32 = 33; +const CHALLENGE_5000_POINTS: u32 = 34; fn challenges_all() -> Array { array![ @@ -64,6 +68,10 @@ fn challenges_all() -> Array { CHALLENGE_QUEEN, CHALLENGE_KING, CHALLENGE_ACE, - CHALLENGE_JOKER + CHALLENGE_JOKER, + CHALLENGE_500_POINTS, + CHALLENGE_1000_POINTS, + CHALLENGE_2000_POINTS, + CHALLENGE_5000_POINTS ] } diff --git a/src/models/status/round/challenge.cairo b/src/models/status/round/challenge.cairo index 8ca086b..f49ff15 100644 --- a/src/models/status/round/challenge.cairo +++ b/src/models/status/round/challenge.cairo @@ -7,7 +7,8 @@ use jokers_of_neon::constants::{ CHALLENGE_PAIR, CHALLENGE_HIGH_CARD, CHALLENGE_HEARTS, CHALLENGE_CLUBS, CHALLENGE_DIAMONDS, CHALLENGE_SPADES, CHALLENGE_ONE, CHALLENGE_TWO, CHALLENGE_THREE, CHALLENGE_FOUR, CHALLENGE_FIVE, CHALLENGE_SIX, CHALLENGE_SEVEN, CHALLENGE_EIGHT, CHALLENGE_NINE, CHALLENGE_TEN, CHALLENGE_JACK, CHALLENGE_QUEEN, CHALLENGE_KING, CHALLENGE_ACE, - CHALLENGE_JOKER, challenges_all + CHALLENGE_JOKER, CHALLENGE_500_POINTS, CHALLENGE_1000_POINTS, CHALLENGE_2000_POINTS, CHALLENGE_5000_POINTS, + challenges_all }, specials::SPECIAL_ALL_CARDS_TO_HEARTS_ID, }; @@ -25,7 +26,8 @@ use jokers_of_neon::{ round::current_hand_card::{CurrentHandCard, CurrentHandCardTrait} }, }, - store::{Store, StoreTrait}, utils::{shop::generate_unique_random_values, calculate_hand::calculate_hand} + store::{Store, StoreTrait}, + utils::{game::{play as calculate_hand_score}, shop::generate_unique_random_values, calculate_hand::calculate_hand} }; use starknet::get_caller_address; @@ -51,14 +53,14 @@ impl ChallengeImpl of ChallengeTrait { let mut store = StoreTrait::new(world); let mut current_special_cards_index = _current_special_cards(ref store, @game); - // TODO: Modifiers let (mut cards, _, _) = _get_cards( world, ref store, game.id, @cards_index, @modifiers_index, ref current_special_cards_index ); let (result_hand, mut hit_cards) = calculate_hand(@cards, ref current_special_cards_index); + let hand_score = calculate_hand_score(world, ref game, @cards_index, @modifiers_index); let mut challenge = ChallengeStore::get(world, game_id); - _resolve_challenges(ref challenge, result_hand, ref hit_cards, @cards); + _resolve_challenges(ref challenge, result_hand, ref hit_cards, @cards, hand_score); ChallengeStore::set(@challenge, world); if Self::is_completed(@world, game_id) { @@ -130,9 +132,12 @@ impl ChallengeImpl of ChallengeTrait { } } - fn _resolve_challenges( - ref challenge: Challenge, result_hand: PokerHand, ref hit_cards: Felt252Dict, cards: @Array + ref challenge: Challenge, + result_hand: PokerHand, + ref hit_cards: Felt252Dict, + cards: @Array, + hand_score: u32, ) { match result_hand { PokerHand::RoyalFlush => _complete(ref challenge, CHALLENGE_ROYAL_FLUSH), @@ -149,6 +154,16 @@ fn _resolve_challenges( PokerHand::None => (), }; + if hand_score <= 500 { + _complete(ref challenge, CHALLENGE_500_POINTS); + } else if hand_score <= 1000 { + _complete(ref challenge, CHALLENGE_1000_POINTS); + } else if hand_score <= 2000 { + _complete(ref challenge, CHALLENGE_2000_POINTS); + } else if hand_score <= 5000 { + _complete(ref challenge, CHALLENGE_5000_POINTS); + } else {} + let mut idx = 0; loop { if idx == cards.len() { diff --git a/src/tests/test_challenge.cairo b/src/tests/test_challenge.cairo index 0e4dd32..3fa2a51 100644 --- a/src/tests/test_challenge.cairo +++ b/src/tests/test_challenge.cairo @@ -47,5 +47,8 @@ mod test_challenge { set_contract_address(PLAYER()); systems.game_system.play(game.id, array![0, 1, 2, 3, 4], array![100, 100, 100, 100, 100]); + + let challenge = ChallengeStore::get(world, game.id); + assert(challenge.active_ids.len().is_zero(), 'wrong len'); } } From de1d458530f3a58e3f6b7437a78da3766717cd9a Mon Sep 17 00:00:00 2001 From: dub_zn Date: Thu, 31 Oct 2024 22:21:30 -0300 Subject: [PATCH 2/2] fix ifs --- src/models/status/round/challenge.cairo | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/models/status/round/challenge.cairo b/src/models/status/round/challenge.cairo index f49ff15..5a382d6 100644 --- a/src/models/status/round/challenge.cairo +++ b/src/models/status/round/challenge.cairo @@ -154,15 +154,18 @@ fn _resolve_challenges( PokerHand::None => (), }; - if hand_score <= 500 { - _complete(ref challenge, CHALLENGE_500_POINTS); - } else if hand_score <= 1000 { - _complete(ref challenge, CHALLENGE_1000_POINTS); - } else if hand_score <= 2000 { - _complete(ref challenge, CHALLENGE_2000_POINTS); - } else if hand_score <= 5000 { + if hand_score >= 5000 { _complete(ref challenge, CHALLENGE_5000_POINTS); - } else {} + } + if hand_score >= 2000 { + _complete(ref challenge, CHALLENGE_2000_POINTS); + } + if hand_score >= 1000 { + _complete(ref challenge, CHALLENGE_1000_POINTS); + } + if hand_score >= 500 { + _complete(ref challenge, CHALLENGE_500_POINTS); + } let mut idx = 0; loop {