Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,35 @@
use std::collections::BTreeSet;
struct Chess960 ( BTreeSet<String> );
impl Chess960 {
fn invoke(&mut self, b: &str, e: &str) {
if e.len() <= 1 {
let s = b.to_string() + e;
if Chess960::is_valid(&s) { self.0.insert(s); }
} else {
for (i, c) in e.char_indices() {
let mut b = b.to_string();
b.push(c);
let mut e = e.to_string();
e.remove(i);
self.invoke(&b, &e);
}
}
}
fn is_valid(s: &str) -> bool {
let k = s.find('K').unwrap();
k > s.find('R').unwrap() && k < s.rfind('R').unwrap() && s.find('B').unwrap() % 2 != s.rfind('B').unwrap() % 2
}
}
// Program entry point.
fn main() {
let mut chess960 = Chess960(BTreeSet::new());
chess960.invoke("", "KQRRNNBB");
for (i, p) in chess960.0.iter().enumerate() {
println!("{}: {}", i, p);
}
}

View file

@ -0,0 +1,41 @@
// Chess960: regex and unicode version, create 5 valid random positions.
use rand::{seq::SliceRandom, thread_rng};
use regex::Regex;
fn vec_to_string(v: Vec<&str>) -> String {
let mut is_string = String::new();
for ele in v {
is_string.push_str(ele)
}
is_string
}
fn is_rook_king_ok(str_to_check: Vec<&str>) -> bool {
Regex::new(r"(.*♖.*♔.*♖.*)")
.unwrap()
.is_match(vec_to_string(str_to_check.clone()).as_str())
}
fn is_two_bishops_ok(str_to_check: Vec<&str>) -> bool {
Regex::new(r"(.*♗.{0}♗.*|.*♗.{2}♗.*|.*♗.{4}♗.*|.*♗.{6}♗.*)")
.unwrap()
.is_match(vec_to_string(str_to_check.clone()).as_str())
}
fn create_rnd_candidate() -> [&'static str; 8] {
let mut rng = thread_rng();
let mut chaine = ["♖", "♘", "♗", "♔", "♕", "♗", "♘", "♖"];
loop {
chaine.shuffle(&mut rng);
if is_candidate_valide(chaine) {
break chaine;
}
}
}
fn is_candidate_valide(s: [&str; 8]) -> bool {
is_rook_king_ok(s.to_vec()) && is_two_bishops_ok(s.to_vec())
}
fn main() {
for _ in 0..5 {
println!("{:?}", create_rnd_candidate());
}
}