Compare commits

...

5 commits

Author SHA1 Message Date
96345d7a4a stupid bug 2022-09-21 20:07:15 +09:00
12536c2d5c mrrrp 2022-09-21 19:54:27 +09:00
64c11f6ce0 fine I'll beautify them 2022-09-21 19:02:13 +09:00
e540cd5b9a scrunkly 2022-09-21 18:42:06 +09:00
fe50ee1f2c more shit 2022-09-21 18:22:14 +09:00
6 changed files with 3964 additions and 17 deletions

View file

@ -253,7 +253,7 @@ const catgirlTable = generateMarkov(catgirlNonsense.split('\n'), 2)
const keysmashTable = generateMarkov(keysmash, 1); const keysmashTable = generateMarkov(keysmash, 1);
const scrunklyTable = generateMarkov(scrunks, 2); const scrunklyTable = generateMarkov(scrunks, 2);
console.log(JSON.stringify(magic(catgirlTable))) console.log(JSON.stringify(magic(scrunklyTable)))
// console.log(generateFromArray(catgirlTable, 100, 'ny')); // console.log(generateFromArray(catgirlTable, 100, 'ny'));
// //

409
src/catgirl_nonsense.rs Normal file
View file

@ -0,0 +1,409 @@
uwurandom_proc_macros::gen_fsm![
{
"choices": [
{
"nextNgram": 0,
"nextChar": "a",
"cumulativeProbability": 2
},
{
"nextNgram": 1,
"nextChar": "m",
"cumulativeProbability": 3
}
],
"totalProbability": 3,
"name": "aa"
},
{
"choices": [
{
"nextNgram": 7,
"nextChar": "r",
"cumulativeProbability": 3
},
{
"nextNgram": 6,
"nextChar": "e",
"cumulativeProbability": 4
}
],
"totalProbability": 4,
"name": "am"
},
{
"choices": [
{
"nextNgram": 8,
"nextChar": "y",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "an"
},
{
"choices": [
{
"nextNgram": 9,
"nextChar": "w",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "ao"
},
{
"choices": [
{
"nextNgram": 9,
"nextChar": "w",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "eo"
},
{
"choices": [
{
"nextNgram": 21,
"nextChar": "m",
"cumulativeProbability": 6
},
{
"nextNgram": 22,
"nextChar": "n",
"cumulativeProbability": 7
},
{
"nextNgram": 23,
"nextChar": "p",
"cumulativeProbability": 8
}
],
"totalProbability": 8,
"name": "ew"
},
{
"choices": [
{
"nextNgram": 4,
"nextChar": "o",
"cumulativeProbability": 3
},
{
"nextNgram": 5,
"nextChar": "w",
"cumulativeProbability": 5
}
],
"totalProbability": 5,
"name": "me"
},
{
"choices": [
{
"nextNgram": 16,
"nextChar": "o",
"cumulativeProbability": 15
},
{
"nextNgram": 12,
"nextChar": "a",
"cumulativeProbability": 24
},
{
"nextNgram": 18,
"nextChar": "r",
"cumulativeProbability": 28
},
{
"nextNgram": 19,
"nextChar": "w",
"cumulativeProbability": 29
},
{
"nextNgram": 13,
"nextChar": "e",
"cumulativeProbability": 30
}
],
"totalProbability": 30,
"name": "mr"
},
{
"choices": [
{
"nextNgram": 26,
"nextChar": "a",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "ny"
},
{
"choices": [
{
"nextNgram": 21,
"nextChar": "m",
"cumulativeProbability": 22
},
{
"nextNgram": 24,
"nextChar": "r",
"cumulativeProbability": 32
},
{
"nextNgram": 22,
"nextChar": "n",
"cumulativeProbability": 36
},
{
"nextNgram": 25,
"nextChar": "w",
"cumulativeProbability": 37
},
{
"nextNgram": 23,
"nextChar": "p",
"cumulativeProbability": 38
}
],
"totalProbability": 38,
"name": "ow"
},
{
"choices": [
{
"nextNgram": 11,
"nextChar": "u",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "pp"
},
{
"choices": [
{
"nextNgram": 20,
"nextChar": "r",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "pu"
},
{
"choices": [
{
"nextNgram": 3,
"nextChar": "o",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "ra"
},
{
"choices": [
{
"nextNgram": 4,
"nextChar": "o",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "re"
},
{
"choices": [
{
"nextNgram": 7,
"nextChar": "r",
"cumulativeProbability": 1
},
{
"nextNgram": 6,
"nextChar": "e",
"cumulativeProbability": 2
}
],
"totalProbability": 2,
"name": "rm"
},
{
"choices": [
{
"nextNgram": 8,
"nextChar": "y",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "rn"
},
{
"choices": [
{
"nextNgram": 9,
"nextChar": "w",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "ro"
},
{
"choices": [
{
"nextNgram": 10,
"nextChar": "p",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "rp"
},
{
"choices": [
{
"nextNgram": 18,
"nextChar": "r",
"cumulativeProbability": 7
},
{
"nextNgram": 14,
"nextChar": "m",
"cumulativeProbability": 10
},
{
"nextNgram": 16,
"nextChar": "o",
"cumulativeProbability": 13
},
{
"nextNgram": 17,
"nextChar": "p",
"cumulativeProbability": 14
}
],
"totalProbability": 14,
"name": "rr"
},
{
"choices": [
{
"nextNgram": 21,
"nextChar": "m",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "rw"
},
{
"choices": [
{
"nextNgram": 18,
"nextChar": "r",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "ur"
},
{
"choices": [
{
"nextNgram": 7,
"nextChar": "r",
"cumulativeProbability": 17
},
{
"nextNgram": 6,
"nextChar": "e",
"cumulativeProbability": 30
}
],
"totalProbability": 30,
"name": "wm"
},
{
"choices": [
{
"nextNgram": 8,
"nextChar": "y",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "wn"
},
{
"choices": [
{
"nextNgram": 11,
"nextChar": "u",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "wp"
},
{
"choices": [
{
"nextNgram": 14,
"nextChar": "m",
"cumulativeProbability": 7
},
{
"nextNgram": 15,
"nextChar": "n",
"cumulativeProbability": 10
}
],
"totalProbability": 10,
"name": "wr"
},
{
"choices": [
{
"nextNgram": 25,
"nextChar": "w",
"cumulativeProbability": 3
},
{
"nextNgram": 21,
"nextChar": "m",
"cumulativeProbability": 4
}
],
"totalProbability": 4,
"name": "ww"
},
{
"choices": [
{
"nextNgram": 0,
"nextChar": "a",
"cumulativeProbability": 4
},
{
"nextNgram": 2,
"nextChar": "n",
"cumulativeProbability": 5
},
{
"nextNgram": 1,
"nextChar": "m",
"cumulativeProbability": 6
}
],
"totalProbability": 6,
"name": "ya"
}
];

579
src/keysmash.rs Normal file
View file

@ -0,0 +1,579 @@
uwurandom_proc_macros::gen_fsm![
{
"choices": [
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 4
},
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 5
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 6
},
{
"nextNgram": 11,
"nextChar": "l",
"cumulativeProbability": 7
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 8
}
],
"totalProbability": 8,
"name": ";"
},
{
"choices": [
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 7
},
{
"nextNgram": 9,
"nextChar": "j",
"cumulativeProbability": 13
},
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 18
},
{
"nextNgram": 11,
"nextChar": "l",
"cumulativeProbability": 21
},
{
"nextNgram": 16,
"nextChar": "u",
"cumulativeProbability": 24
},
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 26
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 28
},
{
"nextNgram": 0,
"nextChar": ";",
"cumulativeProbability": 29
},
{
"nextNgram": 14,
"nextChar": "r",
"cumulativeProbability": 30
}
],
"totalProbability": 30,
"name": "a"
},
{
"choices": [
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 1
},
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 2
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 3
}
],
"totalProbability": 3,
"name": "b"
},
{
"choices": [
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 7
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 12
},
{
"nextNgram": 15,
"nextChar": "s",
"cumulativeProbability": 13
},
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 14
},
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 15
},
{
"nextNgram": 9,
"nextChar": "j",
"cumulativeProbability": 16
},
{
"nextNgram": 2,
"nextChar": "b",
"cumulativeProbability": 17
}
],
"totalProbability": 17,
"name": "d"
},
{
"choices": [
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "e"
},
{
"choices": [
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 12
},
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 16
},
{
"nextNgram": 9,
"nextChar": "j",
"cumulativeProbability": 19
},
{
"nextNgram": 11,
"nextChar": "l",
"cumulativeProbability": 21
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 23
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 25
},
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 26
}
],
"totalProbability": 26,
"name": "f"
},
{
"choices": [
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 8
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 14
},
{
"nextNgram": 0,
"nextChar": ";",
"cumulativeProbability": 18
},
{
"nextNgram": 9,
"nextChar": "j",
"cumulativeProbability": 22
},
{
"nextNgram": 11,
"nextChar": "l",
"cumulativeProbability": 25
},
{
"nextNgram": 2,
"nextChar": "b",
"cumulativeProbability": 27
},
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 29
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 30
},
{
"nextNgram": 15,
"nextChar": "s",
"cumulativeProbability": 31
},
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 32
},
{
"nextNgram": 16,
"nextChar": "u",
"cumulativeProbability": 33
},
{
"nextNgram": 12,
"nextChar": "n",
"cumulativeProbability": 34
}
],
"totalProbability": 34,
"name": "g"
},
{
"choices": [
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 7
},
{
"nextNgram": 9,
"nextChar": "j",
"cumulativeProbability": 11
},
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 14
},
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 17
},
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 20
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 23
},
{
"nextNgram": 8,
"nextChar": "i",
"cumulativeProbability": 25
},
{
"nextNgram": 14,
"nextChar": "r",
"cumulativeProbability": 27
},
{
"nextNgram": 0,
"nextChar": ";",
"cumulativeProbability": 28
},
{
"nextNgram": 12,
"nextChar": "n",
"cumulativeProbability": 29
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 30
},
{
"nextNgram": 16,
"nextChar": "u",
"cumulativeProbability": 31
}
],
"totalProbability": 31,
"name": "h"
},
{
"choices": [
{
"nextNgram": 16,
"nextChar": "u",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "i"
},
{
"choices": [
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 5
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 9
},
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 12
},
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 15
},
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 17
},
{
"nextNgram": 14,
"nextChar": "r",
"cumulativeProbability": 18
},
{
"nextNgram": 4,
"nextChar": "e",
"cumulativeProbability": 19
},
{
"nextNgram": 13,
"nextChar": "o",
"cumulativeProbability": 20
},
{
"nextNgram": 11,
"nextChar": "l",
"cumulativeProbability": 21
},
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 22
}
],
"totalProbability": 22,
"name": "j"
},
{
"choices": [
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 6
},
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 10
},
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 13
},
{
"nextNgram": 9,
"nextChar": "j",
"cumulativeProbability": 16
},
{
"nextNgram": 15,
"nextChar": "s",
"cumulativeProbability": 17
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 18
},
{
"nextNgram": 11,
"nextChar": "l",
"cumulativeProbability": 19
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 20
}
],
"totalProbability": 20,
"name": "k"
},
{
"choices": [
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 4
},
{
"nextNgram": 0,
"nextChar": ";",
"cumulativeProbability": 6
},
{
"nextNgram": 15,
"nextChar": "s",
"cumulativeProbability": 7
},
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 8
},
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 9
},
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 10
},
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 11
}
],
"totalProbability": 11,
"name": "l"
},
{
"choices": [
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 1
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 2
}
],
"totalProbability": 2,
"name": "n"
},
{
"choices": [
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 1
}
],
"totalProbability": 1,
"name": "o"
},
{
"choices": [
{
"nextNgram": 6,
"nextChar": "g",
"cumulativeProbability": 4
},
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 6
},
{
"nextNgram": 7,
"nextChar": "h",
"cumulativeProbability": 7
}
],
"totalProbability": 7,
"name": "r"
},
{
"choices": [
{
"nextNgram": 3,
"nextChar": "d",
"cumulativeProbability": 1
},
{
"nextNgram": 10,
"nextChar": "k",
"cumulativeProbability": 2
}
],
"totalProbability": 2,
"name": "s"
},
{
"choices": [
{
"nextNgram": 14,
"nextChar": "r",
"cumulativeProbability": 3
},
{
"nextNgram": 1,
"nextChar": "a",
"cumulativeProbability": 4
},
{
"nextNgram": 5,
"nextChar": "f",
"cumulativeProbability": 5
},
{
"nextNgram": 9,
"nextChar": "j",
"cumulativeProbability": 6
},
{
"nextNgram": 4,
"nextChar": "e",
"cumulativeProbability": 7
}
],
"totalProbability": 7,
"name": "u"
}
];

View file

@ -5,20 +5,53 @@ pub fn add(left: usize, right: usize) -> usize {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use crate::{keysmash, scrunkly};
use super::catgirl_nonsense;
#[test] #[test]
fn it_works() { fn catgirl_nonsense_test() {
// Use a stable-algorithm RNG with fixed seed
let mut rng = rand_pcg::Pcg32::new(0xcafef00dd15ea5e5, 0xa02bdbf7bb3c0a7); let mut rng = rand_pcg::Pcg32::new(0xcafef00dd15ea5e5, 0xa02bdbf7bb3c0a7);
let mut state_machine = StateMachine::Ny; let mut state_machine = catgirl_nonsense::StateMachine::Mr;
let mut result = String::from("ny"); let mut result = String::from("mr");
for _ in 0..100 { for _ in 0..100 {
let (new_state, generated) = state_machine.generate(&mut rng); let (new_state, generated) = state_machine.generate(&mut rng);
result.push(generated); result.push(generated);
state_machine = new_state; state_machine = new_state;
} }
assert_eq!(&result, "nyaaaameowmrowrmrowmrrmeowmrowmeownyanyaaaaaaaaaaaaamraowrmeowwwmeowmraowmrowmrowmeowmeowrnyamreownyaa"); assert_eq!(&result, "mrowrnyameowmrowrmrowmrrmeowmrowmeownyanyaaaaaaaaaaaaamraowrmeowwwmeowmraowmrowmrowmeowmeowrnyamreowny");
}
#[test]
fn keysmash_test() {
// Use a stable-algorithm RNG with fixed seed
let mut rng = rand_pcg::Pcg32::new(0xcafef00dd15ea5e5, 0xa02bdbf7bb3c0a7);
let (mut state_machine, result) = keysmash::StateMachine::new_random(&mut rng);
let mut result = String::from(result);
for _ in 0..100 {
let (new_state, generated) = state_machine.generate(&mut rng);
result.push(generated);
state_machine = new_state;
}
assert_eq!(&result, "ra;ajgjdhdfkgldskadfghkfghiurgjeghnhgjalkjfhgnhrgjhnhiuradfdbahrgbafhg;djkafgjhjrajfjdfghfhdfgajgadka");
}
#[test]
fn scrunkly_test() {
// Use a stable-algorithm RNG with fixed seed
let mut rng = rand_pcg::Pcg32::new(0xcafef00dd15ea5e5, 0xa02bdbf7bb3c0a7);
let mut state_machine = scrunkly::StateMachine::Aw;
let mut result = String::from("aw");
for _ in 0..100 {
let (new_state, generated) = state_machine.generate(&mut rng);
result.push(generated);
state_machine = new_state;
}
assert_eq!(&result, "aw sproinkly,,,,scringle limtle cutest the like scrinkly double scrimblookimty... ittle adornale boink");
} }
} }
uwurandom_proc_macros::gen_fsm![{"choices":[{"nextNgram":0,"nextChar":"a","cumulativeProbability":2},{"nextNgram":1,"nextChar":"m","cumulativeProbability":3}],"totalProbability":3,"name":"aa"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":3},{"nextNgram":6,"nextChar":"e","cumulativeProbability":4}],"totalProbability":4,"name":"am"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"an"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"ao"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"eo"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":6},{"nextNgram":22,"nextChar":"n","cumulativeProbability":7},{"nextNgram":23,"nextChar":"p","cumulativeProbability":8}],"totalProbability":8,"name":"ew"},{"choices":[{"nextNgram":4,"nextChar":"o","cumulativeProbability":3},{"nextNgram":5,"nextChar":"w","cumulativeProbability":5}],"totalProbability":5,"name":"me"},{"choices":[{"nextNgram":16,"nextChar":"o","cumulativeProbability":15},{"nextNgram":12,"nextChar":"a","cumulativeProbability":24},{"nextNgram":18,"nextChar":"r","cumulativeProbability":28},{"nextNgram":19,"nextChar":"w","cumulativeProbability":29},{"nextNgram":13,"nextChar":"e","cumulativeProbability":30}],"totalProbability":30,"name":"mr"},{"choices":[{"nextNgram":26,"nextChar":"a","cumulativeProbability":1}],"totalProbability":1,"name":"ny"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":22},{"nextNgram":24,"nextChar":"r","cumulativeProbability":32},{"nextNgram":22,"nextChar":"n","cumulativeProbability":36},{"nextNgram":25,"nextChar":"w","cumulativeProbability":37},{"nextNgram":23,"nextChar":"p","cumulativeProbability":38}],"totalProbability":38,"name":"ow"},{"choices":[{"nextNgram":11,"nextChar":"u","cumulativeProbability":1}],"totalProbability":1,"name":"pp"},{"choices":[{"nextNgram":20,"nextChar":"r","cumulativeProbability":1}],"totalProbability":1,"name":"pu"},{"choices":[{"nextNgram":3,"nextChar":"o","cumulativeProbability":1}],"totalProbability":1,"name":"ra"},{"choices":[{"nextNgram":4,"nextChar":"o","cumulativeProbability":1}],"totalProbability":1,"name":"re"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":1},{"nextNgram":6,"nextChar":"e","cumulativeProbability":2}],"totalProbability":2,"name":"rm"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"rn"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"ro"},{"choices":[{"nextNgram":10,"nextChar":"p","cumulativeProbability":1}],"totalProbability":1,"name":"rp"},{"choices":[{"nextNgram":18,"nextChar":"r","cumulativeProbability":7},{"nextNgram":14,"nextChar":"m","cumulativeProbability":10},{"nextNgram":16,"nextChar":"o","cumulativeProbability":13},{"nextNgram":17,"nextChar":"p","cumulativeProbability":14}],"totalProbability":14,"name":"rr"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":1}],"totalProbability":1,"name":"rw"},{"choices":[{"nextNgram":18,"nextChar":"r","cumulativeProbability":1}],"totalProbability":1,"name":"ur"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":17},{"nextNgram":6,"nextChar":"e","cumulativeProbability":30}],"totalProbability":30,"name":"wm"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"wn"},{"choices":[{"nextNgram":11,"nextChar":"u","cumulativeProbability":1}],"totalProbability":1,"name":"wp"},{"choices":[{"nextNgram":14,"nextChar":"m","cumulativeProbability":7},{"nextNgram":15,"nextChar":"n","cumulativeProbability":10}],"totalProbability":10,"name":"wr"},{"choices":[{"nextNgram":25,"nextChar":"w","cumulativeProbability":3},{"nextNgram":21,"nextChar":"m","cumulativeProbability":4}],"totalProbability":4,"name":"ww"},{"choices":[{"nextNgram":0,"nextChar":"a","cumulativeProbability":4},{"nextNgram":2,"nextChar":"n","cumulativeProbability":5},{"nextNgram":1,"nextChar":"m","cumulativeProbability":6}],"totalProbability":6,"name":"ya"}]; mod catgirl_nonsense;
mod keysmash;
mod scrunkly;

2901
src/scrunkly.rs Normal file

File diff suppressed because it is too large Load diff

View file

@ -12,9 +12,15 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
let input: Vec<MarkovArr> = serde_json::from_str(&format!("[{}]", item)).unwrap(); let input: Vec<MarkovArr> = serde_json::from_str(&format!("[{}]", item)).unwrap();
let mut match_arms = quote!(); let mut match_arms = quote!();
let mut variants = quote!(); let mut variants = quote!();
for state in input.iter() { let mut random_selection_match_arms = quote!();
let name = state.name.to_case(Case::Pascal); for (idx, state) in input.iter().enumerate() {
let name = Ident::new(&name, Span::call_site().into()); let name = to_ident(&state.name);
let name_lit = &state.name;
let idx = idx as u32;
random_selection_match_arms = quote!(
#random_selection_match_arms
#idx => (Self::#name, #name_lit),
);
variants = quote!( variants = quote!(
#variants #variants
#name, #name,
@ -22,8 +28,7 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
let mut inner_match_arms = quote!(); let mut inner_match_arms = quote!();
if state.total_probability == 1 { if state.total_probability == 1 {
let choice = &state.choices[0]; let choice = &state.choices[0];
let next_state = input[choice.next_ngram].name.to_case(Case::Pascal); let next_state = to_ident(&input[choice.next_ngram].name);
let next_state = Ident::new(&next_state, Span::call_site().into());
let next_char = LitChar::new(choice.next_char, Span::call_site().into()); let next_char = LitChar::new(choice.next_char, Span::call_site().into());
match_arms = quote!( match_arms = quote!(
#match_arms #match_arms
@ -32,8 +37,7 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
continue; continue;
} }
for choice in &state.choices { for choice in &state.choices {
let next_state = input[choice.next_ngram].name.to_case(Case::Pascal); let next_state = to_ident(&input[choice.next_ngram].name);
let next_state = Ident::new(&next_state, Span::call_site().into());
let cumulative_probability = choice.cumulative_probability - 1; let cumulative_probability = choice.cumulative_probability - 1;
let next_char = LitChar::new(choice.next_char, Span::call_site().into()); let next_char = LitChar::new(choice.next_char, Span::call_site().into());
inner_match_arms = quote!( inner_match_arms = quote!(
@ -50,17 +54,38 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
}, },
); );
} }
let variant_count = input.len() as u32;
quote!( quote!(
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
enum StateMachine { pub enum StateMachine {
#variants #variants
} }
impl StateMachine { impl StateMachine {
fn generate(self, mut rng: impl ::rand_core::RngCore) -> (Self, char) { pub fn generate(self, mut rng: impl ::rand_core::RngCore) -> (Self, char) {
match self { match self {
#match_arms #match_arms
} }
} }
pub fn new_random(mut rng: impl ::rand_core::RngCore) -> (Self, &'static str) {
match rng.next_u32() % #variant_count {
#random_selection_match_arms
_ => unreachable!()
} }
).into() }
}
)
.into()
}
fn to_ident(name: &str) -> Ident {
Ident::new(
&name
.replace(' ', " space ")
.replace(';', " semicolon ") // Sanitize ident-unsafe characters
.replace('!', " exclamation ")
.replace(',', " comma ")
.replace('.', " period ") // I'm not calling it a full stop
.to_case(Case::Pascal),
Span::call_site().into(),
)
} }