Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
[PLAT-745] Roll for each sacrifice (#213)
Browse files Browse the repository at this point in the history
fix(aaa): pop if success
  • Loading branch information
cowboy-bebug authored Feb 20, 2023
1 parent 082f578 commit c9d62a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pallets/ajuna-awesome-avatars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,9 @@ pub mod pallet {

let rolls = sacrifices.len();
for hash in random_hash.iter().take(rolls) {
if let Some(first_matched_index) = unique_matched_indexes.pop_first() {
let roll = hash % MAX_PERCENTAGE;
if roll <= prob {
let roll = hash % MAX_PERCENTAGE;
if roll <= prob {
if let Some(first_matched_index) = unique_matched_indexes.pop_first() {
let nucleotide = leader.dna[first_matched_index];
let current_tier_index = season
.tiers
Expand Down
47 changes: 15 additions & 32 deletions pallets/ajuna-awesome-avatars/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ mod forging {
.tiers(&[RarityTier::Common, RarityTier::Uncommon, RarityTier::Legendary])
.single_mint_probs(&[100, 0])
.batch_mint_probs(&[100, 0])
.base_prob(30)
.per_period(1)
.periods(6)
.max_tier_forges(1)
Expand Down Expand Up @@ -1285,62 +1286,44 @@ mod forging {

// 1st mutation
assert_dna(&leader_id, &[0x03, 0x04, 0x00, 0x03, 0x03, 0x05, 0x05, 0x01], None);
assert_dna(&leader_id, &[0x03, 0x04, 0x00, 0x03, 0x03, 0x05, 0x05, 0x01], None);

// 2nd mutation
assert_dna(&leader_id, &[0x03, 0x14, 0x00, 0x03, 0x13, 0x05, 0x05, 0x01], None);
assert_dna(&leader_id, &[0x03, 0x14, 0x00, 0x03, 0x13, 0x05, 0x05, 0x01], None);
assert_dna(&leader_id, &[0x13, 0x04, 0x00, 0x03, 0x03, 0x05, 0x05, 0x11], None);

// 3rd mutation
assert_dna(&leader_id, &[0x13, 0x14, 0x10, 0x03, 0x13, 0x05, 0x05, 0x01], None);
assert_dna(&leader_id, &[0x13, 0x14, 0x10, 0x03, 0x13, 0x05, 0x05, 0x01], None);
assert_dna(&leader_id, &[0x13, 0x14, 0x10, 0x03, 0x03, 0x05, 0x05, 0x11], None);

// 4th mutation
assert_dna(&leader_id, &[0x13, 0x14, 0x10, 0x03, 0x13, 0x05, 0x05, 0x11], None);
assert_dna(&leader_id, &[0x13, 0x14, 0x10, 0x03, 0x13, 0x05, 0x05, 0x11], None);
assert_dna(&leader_id, &[0x13, 0x14, 0x10, 0x03, 0x03, 0x05, 0x15, 0x11], None);

// 5th mutation: force 4th, 6th and 7th components' variations to be similar
assert_dna(
&leader_id,
&[0x13, 0x14, 0x10, 0x03, 0x13, 0x05, 0x15, 0x11],
Some(&[0x13, 0x14, 0x10, 0x02, 0x13, 0x04, 0x04, 0x11]),
);
// 5th mutation
assert_dna(&leader_id, &[0x13, 0x14, 0x10, 0x13, 0x13, 0x05, 0x15, 0x11], None);

// 6th mutation: force 4th, 6th, 7th components' variations to be similar
// 6th mutation: force 6th component's variations to be similar
assert_dna(
&leader_id,
&[0x13, 0x14, 0x10, 0x13, 0x13, 0x15, 0x15, 0x11],
Some(&[0x13, 0x14, 0x10, 0x04, 0x13, 0x06, 0x15, 0x11]),
Some(&[0x13, 0x14, 0x10, 0x13, 0x13, 0x06, 0x15, 0x11]),
);

// force highest tier mint and assert for associated checks
assert_dna(
&leader_id,
&[0x43, 0x14, 0x40, 0x43, 0x13, 0x15, 0x15, 0x11],
Some(&[0x14, 0x15, 0x11, 0x14, 0x14, 0x16, 0x16, 0x12]),
);
assert_dna(
&leader_id,
&[0x43, 0x14, 0x40, 0x43, 0x13, 0x15, 0x15, 0x41],
Some(&[0x43, 0x15, 0x40, 0x13, 0x16, 0x16, 0x16, 0x12]),
);
assert_dna(
&leader_id,
&[0x43, 0x44, 0x40, 0x43, 0x13, 0x15, 0x15, 0x41],
Some(&[0x43, 0x15, 0x40, 0x43, 0x14, 0x16, 0x16, 0x41]),
&[0x43, 0x44, 0x40, 0x13, 0x13, 0x15, 0x15, 0x11],
Some(&[0x14, 0x15, 0x11, 0x14, 0x13, 0x15, 0x15, 0x11]),
);
assert_dna(
&leader_id,
&[0x43, 0x44, 0x40, 0x43, 0x43, 0x15, 0x45, 0x41],
Some(&[0x43, 0x44, 0x40, 0x43, 0x14, 0x16, 0x16, 0x41]),
&[0x43, 0x44, 0x40, 0x43, 0x43, 0x45, 0x45, 0x11],
Some(&[0x43, 0x44, 0x40, 0x14, 0x14, 0x16, 0x16, 0x11]),
);
assert_eq!(AAvatars::current_season_status().max_tier_avatars, 0);

// fully upgraded
assert_dna(
&leader_id,
&[0x43, 0x44, 0x40, 0x43, 0x43, 0x45, 0x45, 0x41],
Some(&[0x43, 0x44, 0x40, 0x43, 0x43, 0x16, 0x45, 0x41]),
Some(&[0x43, 0x44, 0x40, 0x43, 0x43, 0x45, 0x45, 0x12]),
);
assert_eq!(AAvatars::current_season_status().max_tier_avatars, 1);
assert!(AAvatars::current_season_status().early_ended);
Expand All @@ -1353,8 +1336,8 @@ mod forging {
);

// check stats for season 1
assert_eq!(AAvatars::season_stats(1, BOB).forged, 15);
assert_eq!(AAvatars::season_stats(1, BOB).minted, 61);
assert_eq!(AAvatars::season_stats(1, BOB).forged, 9);
assert_eq!(AAvatars::season_stats(1, BOB).minted, 37);

// trigger season end and assert for associated checks
run_to_block(season.end + 1);
Expand Down

0 comments on commit c9d62a4

Please sign in to comment.