poke_engine/
lib.rs

1#[cfg(feature = "gen1")]
2#[path = "gen1/abilities.rs"]
3pub mod abilities;
4#[cfg(feature = "gen1")]
5#[path = "gen1/base_stats.rs"]
6pub mod base_stats;
7#[cfg(feature = "gen1")]
8#[path = "gen1/choice_effects.rs"]
9pub mod choice_effects;
10#[cfg(feature = "gen1")]
11#[path = "gen1/damage_calc.rs"]
12pub mod damage_calc;
13#[cfg(feature = "gen1")]
14#[path = "gen1/evaluate.rs"]
15pub mod evaluate;
16#[cfg(feature = "gen1")]
17#[path = "gen1/generate_instructions.rs"]
18pub mod generate_instructions;
19#[cfg(feature = "gen1")]
20#[path = "gen1/items.rs"]
21pub mod items;
22#[cfg(feature = "gen1")]
23#[path = "gen1/state.rs"]
24pub mod state;
25
26#[cfg(feature = "gen2")]
27#[path = "gen2/abilities.rs"]
28pub mod abilities;
29#[cfg(feature = "gen2")]
30#[path = "gen2/base_stats.rs"]
31pub mod base_stats;
32#[cfg(feature = "gen2")]
33#[path = "gen2/choice_effects.rs"]
34pub mod choice_effects;
35#[cfg(feature = "gen2")]
36#[path = "gen2/damage_calc.rs"]
37pub mod damage_calc;
38#[cfg(feature = "gen2")]
39#[path = "gen2/evaluate.rs"]
40pub mod evaluate;
41#[cfg(feature = "gen2")]
42#[path = "gen2/generate_instructions.rs"]
43pub mod generate_instructions;
44#[cfg(feature = "gen2")]
45#[path = "gen2/items.rs"]
46pub mod items;
47#[cfg(feature = "gen2")]
48#[path = "gen2/state.rs"]
49pub mod state;
50
51#[cfg(not(any(feature = "gen2", feature = "gen1")))]
52pub mod abilities;
53#[cfg(not(any(feature = "gen2", feature = "gen1")))]
54pub mod base_stats;
55#[cfg(not(any(feature = "gen2", feature = "gen1")))]
56pub mod choice_effects;
57#[cfg(not(any(feature = "gen2", feature = "gen1")))]
58pub mod damage_calc;
59#[cfg(not(any(feature = "gen2", feature = "gen1")))]
60pub mod evaluate;
61#[cfg(not(any(feature = "gen2", feature = "gen1")))]
62pub mod generate_instructions;
63#[cfg(not(any(feature = "gen2", feature = "gen1")))]
64pub mod items;
65#[cfg(not(any(feature = "gen2", feature = "gen1")))]
66pub mod state;
67
68pub mod choices;
69pub mod instruction;
70pub mod io;
71pub mod mcts;
72pub mod pokemon;
73pub mod search;
74
75#[macro_export]
76macro_rules! assert_unique_feature {
77    () => {};
78    ($first:tt $(,$rest:tt)*) => {
79        $(
80            #[cfg(all(feature = $first, feature = $rest))]
81            compile_error!(concat!("features \"", $first, "\" and \"", $rest, "\" cannot be used together"));
82        )*
83        assert_unique_feature!($($rest),*);
84    }
85}
86
87#[macro_export]
88macro_rules! define_enum_with_from_str {
89    // Case when a default variant is provided
90    (
91        #[repr($repr:ident)]
92        $(#[$meta:meta])*
93        $name:ident {
94            $($variant:ident),+ $(,)?
95        },
96        default = $default_variant:ident
97    ) => {
98        #[repr($repr)]
99        $(#[$meta])*
100        pub enum $name {
101            $($variant),+
102        }
103
104        impl std::str::FromStr for $name {
105            type Err = ();
106
107            fn from_str(input: &str) -> Result<Self, Self::Err> {
108                match input.to_uppercase().as_str() {
109                    $(
110                        stringify!($variant) => Ok($name::$variant),
111                    )+
112                    _ => Ok($name::$default_variant),
113                }
114            }
115        }
116
117        impl std::fmt::Display for $name {
118            fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
119                write!(f, "{:?}", self)
120            }
121        }
122
123        impl From<$repr> for $name {
124            fn from(value: $repr) -> $name {
125                match value {
126                    $(
127                        x if x == $name::$variant as $repr => $name::$variant,
128                    )+
129                    _ => $name::$default_variant,
130                }
131            }
132        }
133        impl Into<$repr> for $name {
134            fn into(self) -> $repr {
135                self as $repr
136            }
137        }
138    };
139
140    // Case when no default variant is provided
141    (
142        #[repr($repr:ident)]
143        $(#[$meta:meta])*
144        $name:ident {
145            $($variant:ident),+ $(,)?
146        }
147    ) => {
148        #[repr($repr)]
149        $(#[$meta])*
150        pub enum $name {
151            $($variant),+
152        }
153
154        impl std::str::FromStr for $name {
155            type Err = ();
156
157            fn from_str(input: &str) -> Result<Self, Self::Err> {
158                match input.to_uppercase().as_str() {
159                    $(
160                        stringify!($variant) => Ok($name::$variant),
161                    )+
162                    _ => panic!("Invalid {}: {}", stringify!($name), input.to_uppercase().as_str()),
163                }
164            }
165        }
166
167        impl std::fmt::Display for $name {
168            fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169                write!(f, "{:?}", self)
170            }
171        }
172
173        impl From<$repr> for $name {
174            fn from(value: $repr) -> $name {
175                match value {
176                    $(
177                        x if x == $name::$variant as $repr => $name::$variant,
178                    )+
179                    _ => panic!("Invalid {}: {}", stringify!($name), value),
180                }
181            }
182        }
183        impl Into<$repr> for $name {
184            fn into(self) -> $repr {
185                self as $repr
186            }
187        }
188    };
189}
190
191assert_unique_feature!("gen2", "gen3", "gen4", "gen5", "gen6", "gen7", "gen8", "gen9");