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

Troop attack tests #2704

Merged
merged 25 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
56256ea
contracts: guard_add entrypoint tests
credence0x Feb 23, 2025
2fa4bd1
contracts: add guard_delete test
credence0x Feb 23, 2025
5226788
minor variable name update
credence0x Feb 23, 2025
880f1df
minor variable name update
credence0x Feb 23, 2025
42a05c2
contracts: update troop battle impl
credence0x Feb 23, 2025
e32a2f7
contracts: update troop battle impl
credence0x Feb 23, 2025
a2e5fb4
contracts: allow explorer to guard troop swaps
credence0x Feb 23, 2025
e203c3f
contracts: allow explorer to guard troop swaps
credence0x Feb 23, 2025
47da0c2
contracts: test explorer to guard troop swaps
credence0x Feb 23, 2025
7c2ee5e
contracts: test explorer to guard troop swaps
credence0x Feb 23, 2025
0e765f1
contracts: test explorer to guard troop swaps
credence0x Feb 23, 2025
76e6d2a
contracts: improve and test troop movement
credence0x Feb 24, 2025
2871c36
contracts: improve and test troop movement
credence0x Feb 24, 2025
c0cf982
misc
credence0x Feb 24, 2025
0549c4f
misc
credence0x Feb 24, 2025
df0508e
update ci
credence0x Feb 24, 2025
c9bebcf
update ci
credence0x Feb 24, 2025
2569cd6
update ci
credence0x Feb 24, 2025
319967e
update ci
credence0x Feb 24, 2025
4df276a
contracts: update troop attack
credence0x Feb 24, 2025
b312ca8
contracts: add explorer vs explorer tests
credence0x Feb 24, 2025
1ce9ab2
Merge branch 'feat/new-combat' into troop-attack-tests
credence0x Feb 24, 2025
66c64d7
update ci
credence0x Feb 24, 2025
bf446ca
contracts: add explorer vs guards tests
credence0x Feb 24, 2025
59397ea
contracts: add guards vs explorers tests
credence0x Feb 24, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
models,
test_troop_management,
test_troop_movement,
test_troop_battle,
]
fail-fast: false
steps:
Expand Down
5 changes: 5 additions & 0 deletions contracts/game/src/models/owner.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ pub impl OwnerAddressImpl of OwnerAddressTrait {
fn assert_caller_owner(self: ContractAddress) {
assert(self == starknet::get_caller_address(), ErrorMessages::NOT_OWNER);
}
fn assert_caller_not_owner(self: ContractAddress) {
assert!(self != Zero::zero(), "owner is zero");
assert(self != starknet::get_caller_address(), 'caller is owner');
}

fn assert_non_zero(self: ContractAddress) {
assert!(self.is_non_zero(), "owner is zero");
}
Expand Down
7 changes: 6 additions & 1 deletion contracts/game/src/models/structure.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub impl StructureOwnerStoreImpl of StructureOwnerStoreTrait {
return owner;
}

fn store(ref owner: ContractAddress, ref world: WorldStorage, structure_id: ID) {
fn store(owner: ContractAddress, ref world: WorldStorage, structure_id: ID) {
world.write_member(Model::<Structure>::ptr_from_keys(structure_id), selector!("owner"), owner);
}
}
Expand Down Expand Up @@ -72,6 +72,11 @@ pub impl StructureBaseImpl of StructureBaseTrait {
self.category != StructureCategory::None.into()
}

fn is_not_cloaked(self: StructureBase, battle_config: BattleConfig, tick_config: TickConfig) -> bool {
let (is_cloaked, _) = self.is_cloaked(battle_config, tick_config);
return !is_cloaked;
}

fn is_cloaked(self: StructureBase, battle_config: BattleConfig, tick_config: TickConfig) -> (bool, ByteArray) {
// Fragment mines have no immunity
if self.category == StructureCategory::FragmentMine.into() {
Expand Down
29 changes: 24 additions & 5 deletions contracts/game/src/models/troop.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,22 @@ pub enum GuardSlot {

#[generate_trait]
pub impl GuardImpl of GuardTrait {
fn next_attack_slot(ref self: GuardTroops, max_guards: felt252) -> Option<GuardSlot> {
let relevant_slots = match max_guards {
// todo: test
fn assert_functional_slot(ref self: GuardTroops, slot: GuardSlot, max_guards: felt252) {
let functional_slots = self.functional_slots(max_guards);
let mut is_functional_slot: bool = false;
for functional_slot in functional_slots {
if functional_slot == slot {
is_functional_slot = true;
break;
}
};
assert!(is_functional_slot, "slot can't be selected");
}

// todo: test
fn functional_slots(ref self: GuardTroops, max_guards: felt252) -> Array<GuardSlot> {
match max_guards {
0 => panic!("max guards is 0"),
1 => { array![GuardSlot::Delta] },
2 => { array![GuardSlot::Delta, GuardSlot::Charlie] },
Expand All @@ -91,16 +105,21 @@ pub impl GuardImpl of GuardTrait {
panic!("max guards is greater than 4");
array![]
},
};
}
}

// todo: test: critical
fn next_attack_slot(ref self: GuardTroops, max_guards: felt252) -> Option<GuardSlot> {
let functional_slots = self.functional_slots(max_guards);

// Iterate through relevant slots only
let mut i: usize = 0;
loop {
if i == relevant_slots.len() {
if i == functional_slots.len() {
break Option::None;
}

let slot = *relevant_slots.at(i);
let slot = *functional_slots.at(i);
let has_troops = match slot {
GuardSlot::Delta => self.delta.count.is_non_zero(),
GuardSlot::Charlie => self.charlie.count.is_non_zero(),
Expand Down
1 change: 1 addition & 0 deletions contracts/game/src/systems.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod dev {
pub mod combat {
#[cfg(test)]
mod tests {
mod test_troop_battle;
mod test_troop_management;
mod test_troop_movement;
}
Expand Down
Loading
Loading