September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,4 +1,4 @@
'''[[wp:Chess960|Chess960]]'''   is a variant of chess created by world champion [[wp:Bobby Fisher|Bobby Fisher]]. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
'''[[wp:Chess960|Chess960]]'''   is a variant of chess created by world champion [[wp:Bobby Fischer|Bobby Fischer]]. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
* as in the standard chess game, all eight white pawns must be placed on the second rank.
* White pieces must stand on the first rank as in the standard game, in random column order but with the two following constraints:

View file

@ -22,5 +22,5 @@ function ch960startPos() {
return rank;
}
// test
// testing (10 times)
for (var x = 1; x <= 10; x++) console.log(ch960startPos().join(" | "));

View file

@ -5,20 +5,24 @@ object Chess960 : Iterable<String> {
if (e.length <= 1) {
val s = b + e
if (s.is_valid()) patterns += s
} else
for (i in 0..e.length - 1)
} else {
for (i in 0 until e.length) {
invoke(b + e[i], e.substring(0, i) + e.substring(i + 1))
}
}
}
private fun String.is_valid(): Boolean {
val k = indexOf('K')
return indexOf('R') < k && k < lastIndexOf('R') &&
indexOf('B') % 2 != lastIndexOf('B') % 2
indexOf('B') % 2 != lastIndexOf('B') % 2
}
private val patterns = sortedSetOf<String>()
init { invoke("", "KQRRNNBB") }
init {
invoke("", "KQRRNNBB")
}
}
fun main(args: Array<String>) {

View file

@ -0,0 +1,9 @@
chess960() =
{
my (C = vector(8), i, j, r);
C[random(4) * 2 + 1] = C[random(4) * 2 + 2] = "B";
for (i = 1, 3, while (C[r = random(8) + 1],); C[r] = Vec("NNQ")[i]);
for (i = 1, 8, if (!C[i], C[i] = Vec("RKR")[j++]));
C
}

View file

@ -0,0 +1,25 @@
sequence solutions = {}
--integer d = new_dict()
for i=1 to factorial(8) do
sequence s = permute(i,"RNBQKBNR")
-- sequence s = permute(rand(factorial(8),"RNBQKBNR")
integer b1 = find('B',s),
b2 = find('B',s,b1+1)
if and_bits(b2-b1,1)=1 then
integer k = find('K',s)
integer r1 = find('R',s)
integer r2 = find('R',s,r1+1)
if r1<k and k<r2 then
if find(s,solutions)=0 then
-- if getd_index(s,d)=0 then
-- setd(s,0,d)
solutions = append(solutions,s)
end if
end if
end if
end for
printf(1,"Found %d solutions\n",{length(solutions)})
for i=1 to 5 do
?solutions[rand(length(solutions))]
end for

View file

@ -14,7 +14,8 @@ Do r1=1 To 6
poss=space(translate('12345678',' ',r1||kk||r2),0)
Call rest
End
End
End
End
say cnt.1 'solutions'
Say time('E')
@ -51,7 +52,7 @@ out:
Do k=1 To 8
ol=ol||pos.k
End
cnt.1+=1
cnt.1=cnt.1+1
If cnt.1<4 |,
cnt.1>957 Then
Say format(cnt.1,3) poss r1 kk r2 ol

View file

@ -0,0 +1,56 @@
(import (scheme base) (scheme write)
(srfi 1) ; list library
(srfi 27)) ; random numbers
(random-source-randomize! default-random-source)
;; Random integer in [start, end)
(define (random-between start end)
(let ((len (- end start 1)))
(if (< len 2)
start
(+ start (random-integer len)))))
;; Random item in list
(define (random-pick lst)
(if (= 1 (length lst))
(car lst)
(list-ref lst (random-integer (length lst)))))
;; Construct a random piece placement for Chess960
(define (random-piece-positions)
(define (free-indices positions) ; return list of empty slot indices
(let loop ((i 0)
(free '()))
(if (= 8 i)
free
(loop (+ 1 i)
(if (string=? "." (vector-ref positions i))
(cons i free)
free)))))
;
(define (place-king+rooks positions)
(let ((king-posn (random-between 1 8)))
(vector-set! positions king-posn "K")
; left-rook is between left-edge and king
(vector-set! positions (random-between 0 king-posn) "R")
; right-rook is between right-edge and king
(vector-set! positions (random-between (+ 1 king-posn) 8) "R")))
;
(define (place-bishops positions)
(let-values (((evens odds) (partition even? (free-indices positions))))
(vector-set! positions (random-pick evens) "B")
(vector-set! positions (random-pick odds) "B")))
;
(let ((positions (make-vector 8 ".")))
(place-king+rooks positions)
(place-bishops positions)
;; place the queen in a random remaining slot
(vector-set! positions (random-pick (free-indices positions)) "Q")
;; place the two knights in the remaining slots
(for-each (lambda (idx) (vector-set! positions idx "N"))
(free-indices positions))
positions))
(display "First rank: ") (display (random-piece-positions)) (newline)

View file

@ -0,0 +1,8 @@
const pieces="KQRrBbNN";
starts:=pieces:Utils.Helpers.permuteW(_).filter(fcn(p){
I:=p.index;
I("B") % 2 != I("b") % 2 and // Bishop constraint.
// King constraint.
((I("r") < I("K") and I("K") < I("R")) or
(I("R") < I("K") and I("K") < I("r")))
}).pump(List,"concat","toUpper"):Utils.Helpers.listUnique(_);

View file

@ -0,0 +1,4 @@
N:=starts.len(); println(N);
glyphs:=Dictionary("K","\u2654", "Q","\u2655", "R","\u2656", "B","\u2657", "N","\u2658");
// pick some random starts and transform BBNRKQRN to glyphs
do(10){ starts[(0).random(N)].apply(glyphs.find).println() }