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,25 @@
import scala.annotation.tailrec
object Chess960 extends App {
private val pieces = List('♖', '♗', '♘', '♕', '♔', '♘', '♗', '♖')
@tailrec
private def generateFirstRank(pieces: List[Char]): List[Char] = {
def check(rank: String) =
rank.matches(".*♖.*♔.*♖.*") && rank.matches(".*♗(..|....|......|)♗.*")
val p = scala.util.Random.shuffle(pieces)
if (check(p.toString.replaceAll("[^\\p{Upper}]", "")))
generateFirstRank(pieces)
else p
}
loop(10)
@tailrec
private def loop(n: Int): Unit = {
println(generateFirstRank(pieces))
if (n <= 0) () else loop(n - 1)
}
}

View file

@ -0,0 +1,21 @@
object Chess960 extends App {
private def apply(b: String, e: String) {
if (e.length <= 1) {
val s = b + e
if (is_valid(s)) patterns += s
} else
for (i <- 0 until e.length)
apply(b + e(i), e.substring(0, i) + e.substring(i + 1))
}
private def is_valid(s: String) = {
val k = s.indexOf('K')
if (k < s.indexOf('R')) false
else k < s.lastIndexOf('R') && s.indexOf('B') % 2 != s.lastIndexOf('B') % 2
}
private val patterns = scala.collection.mutable.SortedSet[String]()
apply("", "KQRRNNBB")
for ((s, i) <- patterns.zipWithIndex) println(s"$i: $s")
}