pub struct AttackConstraints {
pub possible_attackers: Vec<CardId>,
pub possible_defenders: Vec<DefenderId>,
pub global_restrictions: GlobalAttackRestrictions,
pub restrictions: HashMap<CardId, AttackRestriction>,
pub requirements: HashMap<CardId, AttackRequirement>,
}Expand description
Constraints on which creatures can and must attack.
Mirrors Java’s AttackConstraints.java.
Holds per-creature restrictions (can’t attack conditions) and requirements (must-attack conditions), plus global attack limits.
Fields§
§possible_attackers: Vec<CardId>§possible_defenders: Vec<DefenderId>§global_restrictions: GlobalAttackRestrictions§restrictions: HashMap<CardId, AttackRestriction>§requirements: HashMap<CardId, AttackRequirement>Implementations§
Source§impl AttackConstraints
impl AttackConstraints
Sourcepub fn new(
game: &GameState,
attacking_player: PlayerId,
possible_defenders: &[DefenderId],
) -> Self
pub fn new( game: &GameState, attacking_player: PlayerId, possible_defenders: &[DefenderId], ) -> Self
Build constraints for a combat phase.
attacking_player is the player declaring attacks.
pub fn get_restrictions(&self) -> &HashMap<CardId, AttackRestriction>
pub fn get_global_restrictions(&self) -> &GlobalAttackRestrictions
pub fn get_requirements(&self) -> &HashMap<CardId, AttackRequirement>
Sourcepub fn get_legal_attackers(
&self,
cards: &[Card],
) -> (Vec<(CardId, DefenderId)>, i32)
pub fn get_legal_attackers( &self, cards: &[Card], ) -> (Vec<(CardId, DefenderId)>, i32)
Get a set of legal attackers that minimizes requirement violations.
Returns (attack_map, violation_count).
Mirrors Java’s getLegalAttackers(). This is a simplified port that
handles the most common cases (single-creature requirements, global
limits). The full recursive constraint solver from Java is replaced
with a greedy approach that works correctly for 2-player games.
Sourcepub fn count_violations(
&self,
attackers: &[(CardId, DefenderId)],
cards: &[Card],
) -> i32
pub fn count_violations( &self, attackers: &[(CardId, DefenderId)], cards: &[Card], ) -> i32
Count the number of requirement violations for a proposed attack set. Returns -1 if a restriction is violated (illegal attack).
Mirrors Java’s countViolations().
Trait Implementations§
Source§impl Clone for AttackConstraints
impl Clone for AttackConstraints
Source§fn clone(&self) -> AttackConstraints
fn clone(&self) -> AttackConstraints
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more