2025-08-10 11:32:32 +09:00
|
|
|
|
/*! 🎲 RandomBox - 乱数生成Box
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ## 📝 概要
|
|
|
|
|
|
* 高品質な乱数生成機能を提供するBox。
|
|
|
|
|
|
* ゲーム開発、統計処理、テストデータ生成に最適。
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ## 🛠️ 利用可能メソッド
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ### 🔢 基本乱数
|
|
|
|
|
|
* - `random()` - 0.0~1.0の浮動小数点乱数
|
|
|
|
|
|
* - `randInt(min, max)` - 指定範囲の整数乱数
|
|
|
|
|
|
* - `randBool()` - true/falseのランダム選択
|
|
|
|
|
|
* - `seed(value)` - 乱数種を設定(再現可能な乱数)
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ### 🎯 選択・配列操作
|
|
|
|
|
|
* - `choice(array)` - 配列からランダム選択
|
|
|
|
|
|
* - `shuffle(array)` - 配列をシャッフル
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ### 🎨 生成
|
|
|
|
|
|
* - `randString(length)` - ランダム文字列生成
|
|
|
|
|
|
* - `probability(prob)` - 指定確率でtrue
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ## 💡 使用例
|
|
|
|
|
|
* ```nyash
|
|
|
|
|
|
* local random, result, dice, array
|
|
|
|
|
|
* random = new RandomBox()
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* // 基本的な乱数
|
|
|
|
|
|
* result = random.random() // 0.0~1.0
|
|
|
|
|
|
* dice = random.randInt(1, 6) // サイコロ(1-6)
|
|
|
|
|
|
* result = random.randBool() // true or false
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* // 配列関連
|
|
|
|
|
|
* array = ["apple", "banana", "cherry"]
|
|
|
|
|
|
* result = random.choice(array) // ランダム選択
|
|
|
|
|
|
* array = random.shuffle(array) // シャッフル
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* // ゲーム用途
|
|
|
|
|
|
* local password, critical_hit
|
|
|
|
|
|
* password = random.randString(8) // 8文字のランダム文字列
|
|
|
|
|
|
* critical_hit = random.probability(0.1) // 10%でクリティカル
|
|
|
|
|
|
* ```
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ## 🎮 実用例
|
|
|
|
|
|
* ```nyash
|
|
|
|
|
|
* // RPGダメージ計算
|
|
|
|
|
|
* local damage, is_critical
|
|
|
|
|
|
* damage = random.randInt(10, 20) // 基本ダメージ10-20
|
|
|
|
|
|
* is_critical = random.probability(0.15) // 15%でクリティカル
|
|
|
|
|
|
* if (is_critical) {
|
|
|
|
|
|
* damage = damage * 2
|
|
|
|
|
|
* }
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* // テストデータ生成
|
|
|
|
|
|
* local users, user_id, user_name
|
|
|
|
|
|
* users = []
|
|
|
|
|
|
* loop(i < 10) {
|
|
|
|
|
|
* user_id = random.randInt(1000, 9999)
|
|
|
|
|
|
* user_name = "user_" + random.randString(5)
|
|
|
|
|
|
* users.push(user_name + ":" + user_id)
|
|
|
|
|
|
* }
|
|
|
|
|
|
* ```
|
2025-09-17 07:43:07 +09:00
|
|
|
|
*
|
2025-08-10 11:32:32 +09:00
|
|
|
|
* ## ⚠️ 注意
|
|
|
|
|
|
* - 暗号学的に安全な乱数ではない(セキュリティ用途非推奨)
|
|
|
|
|
|
* - seed()で同じ値を設定すると同じ乱数列を生成(テスト用)
|
|
|
|
|
|
* - 大きな配列のshuffleは処理時間が長い場合あり
|
2025-08-09 15:14:44 +09:00
|
|
|
|
*/
|
|
|
|
|
|
|
2025-09-17 07:43:07 +09:00
|
|
|
|
use crate::box_trait::{BoolBox, BoxBase, BoxCore, IntegerBox, NyashBox, StringBox};
|
2025-08-11 20:32:25 +00:00
|
|
|
|
use crate::boxes::{ArrayBox, FloatBox};
|
2025-08-09 15:14:44 +09:00
|
|
|
|
use std::any::Any;
|
2025-09-17 07:43:07 +09:00
|
|
|
|
use std::fmt::{Debug, Display};
|
2025-08-15 01:07:48 +00:00
|
|
|
|
use std::sync::RwLock;
|
2025-08-09 15:14:44 +09:00
|
|
|
|
|
|
|
|
|
|
/// 乱数生成を提供するBox
|
2025-08-15 01:07:48 +00:00
|
|
|
|
#[derive(Debug)]
|
2025-08-09 15:14:44 +09:00
|
|
|
|
pub struct RandomBox {
|
|
|
|
|
|
// 簡易線形合同法による疑似乱数生成器
|
2025-08-15 01:07:48 +00:00
|
|
|
|
seed: RwLock<u64>,
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
base: BoxBase,
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-15 01:07:48 +00:00
|
|
|
|
impl Clone for RandomBox {
|
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
|
let seed_val = *self.seed.read().unwrap();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-15 01:07:48 +00:00
|
|
|
|
Self {
|
|
|
|
|
|
seed: RwLock::new(seed_val),
|
|
|
|
|
|
base: BoxBase::new(), // New unique ID for clone
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
impl RandomBox {
|
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
|
// 現在時刻を種として使用
|
|
|
|
|
|
let seed = std::time::SystemTime::now()
|
|
|
|
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
.as_nanos() as u64;
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
Self {
|
2025-08-15 01:07:48 +00:00
|
|
|
|
seed: RwLock::new(seed),
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
base: BoxBase::new(),
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// 種を設定
|
|
|
|
|
|
pub fn seed(&self, new_seed: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(int_box) = new_seed.as_any().downcast_ref::<IntegerBox>() {
|
2025-08-15 01:07:48 +00:00
|
|
|
|
*self.seed.write().unwrap() = int_box.value as u64;
|
2025-08-09 15:14:44 +09:00
|
|
|
|
Box::new(StringBox::new("Seed set"))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Box::new(StringBox::new("Error: seed() requires integer input"))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// 次の乱数を生成(線形合同法)
|
|
|
|
|
|
fn next_random(&self) -> u64 {
|
2025-08-15 01:07:48 +00:00
|
|
|
|
let mut seed = self.seed.write().unwrap();
|
2025-08-09 15:14:44 +09:00
|
|
|
|
// 線形合同法の定数(Numerical Recipes より)
|
|
|
|
|
|
*seed = seed.wrapping_mul(1664525).wrapping_add(1013904223);
|
|
|
|
|
|
*seed
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// 0.0-1.0の浮動小数点乱数
|
|
|
|
|
|
pub fn random(&self) -> Box<dyn NyashBox> {
|
|
|
|
|
|
let r = self.next_random();
|
|
|
|
|
|
let normalized = (r as f64) / (u64::MAX as f64);
|
|
|
|
|
|
Box::new(FloatBox::new(normalized))
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// 指定範囲の整数乱数
|
|
|
|
|
|
pub fn randInt(&self, min: Box<dyn NyashBox>, max: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let (Some(min_int), Some(max_int)) = (
|
|
|
|
|
|
min.as_any().downcast_ref::<IntegerBox>(),
|
2025-09-17 07:43:07 +09:00
|
|
|
|
max.as_any().downcast_ref::<IntegerBox>(),
|
2025-08-09 15:14:44 +09:00
|
|
|
|
) {
|
|
|
|
|
|
if min_int.value > max_int.value {
|
|
|
|
|
|
return Box::new(StringBox::new("Error: min must be <= max"));
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
let range = (max_int.value - min_int.value + 1) as u64;
|
|
|
|
|
|
let r = self.next_random() % range;
|
|
|
|
|
|
Box::new(IntegerBox::new(min_int.value + r as i64))
|
|
|
|
|
|
} else {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
Box::new(StringBox::new(
|
|
|
|
|
|
"Error: randInt() requires two integer inputs",
|
|
|
|
|
|
))
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// true/falseのランダム選択
|
|
|
|
|
|
pub fn randBool(&self) -> Box<dyn NyashBox> {
|
|
|
|
|
|
let r = self.next_random();
|
|
|
|
|
|
Box::new(BoolBox::new(r % 2 == 0))
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// 配列からランダム選択
|
|
|
|
|
|
pub fn choice(&self, array: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(array_box) = array.as_any().downcast_ref::<ArrayBox>() {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
let length = array_box
|
|
|
|
|
|
.length()
|
|
|
|
|
|
.to_string_box()
|
|
|
|
|
|
.value
|
|
|
|
|
|
.parse::<i64>()
|
|
|
|
|
|
.unwrap_or(0);
|
2025-08-09 15:14:44 +09:00
|
|
|
|
if length == 0 {
|
|
|
|
|
|
return Box::new(StringBox::new("Error: cannot choose from empty array"));
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
let index = self.next_random() % (length as u64);
|
2025-08-10 16:46:39 +09:00
|
|
|
|
// 新しいArrayBox.get()は既にBox<dyn NyashBox>を返すので、直接使用
|
|
|
|
|
|
array_box.get(Box::new(IntegerBox::new(index as i64)))
|
2025-08-09 15:14:44 +09:00
|
|
|
|
} else {
|
|
|
|
|
|
Box::new(StringBox::new("Error: choice() requires array input"))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// 配列をシャッフル
|
|
|
|
|
|
pub fn shuffle(&self, array: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(array_box) = array.as_any().downcast_ref::<ArrayBox>() {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
let length = array_box
|
|
|
|
|
|
.length()
|
|
|
|
|
|
.to_string_box()
|
|
|
|
|
|
.value
|
|
|
|
|
|
.parse::<i64>()
|
|
|
|
|
|
.unwrap_or(0);
|
2025-08-09 15:14:44 +09:00
|
|
|
|
if length <= 1 {
|
|
|
|
|
|
return array;
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
// 新しい配列を作成
|
|
|
|
|
|
let shuffled = ArrayBox::new();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
// 元の配列の要素を全て新しい配列にコピー
|
|
|
|
|
|
for i in 0..length {
|
2025-08-10 16:46:39 +09:00
|
|
|
|
let element = array_box.get(Box::new(IntegerBox::new(i as i64)));
|
|
|
|
|
|
// NullBoxでなければ追加
|
|
|
|
|
|
if element.type_name() != "NullBox" {
|
2025-08-09 15:14:44 +09:00
|
|
|
|
shuffled.push(element);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
// 簡易シャッフル実装(完全なFisher-Yatesは複雑なので)
|
|
|
|
|
|
// 代わりに、元の配列からランダムに選んで新しい配列を作る
|
|
|
|
|
|
let result = ArrayBox::new();
|
|
|
|
|
|
let mut remaining_indices: Vec<usize> = (0..length as usize).collect();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
while !remaining_indices.is_empty() {
|
|
|
|
|
|
let random_idx = (self.next_random() % remaining_indices.len() as u64) as usize;
|
|
|
|
|
|
let actual_idx = remaining_indices.remove(random_idx);
|
2025-08-10 16:46:39 +09:00
|
|
|
|
let element = array_box.get(Box::new(IntegerBox::new(actual_idx as i64)));
|
|
|
|
|
|
// NullBoxでなければ追加
|
|
|
|
|
|
if element.type_name() != "NullBox" {
|
2025-08-09 15:14:44 +09:00
|
|
|
|
result.push(element);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
Box::new(result)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Box::new(StringBox::new("Error: shuffle() requires array input"))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// ランダムな文字列生成
|
|
|
|
|
|
pub fn randString(&self, length: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(len_int) = length.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
|
if len_int.value < 0 {
|
|
|
|
|
|
return Box::new(StringBox::new("Error: length must be positive"));
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
let chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
|
|
let char_vec: Vec<char> = chars.chars().collect();
|
|
|
|
|
|
let mut result = String::new();
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
for _ in 0..len_int.value {
|
|
|
|
|
|
let index = self.next_random() % (char_vec.len() as u64);
|
|
|
|
|
|
result.push(char_vec[index as usize]);
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
Box::new(StringBox::new(&result))
|
|
|
|
|
|
} else {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
Box::new(StringBox::new(
|
|
|
|
|
|
"Error: randString() requires integer length",
|
|
|
|
|
|
))
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
/// 指定確率でtrue
|
|
|
|
|
|
pub fn probability(&self, prob: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(float_box) = prob.as_any().downcast_ref::<FloatBox>() {
|
|
|
|
|
|
if float_box.value < 0.0 || float_box.value > 1.0 {
|
|
|
|
|
|
return Box::new(StringBox::new("Error: probability must be 0.0-1.0"));
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
let r = self.next_random() as f64 / u64::MAX as f64;
|
|
|
|
|
|
Box::new(BoolBox::new(r < float_box.value))
|
|
|
|
|
|
} else if let Some(int_box) = prob.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
|
let prob_val = int_box.value as f64;
|
|
|
|
|
|
if prob_val < 0.0 || prob_val > 1.0 {
|
|
|
|
|
|
return Box::new(StringBox::new("Error: probability must be 0.0-1.0"));
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
let r = self.next_random() as f64 / u64::MAX as f64;
|
|
|
|
|
|
Box::new(BoolBox::new(r < prob_val))
|
|
|
|
|
|
} else {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
Box::new(StringBox::new(
|
|
|
|
|
|
"Error: probability() requires numeric input",
|
|
|
|
|
|
))
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl NyashBox for RandomBox {
|
|
|
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
|
|
"RandomBox"
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
fn to_string_box(&self) -> StringBox {
|
|
|
|
|
|
StringBox::new("RandomBox()")
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
fn clone_box(&self) -> Box<dyn NyashBox> {
|
2025-08-15 04:48:10 +00:00
|
|
|
|
Box::new(self.clone())
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-15 04:29:41 +00:00
|
|
|
|
/// 仮実装: clone_boxと同じ(後で修正)
|
|
|
|
|
|
fn share_box(&self) -> Box<dyn NyashBox> {
|
|
|
|
|
|
self.clone_box()
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-09 15:14:44 +09:00
|
|
|
|
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
|
|
|
|
|
if let Some(other_random) = other.as_any().downcast_ref::<RandomBox>() {
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
BoolBox::new(self.base.id == other_random.base.id)
|
2025-08-09 15:14:44 +09:00
|
|
|
|
} else {
|
|
|
|
|
|
BoolBox::new(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl BoxCore for RandomBox {
|
2025-08-09 15:14:44 +09:00
|
|
|
|
fn box_id(&self) -> u64 {
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
self.base.id
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-11 15:01:11 +09:00
|
|
|
|
fn parent_type_id(&self) -> Option<std::any::TypeId> {
|
|
|
|
|
|
self.base.parent_type_id
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
|
|
write!(f, "RandomBox()")
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-11 15:01:11 +09:00
|
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
|
2025-08-11 15:01:11 +09:00
|
|
|
|
fn as_any_mut(&mut self) -> &mut dyn Any {
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Display for RandomBox {
|
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
self.fmt_box(f)
|
2025-08-09 15:14:44 +09:00
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
|
}
|