Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JON-473: Add challenge points #4

Merged
merged 2 commits into from
Nov 1, 2024
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
10 changes: 9 additions & 1 deletion src/constants/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
array![
Expand Down Expand Up @@ -64,6 +68,10 @@ fn challenges_all() -> Array<u32> {
CHALLENGE_QUEEN,
CHALLENGE_KING,
CHALLENGE_ACE,
CHALLENGE_JOKER
CHALLENGE_JOKER,
CHALLENGE_500_POINTS,
CHALLENGE_1000_POINTS,
CHALLENGE_2000_POINTS,
CHALLENGE_5000_POINTS
]
}
30 changes: 24 additions & 6 deletions src/models/status/round/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -130,9 +132,12 @@ impl ChallengeImpl of ChallengeTrait {
}
}


fn _resolve_challenges(
ref challenge: Challenge, result_hand: PokerHand, ref hit_cards: Felt252Dict<bool>, cards: @Array<Card>
ref challenge: Challenge,
result_hand: PokerHand,
ref hit_cards: Felt252Dict<bool>,
cards: @Array<Card>,
hand_score: u32,
) {
match result_hand {
PokerHand::RoyalFlush => _complete(ref challenge, CHALLENGE_ROYAL_FLUSH),
Expand All @@ -149,6 +154,19 @@ fn _resolve_challenges(
PokerHand::None => (),
};

if hand_score >= 5000 {
_complete(ref challenge, CHALLENGE_5000_POINTS);
}
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 {
if idx == cards.len() {
Expand Down
3 changes: 3 additions & 0 deletions src/tests/test_challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Loading