Last active
February 4, 2025 13:26
-
-
Save shunsock/09dc09218ec3d832a492ef6a6fd8924f to your computer and use it in GitHub Desktop.
Kiyoshi Hikawa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "kiyoshi" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
rand = "0.9.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand::prelude::*; | |
use std::collections::VecDeque; | |
#[derive(Debug, Clone)] | |
pub struct Kiyoshi { | |
pub queue: VecDeque<Zundoko>, | |
} | |
#[derive(PartialEq, Eq, Debug, Clone)] | |
pub enum Zundoko { | |
Zun, | |
Doko, | |
} | |
impl Kiyoshi { | |
pub fn new(mut q: VecDeque<Zundoko>) -> Self { | |
loop { | |
return if q.len() <= 3 { | |
Kiyoshi { queue: q } | |
} else { | |
let mut q_copy: VecDeque<Zundoko> = q.clone(); | |
q_copy.pop_front(); | |
Kiyoshi::new(q_copy) | |
}; | |
} | |
} | |
pub fn say(self) -> Kiyoshi { | |
let mut rng: ThreadRng = rand::rng(); | |
let mut q: VecDeque<Zundoko> = self.queue.clone(); | |
if rng.random_bool(0.5) { | |
println!("ズン"); | |
q.push_back(Zundoko::Zun); | |
} else { | |
println!("ドコ"); | |
q.push_back(Zundoko::Doko); | |
} | |
Kiyoshi::new(q) | |
} | |
pub fn kiyoshi_said_kiyoshi(&self) -> bool { | |
let mut q: VecDeque<Zundoko> = self.queue.clone(); | |
let expected: Vec<Zundoko> = vec![Zundoko::Zun, Zundoko::Zun, Zundoko::Doko]; | |
let mut actual: Vec<Zundoko> = Vec::new(); | |
loop { | |
match q.pop_front() { | |
Some(zundoko) => { | |
actual.push(zundoko); | |
} | |
None => { | |
return actual == expected; | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod kiyoshi; | |
use kiyoshi::Kiyoshi; | |
use std::collections::VecDeque; | |
fn main() { | |
let mut k: Kiyoshi = Kiyoshi::new(VecDeque::new()); | |
loop { | |
k = k.say(); | |
if k.kiyoshi_said_kiyoshi() { | |
println!("キ・ヨ・シ!"); | |
return; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ドコ | |
ズン | |
ズン | |
ズン | |
ズン | |
ドコ | |
キ・ヨ・シ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment