111 lines
3.4 KiB
Rust
111 lines
3.4 KiB
Rust
mod model;
|
|
mod logic;
|
|
|
|
use model::{AiSystem, Environment, Messaging, Personality, Relationship};
|
|
use serde_json;
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
use chrono::{Duration, Local, NaiveDateTime};
|
|
|
|
#[derive(Debug)]
|
|
struct AIState {
|
|
relation_score: f32,
|
|
previous_score: f32,
|
|
decay_rate: f32,
|
|
sensitivity: f32,
|
|
message_threshold: f32,
|
|
last_message_time: NaiveDateTime,
|
|
}
|
|
|
|
impl AIState {
|
|
fn update(&mut self, now: NaiveDateTime) {
|
|
let days_passed = (now - self.last_message_time).num_days() as f32;
|
|
let decay = self.decay_rate * days_passed;
|
|
self.previous_score = self.relation_score;
|
|
self.relation_score -= decay;
|
|
self.relation_score = self.relation_score.clamp(0.0, 100.0);
|
|
}
|
|
|
|
fn should_talk(&self) -> bool {
|
|
let delta = self.previous_score - self.relation_score;
|
|
delta > self.message_threshold && self.sensitivity > 0.5
|
|
}
|
|
|
|
fn generate_message(&self) -> String {
|
|
let _delta = self.previous_score - self.relation_score;
|
|
match self.relation_score as i32 {
|
|
80..=100 => "ふふっ、最近どうしてる?会いたくなっちゃった!".to_string(),
|
|
60..=79 => "ちょっとだけ、さみしかったんだよ?".to_string(),
|
|
40..=59 => "えっと……話せる時間ある?".to_string(),
|
|
_ => "ううん、もしかして私のこと、忘れちゃったのかな……".to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
// テスト用のAIシステム初期化
|
|
let ai = AiSystem {
|
|
personality: Personality {
|
|
kind: "positive".to_string(),
|
|
strength: 0.8,
|
|
},
|
|
relationship: Relationship {
|
|
trust: 0.7,
|
|
intimacy: 0.6,
|
|
curiosity: 0.5,
|
|
threshold: 1.5,
|
|
},
|
|
environment: Environment {
|
|
luck_today: 0.9,
|
|
luck_history: vec![0.9, 0.9, 0.9],
|
|
level: 1,
|
|
},
|
|
messaging: Messaging {
|
|
enabled: true,
|
|
schedule_time: Some("08:00".to_string()),
|
|
decay_rate: 0.1,
|
|
templates: vec![
|
|
"ねえねえ、今日もがんばろうね!".to_string(),
|
|
"そろそろ話したくなっちゃった...".to_string(),
|
|
],
|
|
},
|
|
};
|
|
|
|
// JSONにシリアライズして表示
|
|
let json = serde_json::to_string_pretty(&ai).unwrap();
|
|
println!("{}", json);
|
|
|
|
let path = Path::new("config/config.json");
|
|
let data = fs::read_to_string(path).expect("JSON読み込み失敗");
|
|
let ai: AiSystem = serde_json::from_str(&data).expect("パース失敗");
|
|
|
|
println!("AI構成読み込み完了: {:?}", ai);
|
|
|
|
if logic::should_send(&ai) {
|
|
let msg = &ai.messaging.templates[0];
|
|
println!("✅ メッセージ送信決定: {msg}");
|
|
} else {
|
|
println!("❌ 今はメッセージを送る条件ではありません。");
|
|
}
|
|
|
|
let now = Local::now().naive_local();
|
|
let mut ai = AIState {
|
|
relation_score: 80.0,
|
|
previous_score: 80.0,
|
|
decay_rate: 1.5, // 1日あたりの減少スコア
|
|
sensitivity: 0.8,
|
|
message_threshold: 5.0,
|
|
last_message_time: now - Duration::days(4), // 最後の会話から4日経過
|
|
};
|
|
|
|
ai.update(now);
|
|
|
|
if ai.should_talk() {
|
|
println!("AI発話: {}", ai.generate_message());
|
|
} else {
|
|
println!("まだ何も言わずにそっとしているようです...");
|
|
}
|
|
}
|
|
|