diff --git a/src/models/actions.cairo b/src/models/actions.cairo index caf628c..fadc99c 100644 --- a/src/models/actions.cairo +++ b/src/models/actions.cairo @@ -7,7 +7,6 @@ //////////////////////////////// //////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// - use starknet::ContractAddress; use zktt::models::structs::{StructBlockchain, StructAssetGroup}; use zktt::models::enums::{EnumGasFeeType, EnumPlayerTarget}; @@ -177,4 +176,4 @@ struct ActionSoftFork { m_set: StructAssetGroup, m_value: u8, m_index: u8 -} \ No newline at end of file +} diff --git a/src/models/enums.cairo b/src/models/enums.cairo index 951c6a5..c92fd7d 100644 --- a/src/models/enums.cairo +++ b/src/models/enums.cairo @@ -10,9 +10,9 @@ use starknet::ContractAddress; use zktt::models::structs::{StructAsset, StructBlockchain, StructHybridBlockchain}; use zktt::models::actions::{ - ActionChainReorg, ActionClaimYield, ActionFrontrun, ActionPriorityFee, - ActionReplayAttack, ActionGasFee, ActionFiftyOnePercentAttack, ActionSandwichAttack, ActionHardFork, - ActionMEVBoost, ActionSoftFork + ActionChainReorg, ActionClaimYield, ActionFrontrun, ActionPriorityFee, ActionReplayAttack, + ActionGasFee, ActionFiftyOnePercentAttack, ActionSandwichAttack, ActionHardFork, ActionMEVBoost, + ActionSoftFork }; use zktt::models::traits::{ StructAssetEq, StructAssetGroupEq, StructBlockchainEq, StructHybridBlockchainEq, @@ -108,7 +108,7 @@ pub enum EnumMoveError { #[derive(Drop, Serde, Copy, PartialEq, Debug)] pub enum EnumHardForkErrors { - InvalidCard, // When card played against is not an onchain event targeting owner of the card. - TooLate // When card is played too late (after 10 secs). + InvalidCard, // When card played against is not an onchain event targeting owner of the card. + TooLate // When card is played too late (after 10 secs). } diff --git a/src/models/structs.cairo b/src/models/structs.cairo index a6fa960..ac369fd 100644 --- a/src/models/structs.cairo +++ b/src/models/structs.cairo @@ -8,9 +8,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// use starknet::ContractAddress; -use zktt::models::enums::{ - EnumCard, EnumColor, EnumGasFeeType, EnumMoveError, EnumPlayerTarget -}; +use zktt::models::enums::{EnumCard, EnumColor, EnumGasFeeType, EnumMoveError, EnumPlayerTarget}; ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// diff --git a/src/models/traits.cairo b/src/models/traits.cairo index 908e2bc..37565a9 100644 --- a/src/models/traits.cairo +++ b/src/models/traits.cairo @@ -14,9 +14,9 @@ use zktt::models::structs::{ StructAsset, StructBlockchain, StructAssetGroup, StructHybridBlockchain }; use zktt::models::actions::{ - ActionChainReorg, ActionClaimYield, ActionFrontrun, ActionPriorityFee, - ActionReplayAttack, ActionGasFee, ActionFiftyOnePercentAttack, ActionSandwichAttack, - ActionHardFork, ActionMEVBoost, ActionSoftFork + ActionChainReorg, ActionClaimYield, ActionFrontrun, ActionPriorityFee, ActionReplayAttack, + ActionGasFee, ActionFiftyOnePercentAttack, ActionSandwichAttack, ActionHardFork, ActionMEVBoost, + ActionSoftFork }; use zktt::models::enums::{ EnumCard, EnumColor, EnumGasFeeType, EnumMoveError, EnumPlayerTarget, EnumHardForkErrors @@ -98,11 +98,15 @@ impl EnumCardEq of PartialEq { (EnumCard::Blockchain(data1), EnumCard::Blockchain(data2)) => data1 == data2, (EnumCard::ChainReorg(data1), EnumCard::ChainReorg(data2)) => data1 == data2, (EnumCard::ClaimYield(data1), EnumCard::ClaimYield(data2)) => data1 == data2, - (EnumCard::FiftyOnePercentAttack(data1), EnumCard::FiftyOnePercentAttack(data2)) => data1 == data2, + ( + EnumCard::FiftyOnePercentAttack(data1), EnumCard::FiftyOnePercentAttack(data2) + ) => data1 == data2, (EnumCard::FrontRun(data1), EnumCard::FrontRun(data2)) => data1 == data2, (EnumCard::GasFee(data1), EnumCard::GasFee(data2)) => data1 == data2, (EnumCard::HardFork(data1), EnumCard::HardFork(data2)) => data1 == data2, - (EnumCard::HybridBlockchain(data1), EnumCard::HybridBlockchain(data2)) => data1 == data2, + ( + EnumCard::HybridBlockchain(data1), EnumCard::HybridBlockchain(data2) + ) => data1 == data2, (EnumCard::MEVBoost(data1), EnumCard::MEVBoost(data2)) => data1 == data2, (EnumCard::PriorityFee(data1), EnumCard::PriorityFee(data2)) => data1 == data2, (EnumCard::ReplayAttack(data1), EnumCard::ReplayAttack(data2)) => data1 == data2, @@ -199,7 +203,7 @@ impl ActionFiftyOnePercentAttackDisplay of Display "Steal Asset Group: Value {0}, Index: {1}", *self.m_value, *self.m_index ); f.buffer.append(@str); - + let mut index = 0; while index < self.m_set.len() { if let Option::Some(bc) = self.m_set.get(index) { @@ -284,7 +288,9 @@ impl ActionReplayAttackDisplay of Display { impl ActionSandwichAttackDisplay of Display { fn fmt(self: @ActionSandwichAttack, ref f: Formatter) -> Result<(), Error> { let str: ByteArray = format!( - "Force any player to give you 5 ETH: Value: {0}, Index: {1}", *self.m_value, *self.m_index + "Force any player to give you 5 ETH: Value: {0}, Index: {1}", + *self.m_value, + *self.m_index ); f.buffer.append(@str); return Result::Ok(()); @@ -555,9 +561,7 @@ impl StructBlockchainDisplay of Display { impl StructHybridBlockchainDisplay of Display { fn fmt(self: @StructHybridBlockchain, ref f: Formatter) -> Result<(), Error> { let str: ByteArray = format!( - "Hybrid Blockchain: {0}, Facing Up: {1}", - self.m_name, - self.m_bc_facing_up_index + "Hybrid Blockchain: {0}, Facing Up: {1}", self.m_name, self.m_bc_facing_up_index ); f.buffer.append(@str); return Result::Ok(()); @@ -615,9 +619,7 @@ impl AssetGroupImpl of IAssetGroup { #[generate_trait] impl BlockchainImpl of IBlockchain { - fn new( - name: ByteArray, bc_type: EnumColor, fee: u8, value: u8 - ) -> StructBlockchain nopanic { + fn new(name: ByteArray, bc_type: EnumColor, fee: u8, value: u8) -> StructBlockchain nopanic { return StructBlockchain { m_name: name, m_bc_type: bc_type, m_fee: fee, m_value: value }; } } @@ -671,7 +673,6 @@ impl DealerImpl of IDealer { if let Option::Some(_) = self.m_cards.get(card_index.into()) { shuffled_cards.append(self.m_cards[card_index.into()].clone()); - } }; self.m_cards = shuffled_cards; @@ -844,13 +845,10 @@ impl DeckImpl of IDeck { } fn check_complete_set( - self: @ComponentDeck, - asset_group_array: Array, - bc_type: @EnumColor + self: @ComponentDeck, asset_group_array: Array, bc_type: @EnumColor ) -> bool { let required_count = match bc_type { - EnumColor::Blue(_) | EnumColor::DarkBlue(_) | - EnumColor::Gold(_) => 2, + EnumColor::Blue(_) | EnumColor::DarkBlue(_) | EnumColor::Gold(_) => 2, EnumColor::LightBlue(_) => 4, _ => 3 }; @@ -964,7 +962,9 @@ impl EnumCardImpl of IEnumCard { EnumCard::FrontRun(data) => { return *data.m_value; }, EnumCard::GasFee(data) => { return *data.m_value; }, EnumCard::HardFork(data) => { return *data.m_value; }, - EnumCard::HybridBlockchain(data) => { return *data.m_bcs[(*data.m_bc_facing_up_index).into()].m_value; }, + EnumCard::HybridBlockchain(data) => { + return *data.m_bcs[(*data.m_bc_facing_up_index).into()].m_value; + }, EnumCard::MEVBoost(data) => { return *data.m_value; }, EnumCard::PriorityFee(data) => { return *data.m_value; }, EnumCard::ReplayAttack(data) => { return *data.m_value; }, @@ -975,7 +975,7 @@ impl EnumCardImpl of IEnumCard { fn remove_one_index(ref self: EnumCard) -> () { assert!(self.get_index() > 0, "No more indices left for {0}", self); - + let new_card: EnumCard = match self.clone() { EnumCard::Asset(mut data) => { data.m_index -= 1; @@ -1048,20 +1048,20 @@ impl EnumCardImpl of IEnumCard { #[generate_trait] impl FiftyOnePercentAttackImpl of IFiftyOnePercentAttack { - fn new(player_targeted: ContractAddress, set: Array, value: u8, copies_left: u8 + fn new( + player_targeted: ContractAddress, set: Array, value: u8, copies_left: u8 ) -> ActionFiftyOnePercentAttack nopanic { return ActionFiftyOnePercentAttack { - m_player_targeted: player_targeted, - m_set: set, - m_value: value, - m_index: copies_left + m_player_targeted: player_targeted, m_set: set, m_value: value, m_index: copies_left }; } } #[generate_trait] impl FrontRunImpl of IFrontRun { - fn new(player_targeted: ContractAddress, blockchain_name: ByteArray, value: u8, copies_left: u8) -> ActionFrontrun nopanic { + fn new( + player_targeted: ContractAddress, blockchain_name: ByteArray, value: u8, copies_left: u8 + ) -> ActionFrontrun nopanic { return ActionFrontrun { m_player_targeted: player_targeted, m_blockchain_name: blockchain_name, @@ -1204,12 +1204,11 @@ impl HandImpl of IHand { #[generate_trait] impl HardForkImpl of IHardFork { - fn new(owner: ContractAddress, timestamp_used: u64, value: u8, copies: u8) -> ActionHardFork nopanic { + fn new( + owner: ContractAddress, timestamp_used: u64, value: u8, copies: u8 + ) -> ActionHardFork nopanic { return ActionHardFork { - m_owner: owner, - m_timestamp_used: timestamp_used, - m_value: value, - m_index: copies + m_owner: owner, m_timestamp_used: timestamp_used, m_value: value, m_index: copies }; } @@ -1237,10 +1236,8 @@ impl HybridBlockchainImpl of IHybridBlockchain { fn new( name: ByteArray, bcs: Array, bc_facing_up_index: u8 ) -> StructHybridBlockchain nopanic { - return StructHybridBlockchain { - m_name: name, - m_bcs: bcs, - m_bc_facing_up_index: bc_facing_up_index + return StructHybridBlockchain { + m_name: name, m_bcs: bcs, m_bc_facing_up_index: bc_facing_up_index }; } } @@ -1248,11 +1245,7 @@ impl HybridBlockchainImpl of IHybridBlockchain { #[generate_trait] impl MEVBoostImpl of IMEVBoost { fn new(set: StructAssetGroup, value: u8, copies_left: u8) -> ActionMEVBoost nopanic { - return ActionMEVBoost { - m_set: set, - m_value: value, - m_index: copies_left - }; + return ActionMEVBoost { m_set: set, m_value: value, m_index: copies_left }; } } @@ -1285,21 +1278,17 @@ impl PriorityFeeImpl of IPriorityFee { #[generate_trait] impl ReplayAttackImpl of IReplayAttack { fn new(owner: ContractAddress, value: u8, copies: u8) -> ActionReplayAttack nopanic { - return ActionReplayAttack { - m_owner: owner, - m_value: value, - m_index: copies - }; + return ActionReplayAttack { m_owner: owner, m_value: value, m_index: copies }; } } #[generate_trait] impl SandwichAttackImpl of ISandwichAttack { - fn new(player_targeted: ContractAddress, value: u8, copies_left: u8) -> ActionSandwichAttack nopanic { + fn new( + player_targeted: ContractAddress, value: u8, copies_left: u8 + ) -> ActionSandwichAttack nopanic { return ActionSandwichAttack { - m_player_targeted: player_targeted, - m_value: value, - m_index: copies_left + m_player_targeted: player_targeted, m_value: value, m_index: copies_left }; } } @@ -1307,11 +1296,7 @@ impl SandwichAttackImpl of ISandwichAttack { #[generate_trait] impl SoftForkImpl of ISoftFork { fn new(set: StructAssetGroup, value: u8, copies_left: u8) -> ActionSoftFork nopanic { - return ActionSoftFork { - m_set: set, - m_value: value, - m_index: copies_left - }; + return ActionSoftFork { m_set: set, m_value: value, m_index: copies_left }; } } @@ -1336,10 +1321,7 @@ impl ChainReorgDefault of Default { impl ClaimYieldDefault of Default { fn default() -> ActionClaimYield nopanic { - return ActionClaimYield { - m_value: 2, - m_index: 3 - }; + return ActionClaimYield { m_value: 2, m_index: 3 }; } } @@ -1379,10 +1361,7 @@ impl HardForkDefault of Default { impl MEVBoostDefault of Default { fn default() -> ActionMEVBoost nopanic { return ActionMEVBoost { - m_set: StructAssetGroup { - m_set: array![], - m_total_fee_value: 0 - }, + m_set: StructAssetGroup { m_set: array![], m_total_fee_value: 0 }, m_value: 4, m_index: 3 }; @@ -1391,19 +1370,14 @@ impl MEVBoostDefault of Default { impl PriorityFeeDefault of Default { fn default() -> ActionPriorityFee nopanic { - return ActionPriorityFee { - m_value: 1, - m_index: 10 - }; + return ActionPriorityFee { m_value: 1, m_index: 10 }; } } impl ReplayAttackDefault of Default { fn default() -> ActionReplayAttack nopanic { return ActionReplayAttack { - m_owner: starknet::contract_address_const::<0x0>(), - m_value: 1, - m_index: 2 + m_owner: starknet::contract_address_const::<0x0>(), m_value: 1, m_index: 2 }; } } @@ -1411,9 +1385,7 @@ impl ReplayAttackDefault of Default { impl SandwichAttackDefault of Default { fn default() -> ActionSandwichAttack nopanic { return ActionSandwichAttack { - m_player_targeted: starknet::contract_address_const::<0x0>(), - m_value: 3, - m_index: 3 + m_player_targeted: starknet::contract_address_const::<0x0>(), m_value: 3, m_index: 3 }; } } @@ -1421,10 +1393,7 @@ impl SandwichAttackDefault of Default { impl SoftForkDefault of Default { fn default() -> ActionSoftFork nopanic { return ActionSoftFork { - m_set: StructAssetGroup { - m_set: array![], - m_total_fee_value: 0 - }, + m_set: StructAssetGroup { m_set: array![], m_total_fee_value: 0 }, m_value: 3, m_index: 3 }; @@ -1433,10 +1402,7 @@ impl SoftForkDefault of Default { impl AssetGroupDefault of Default { fn default() -> StructAssetGroup nopanic { - return StructAssetGroup { - m_set: array![], - m_total_fee_value: 0 - }; + return StructAssetGroup { m_set: array![], m_total_fee_value: 0 }; } } diff --git a/src/systems/actions.cairo b/src/systems/actions.cairo index 4fdaf5a..f02ee7e 100644 --- a/src/systems/actions.cairo +++ b/src/systems/actions.cairo @@ -8,9 +8,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// use starknet::ContractAddress; -use zktt::models::enums::{ - EnumCard, EnumGameState, EnumGasFeeType, EnumPlayerTarget, EnumColor -}; +use zktt::models::enums::{EnumCard, EnumGameState, EnumGasFeeType, EnumPlayerTarget, EnumColor}; #[starknet::interface] @@ -19,7 +17,10 @@ trait IActionSystem { fn play(ref self: T, card: EnumCard, table: ContractAddress) -> (); fn move(ref self: T, card: EnumCard, table: ContractAddress) -> (); fn pay_fee( - ref self: T, pay: Array, recipient: ContractAddress, payee: ContractAddress, + ref self: T, + pay: Array, + recipient: ContractAddress, + payee: ContractAddress, table: ContractAddress ) -> (); } @@ -32,8 +33,8 @@ mod action_system { ComponentPlayer, ComponentDealer, ComponentDiscardPile }; use zktt::models::traits::{ - IEnumCard, IPlayer, IDeck, IDealer, IHand, IGasFee, IAssetGroup, IGame, IAsset, - IBlockchain, IDeposit + IEnumCard, IPlayer, IDeck, IDealer, IHand, IGasFee, IAssetGroup, IGame, IAsset, IBlockchain, + IDeposit }; use zktt::models::enums::{EnumGasFeeType, EnumPlayerTarget, EnumColor}; use dojo::world::IWorldDispatcher; @@ -268,7 +269,12 @@ mod action_system { /// Output: /// None. /// Can Panic?: yes - fn _use_card(ref self: ContractState, caller: @ContractAddress, card: EnumCard, table: ContractAddress) -> () { + fn _use_card( + ref self: ContractState, + caller: @ContractAddress, + card: EnumCard, + table: ContractAddress + ) -> () { let mut world = self.world_default(); let mut hand: ComponentHand = world.read_model(*caller); let mut deck: ComponentDeck = world.read_model(*caller); @@ -314,17 +320,23 @@ mod action_system { EnumCard::ClaimYield(_claim_yield_struct) => { let mut game: ComponentGame = world.read_model(table); game.m_state = EnumGameState::WaitingForRent; - for player in game.m_players.span() { - let mut player_component: ComponentPlayer = world.read_model(*player); - player_component.m_in_debt = Option::Some(2); - world.write_model(@player_component); - }; + for player in game + .m_players + .span() { + let mut player_component: ComponentPlayer = world.read_model(*player); + player_component.m_in_debt = Option::Some(2); + world.write_model(@player_component); + }; world.write_model(@game); }, EnumCard::FiftyOnePercentAttack(asset_group_struct) => { - assert!(*asset_group_struct.m_player_targeted != starknet::contract_address_const::<0x0>(), - "No player targeted"); - let mut opponent_deck: ComponentDeck = world.read_model(*asset_group_struct.m_player_targeted); + assert!( + *asset_group_struct + .m_player_targeted != starknet::contract_address_const::<0x0>(), + "No player targeted" + ); + let mut opponent_deck: ComponentDeck = world + .read_model(*asset_group_struct.m_player_targeted); // Verify opponent has sets to steal assert!(opponent_deck.m_sets > 0, "Opponent has no sets"); @@ -358,12 +370,16 @@ mod action_system { world.write_model(@opponent_deck); }, EnumCard::FrontRun(frontrun_struct) => { - assert!(*frontrun_struct.m_player_targeted != starknet::contract_address_const::<0x0>(), - "No player targeted"); + assert!( + *frontrun_struct + .m_player_targeted != starknet::contract_address_const::<0x0>(), + "No player targeted" + ); let bc_owner = self._get_owner(frontrun_struct.m_blockchain_name, table); assert!(bc_owner.is_some(), "Blockchain in Frontrun card has no owner"); - let mut opponent_deck: ComponentDeck = world.read_model(*frontrun_struct.m_player_targeted); + let mut opponent_deck: ComponentDeck = world + .read_model(*frontrun_struct.m_player_targeted); if let Option::Some(card_index) = opponent_deck .contains(frontrun_struct.m_blockchain_name) { deck.add(opponent_deck.m_cards.at(card_index).clone()); @@ -437,7 +453,9 @@ mod action_system { }, EnumCard::ReplayAttack(replay_attack_struct) => { // Retrieve last card played by player from the discard pile. - if let Option::Some(last_card) = discard_pile.m_cards.get(discard_pile.m_cards.len() - 1) { + if let Option::Some(last_card) = discard_pile + .m_cards + .get(discard_pile.m_cards.len() - 1) { let unboxed_card = last_card.unbox(); match unboxed_card { EnumCard::GasFee(gas_fee_struct) => { @@ -457,18 +475,17 @@ mod action_system { }; }, EnumPlayerTarget::One(player) => { - let mut player_component: ComponentPlayer = world.read_model(*player); + let mut player_component: ComponentPlayer = world + .read_model(*player); player_component.m_in_debt = Option::Some(fee); world.write_model(@player_component); }, _ => panic!("Invalid Gas Fee move: No players targeted") }; - } else { - // Card played too late, potentially punish player... + } else { // Card played too late, potentially punish player... } }, - _ => { - // Invalid card played with it, potentially punish player... + _ => { // Invalid card played with it, potentially punish player... } }; } @@ -494,7 +511,9 @@ mod action_system { return (); } - fn _get_owner(ref self: ContractState, card_name: @ByteArray, table: ContractAddress) -> Option { + fn _get_owner( + ref self: ContractState, card_name: @ByteArray, table: ContractAddress + ) -> Option { let mut world = self.world_default(); let game: ComponentGame = world.read_model(table); assert!(game.m_state == EnumGameState::Started, "Game has not started yet"); diff --git a/src/systems/game.cairo b/src/systems/game.cairo index d859812..84b82c3 100644 --- a/src/systems/game.cairo +++ b/src/systems/game.cairo @@ -23,16 +23,14 @@ mod game_system { ComponentPlayer, ComponentDealer }; use zktt::models::traits::{ - IEnumCard, IPlayer, ICard, IDeck, IDealer, IHand, IGasFee, IAssetGroup, IGame, - IAsset, IBlockchain, IDeposit, IClaimYield, IFiftyOnePercentAttack, IChainReorg, IFrontRun, - IHybridBlockchain,ISandwichAttack, IPriorityFee, IReplayAttack, IHardFork, ISoftFork, IMEVBoost, - ClaimYieldDefault, ChainReorgDefault, FrontrunDefault, MEVBoostDefault, PriorityFeeDefault, - FiftyOnePercentAttackDefault, HardForkDefault, SoftForkDefault, ReplayAttackDefault, - SandwichAttackDefault, EnumCardDisplay - }; - use zktt::models::enums::{ - EnumGasFeeType, EnumPlayerTarget, EnumGameState, EnumColor, EnumCard + IEnumCard, IPlayer, ICard, IDeck, IDealer, IHand, IGasFee, IAssetGroup, IGame, IAsset, + IBlockchain, IDeposit, IClaimYield, IFiftyOnePercentAttack, IChainReorg, IFrontRun, + IHybridBlockchain, ISandwichAttack, IPriorityFee, IReplayAttack, IHardFork, ISoftFork, + IMEVBoost, ClaimYieldDefault, ChainReorgDefault, FrontrunDefault, MEVBoostDefault, + PriorityFeeDefault, FiftyOnePercentAttackDefault, HardForkDefault, SoftForkDefault, + ReplayAttackDefault, SandwichAttackDefault, EnumCardDisplay }; + use zktt::models::enums::{EnumGasFeeType, EnumPlayerTarget, EnumGameState, EnumColor, EnumCard}; use zktt::systems::player::player_system; use dojo::world::IWorldDispatcher; use core::poseidon::poseidon_hash_span; @@ -61,7 +59,10 @@ mod game_system { let mut game: ComponentGame = world.read_model(table); assert!(game.m_state != EnumGameState::Started, "Game has already started"); assert!(game.m_players.len() >= 2, "Missing at least a player before starting"); - assert!(player_system::InternalImpl::_is_everyone_ready(@world, table), "Everyone needs to be ready"); + assert!( + player_system::InternalImpl::_is_everyone_ready(@world, table), + "Everyone needs to be ready" + ); let cards_in_order = InternalImpl::_create_cards(); let mut flattened_cards = InternalImpl::_flatten(ref world, cards_in_order); @@ -119,7 +120,8 @@ mod game_system { /// None. /// Can Panic?: yes fn end(ref self: ContractState, table: ContractAddress) -> () { - // assert!(get_caller_address() == starknet::contract_address_const::<0x0>(), "Unauthorized"); + // assert!(get_caller_address() == starknet::contract_address_const::<0x0>(), + // "Unauthorized"); let mut world = InternalImpl::world_default(@self); let mut game: ComponentGame = world.read_model(table); @@ -129,9 +131,10 @@ mod game_system { game.m_state = EnumGameState::Ended; // Double check that we have reaquired all assets from all players. - for addr in game.m_players { - player_system::InternalImpl::_relinquish_assets(addr, table, ref world); - }; + for addr in game + .m_players { + player_system::InternalImpl::_relinquish_assets(addr, table, ref world); + }; } } @@ -187,7 +190,9 @@ mod game_system { /// None. /// Can Panic?: yes fn _distribute_cards( - ref world: dojo::world::WorldStorage, ref players: Array, ref cards: Array + ref world: dojo::world::WorldStorage, + ref players: Array, + ref cards: Array ) -> () { if players.is_empty() { panic!("There are no players to distribute cards to!"); @@ -261,26 +266,82 @@ mod game_system { EnumCard::Blockchain(IBlockchain::new("ZKSync", EnumColor::Grey, 1, 2)), // Hybrid Blockchains. // Pink + Blue. - EnumCard::HybridBlockchain(IHybridBlockchain::new("Moonbeam & Tezos", array![IBlockchain::new("Osmosis", EnumColor::Pink, 1, 1), - IBlockchain::new("Ton", EnumColor::Blue, 1, 1)], 0)), + EnumCard::HybridBlockchain( + IHybridBlockchain::new( + "Moonbeam & Tezos", + array![ + IBlockchain::new("Osmosis", EnumColor::Pink, 1, 1), + IBlockchain::new("Ton", EnumColor::Blue, 1, 1) + ], + 0 + ) + ), // Pink + Light Blue. - EnumCard::HybridBlockchain(IHybridBlockchain::new("Unichain + Zora", array![IBlockchain::new("Polkadot", EnumColor::Pink, 1, 1), - IBlockchain::new("Metis", EnumColor::LightBlue, 1, 2)], 0)), + EnumCard::HybridBlockchain( + IHybridBlockchain::new( + "Unichain + Zora", + array![ + IBlockchain::new("Polkadot", EnumColor::Pink, 1, 1), + IBlockchain::new("Metis", EnumColor::LightBlue, 1, 2) + ], + 0 + ) + ), // LightBlue + Gold. - EnumCard::HybridBlockchain(IHybridBlockchain::new("Sui + BSC", array![IBlockchain::new("Fantom", EnumColor::LightBlue, 1, 2), - IBlockchain::new("Dogecoin", EnumColor::Gold, 1, 2)], 0)), + EnumCard::HybridBlockchain( + IHybridBlockchain::new( + "Sui + BSC", + array![ + IBlockchain::new("Fantom", EnumColor::LightBlue, 1, 2), + IBlockchain::new("Dogecoin", EnumColor::Gold, 1, 2) + ], + 0 + ) + ), // LightBlue + Red. - EnumCard::HybridBlockchain(IHybridBlockchain::new("Cardano + Tron", array![IBlockchain::new("Base", EnumColor::LightBlue, 1, 2), - IBlockchain::new("Avalanche", EnumColor::Red, 2, 4)], 0)), + EnumCard::HybridBlockchain( + IHybridBlockchain::new( + "Cardano + Tron", + array![ + IBlockchain::new("Base", EnumColor::LightBlue, 1, 2), + IBlockchain::new("Avalanche", EnumColor::Red, 2, 4) + ], + 0 + ) + ), // Red + DarkBlue. - EnumCard::HybridBlockchain(IHybridBlockchain::new("Sei + Hyperliquid", array![IBlockchain::new("Optimism", EnumColor::Red, 2, 4), - IBlockchain::new("Starknet", EnumColor::DarkBlue, 3, 4)], 0)), + EnumCard::HybridBlockchain( + IHybridBlockchain::new( + "Sei + Hyperliquid", + array![ + IBlockchain::new("Optimism", EnumColor::Red, 2, 4), + IBlockchain::new("Starknet", EnumColor::DarkBlue, 3, 4) + ], + 0 + ) + ), // Yellow + Purple. - EnumCard::HybridBlockchain(IHybridBlockchain::new("Terra + Pulse", array![IBlockchain::new("Celo", EnumColor::Yellow, 2, 3), - IBlockchain::new("Polygon", EnumColor::Purple, 2, 3)], 0)), + EnumCard::HybridBlockchain( + IHybridBlockchain::new( + "Terra + Pulse", + array![ + IBlockchain::new("Celo", EnumColor::Yellow, 2, 3), + IBlockchain::new("Polygon", EnumColor::Purple, 2, 3) + ], + 0 + ) + ), // Grey + Green. - EnumCard::HybridBlockchain(IHybridBlockchain::new("Algorand + Flow", array![IBlockchain::new("ZKSync", EnumColor::Grey, 1, 2), - IBlockchain::new("Canto", EnumColor::Green, 1, 1)], 0)), + EnumCard::HybridBlockchain( + IHybridBlockchain::new( + "Algorand + Flow", + array![ + IBlockchain::new("ZKSync", EnumColor::Grey, 1, 2), + IBlockchain::new("Canto", EnumColor::Green, 1, 1) + ], + 0 + ) + ), // Actions. EnumCard::ChainReorg(Default::default()), EnumCard::ClaimYield(Default::default()), @@ -332,10 +393,7 @@ mod game_system { ) ), EnumCard::GasFee( - IGasFee::new( - EnumPlayerTarget::None, - EnumGasFeeType::Any(()), - array![], 3, 3) + IGasFee::new(EnumPlayerTarget::None, EnumGasFeeType::Any(()), array![], 3, 3) ), EnumCard::HardFork(Default::default()), EnumCard::MEVBoost(Default::default()), @@ -383,8 +441,9 @@ mod game_system { /// Output: /// None. /// Can Panic?: yes - fn _assign_winner(ref world: dojo::world::WorldStorage) -> () { - // TODO: Determine the winner upon interrupt and reward for the winner + fn _assign_winner( + ref world: dojo::world::WorldStorage + ) -> () { // TODO: Determine the winner upon interrupt and reward for the winner } } } diff --git a/src/systems/player.cairo b/src/systems/player.cairo index 8101dc6..5dee773 100644 --- a/src/systems/player.cairo +++ b/src/systems/player.cairo @@ -23,8 +23,8 @@ mod player_system { ComponentDealer, ComponentDiscardPile }; use zktt::models::traits::{ - IEnumCard, IPlayer, IDeck, IDealer, IHand, IGasFee, IAssetGroup, IGame, IAsset, - IBlockchain, IDeposit + IEnumCard, IPlayer, IDeck, IDealer, IHand, IGasFee, IAssetGroup, IGame, IAsset, IBlockchain, + IDeposit }; use zktt::models::enums::{EnumGasFeeType, EnumPlayerTarget, EnumGameState}; use dojo::world::IWorldDispatcher; @@ -156,17 +156,18 @@ mod player_system { let game: ComponentGame = world.read_model(table); let mut everyone_ready: bool = true; - for addr in game.m_players { - let player: ComponentPlayer = world.read_model(addr); - if !player.m_is_ready { - everyone_ready = false; - } - }; + for addr in game + .m_players { + let player: ComponentPlayer = world.read_model(addr); + if !player.m_is_ready { + everyone_ready = false; + } + }; return everyone_ready; } - /// Take all cards owned by player and put them in the discard pile, effectively re-possessing - /// all player cards back. Normally after player leaves or game ends. + /// Take all cards owned by player and put them in the discard pile, effectively + /// re-possessing all player cards back. Normally after player leaves or game ends. /// /// Inputs: /// *player_address*: The contract address of the player in question. @@ -175,7 +176,11 @@ mod player_system { /// Output: /// None. /// Can Panic?: yes - fn _relinquish_assets(player_address: ContractAddress, table: ContractAddress, ref world: dojo::world::WorldStorage) -> () { + fn _relinquish_assets( + player_address: ContractAddress, + table: ContractAddress, + ref world: dojo::world::WorldStorage + ) -> () { let mut hand: ComponentHand = world.read_model(player_address); let mut deck: ComponentDeck = world.read_model(player_address); let mut deposit: ComponentDeposit = world.read_model(player_address); diff --git a/src/tests/integration/test_actions.cairo b/src/tests/integration/test_actions.cairo index 1e0f864..534f2e9 100644 --- a/src/tests/integration/test_actions.cairo +++ b/src/tests/integration/test_actions.cairo @@ -29,8 +29,10 @@ use crate::systems::player::{IPlayerSystemDispatcher, IPlayerSystemDispatcherTra use crate::models::components::{ ComponentGame, ComponentHand, ComponentDeposit, ComponentPlayer, ComponentDeck, ComponentDealer }; -use crate::models::traits::{ComponentPlayerDisplay, ComponentHandDisplay, IDealer, IAsset, IClaimYield, IHand, - PriorityFeeDefault, EnumCardDisplay, EnumCardEq}; +use crate::models::traits::{ + ComponentPlayerDisplay, ComponentHandDisplay, IDealer, IAsset, IClaimYield, IHand, + PriorityFeeDefault, EnumCardDisplay, EnumCardEq +}; use crate::tests::utils::{deploy_world, namespace_def}; use crate::tests::integration::test_game::deploy_game; use crate::tests::integration::test_player::deploy_player; @@ -163,13 +165,10 @@ fn test_play() { let hand: ComponentHand = world.read_model(first_caller); let card: EnumCard = hand.m_cards.at(0).clone(); - println!("Hand size: {}", hand.m_cards.len()); - println!("Hand: {}", hand); assert!(hand.m_cards.len() == 7, "Player should have 7 cards after drawing"); // Play the card action_system.play(card.clone(), addr); - println!("Card Played: {}", card); // Verify player state let player: ComponentPlayer = world.read_model(first_caller); diff --git a/src/tests/integration/test_cards.cairo b/src/tests/integration/test_cards.cairo index 513d4ac..85cb318 100644 --- a/src/tests/integration/test_cards.cairo +++ b/src/tests/integration/test_cards.cairo @@ -21,9 +21,7 @@ use starknet::ContractAddress; use crate::models::structs::StructBlockchain; -use crate::models::enums::{ - EnumCard, EnumGameState, EnumColor, EnumGasFeeType, EnumPlayerTarget -}; +use crate::models::enums::{EnumCard, EnumGameState, EnumColor, EnumGasFeeType, EnumPlayerTarget}; use crate::models::components::{ ComponentGame, ComponentHand, ComponentDeposit, ComponentPlayer, ComponentDeck, ComponentDealer }; @@ -220,10 +218,7 @@ fn test_gas_fee_card() { EnumGasFeeType::Any, array![ StructBlockchain { - m_name: "Ethereum", - m_bc_type: EnumColor::DarkBlue, - m_fee: 3, - m_value: 4 + m_name: "Ethereum", m_bc_type: EnumColor::DarkBlue, m_fee: 3, m_value: 4 } ], 3, @@ -345,12 +340,8 @@ fn test_chain_reorg_card() { action_system.draw(false, addr); // Setup blockchains to swap - let blockchain1 = EnumCard::Blockchain( - IBlockchain::new("Ethereum", EnumColor::DarkBlue, 3, 4) - ); - let blockchain2 = EnumCard::Blockchain( - IBlockchain::new("Bitcoin", EnumColor::Gold, 1, 2) - ); + let blockchain1 = EnumCard::Blockchain(IBlockchain::new("Ethereum", EnumColor::DarkBlue, 3, 4)); + let blockchain2 = EnumCard::Blockchain(IBlockchain::new("Bitcoin", EnumColor::Gold, 1, 2)); // Add blockchains to respective decks let mut player1_deck: ComponentDeck = world.read_model(first_caller); @@ -401,14 +392,8 @@ fn test_fifty_one_percent_attack_card() { ]; let mut player2_deck: ComponentDeck = world.read_model(second_caller); - player2_deck - .add( - EnumCard::Blockchain(IBlockchain::new("Ethereum", EnumColor::DarkBlue, 3, 4)) - ); - player2_deck - .add( - EnumCard::Blockchain(IBlockchain::new("Starknet", EnumColor::DarkBlue, 3, 4)) - ); + player2_deck.add(EnumCard::Blockchain(IBlockchain::new("Ethereum", EnumColor::DarkBlue, 3, 4))); + player2_deck.add(EnumCard::Blockchain(IBlockchain::new("Starknet", EnumColor::DarkBlue, 3, 4))); world.write_model_test(@player2_deck); // Set player one as the next caller and draw cards first @@ -451,7 +436,5 @@ fn test_all_cards() { player_system.set_ready(true, addr); let hand: ComponentHand = world.read_model(first_caller); - println!("Hand: {}", hand); assert!(hand.m_cards.len() == 5, "Player should have 5 cards"); - }