1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! Policy trait definitions for the reputation mechanic.
//!
//! These traits define the "slots" where different strategies can be plugged in.
//! Each policy represents a specific aspect of reputation behavior that can
//! vary independently.
//!
//! # Policy-Based Design
//!
//! This module follows the Policy-Based Design pattern:
//! - Each trait represents a single dimension of variation
//! - All methods are static (no `&self`) for zero runtime overhead
//! - Implementations are Zero-Sized Types (ZST) for optimal performance
//! - Different policies can be combined to create custom mechanics
use ReputationConfig;
/// Policy for calculating reputation value changes.
///
/// This policy determines how delta changes are applied to the current value.
///
/// # Design Notes
///
/// - All methods are static (no `&self`) to ensure zero runtime overhead
/// - Implementations should be Zero-Sized Types (ZST) for optimal performance
/// - Can implement different scaling behaviors (linear, logarithmic, threshold-based)
///
/// # Examples
///
/// ```
/// use issun_core::mechanics::reputation::policies::ChangePolicy;
///
/// // Define a custom change policy
/// pub struct DoublePositiveChange;
///
/// impl ChangePolicy for DoublePositiveChange {
/// fn apply_change(current: f32, delta: f32, _config: &issun_core::mechanics::reputation::ReputationConfig) -> f32 {
/// if delta > 0.0 {
/// current + (delta * 2.0) // Double positive changes
/// } else {
/// current + delta // Normal negative changes
/// }
/// }
/// }
///
/// // Use it
/// let config = issun_core::mechanics::reputation::ReputationConfig::default();
/// let new_value = DoublePositiveChange::apply_change(50.0, 10.0, &config);
/// assert_eq!(new_value, 70.0); // 50 + (10 * 2)
/// ```
/// Policy for time-based value decay.
///
/// This policy determines how reputation naturally changes over time
/// (typically decaying toward a neutral value).
///
/// # Design Notes
///
/// - Decay can be exponential, linear, or none
/// - Elapsed time is provided to support different time scales
/// - Can implement asymmetric decay (different rates for high/low values)
///
/// # Examples
///
/// ```
/// use issun_core::mechanics::reputation::policies::DecayPolicy;
///
/// // Define a custom decay policy
/// pub struct HalfLifeDecay;
///
/// impl DecayPolicy for HalfLifeDecay {
/// fn apply_decay(current: f32, elapsed_time: u32, config: &issun_core::mechanics::reputation::ReputationConfig) -> f32 {
/// // Exponential decay with half-life
/// current * config.decay_rate.powi(elapsed_time as i32)
/// }
/// }
///
/// // Use it
/// let config = issun_core::mechanics::reputation::ReputationConfig {
/// min: 0.0,
/// max: 100.0,
/// decay_rate: 0.5, // 50% decay per turn
/// };
/// let new_value = HalfLifeDecay::apply_decay(100.0, 1, &config);
/// assert_eq!(new_value, 50.0); // 100 * 0.5^1
/// ```
/// Policy for clamping values to valid ranges.
///
/// This policy determines how out-of-range values are handled.
///
/// # Design Notes
///
/// - Can implement fixed ranges, dynamic ranges, or no clamping
/// - Should return whether clamping occurred for event emission
/// - Ranges can be asymmetric or context-dependent
///
/// # Examples
///
/// ```
/// use issun_core::mechanics::reputation::policies::ClampPolicy;
///
/// // Define a custom clamp policy
/// pub struct SoftCap;
///
/// impl ClampPolicy for SoftCap {
/// fn clamp(value: f32, config: &issun_core::mechanics::reputation::ReputationConfig) -> (f32, bool) {
/// // Soft cap: harder to reach extremes
/// if value > config.max {
/// let excess = value - config.max;
/// let clamped = config.max + (excess * 0.1); // Only 10% of excess
/// (clamped, true)
/// } else if value < config.min {
/// let deficit = config.min - value;
/// let clamped = config.min - (deficit * 0.1);
/// (clamped, true)
/// } else {
/// (value, false)
/// }
/// }
/// }
/// ```