June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,4 +1,4 @@
'''[[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:
'''[[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:
@ -11,5 +11,5 @@ With those constraints there are '''960''' possible starting positions, thus the
;Task:
The purpose of this task is to write a program that can randomly generate any one of the 960 Chess960 initial positions.   You will show the result as the first rank displayed with   [[wp:Chess symbols in Unicode|Chess symbols in Unicode: ♔♕♖♗♘]]   or with the letters   '''K'''ing   '''Q'''ueen   '''R'''ook   '''B'''ishop   k'''N'''ight.
The purpose of this task is to write a program that can randomly generate any one of the 960 Chess960 initial positions. You will show the result as the first rank displayed with [[wp:Chess symbols in Unicode|Chess symbols in Unicode: ♔♕♖♗♘]] or with the letters '''K'''ing '''Q'''ueen '''R'''ook '''B'''ishop k'''N'''ight.
<br><br>

View file

@ -0,0 +1,104 @@
/*Abhishek Ghosh, 10th October 2017*/
#include<stdlib.h>
#include<locale.h>
#include<wchar.h>
#include<stdio.h>
#include<time.h>
char rank[9];
int pos[8];
void swap(int i,int j){
int temp = pos[i];
pos[i] = pos[j];
pos[j] = temp;
}
void generateFirstRank(){
int kPos,qPos,bPos1,bPos2,rPos1,rPos2,nPos1,nPos2,i;
for(i=0;i<8;i++){
rank[i] = 'e';
pos[i] = i;
}
do{
kPos = rand()%8;
rPos1 = rand()%8;
rPos2 = rand()%8;
}while((rPos1-kPos<=0 && rPos2-kPos<=0)||(rPos1-kPos>=0 && rPos2-kPos>=0)||(rPos1==rPos2 || kPos==rPos1 || kPos==rPos2));
rank[pos[rPos1]] = 'R';
rank[pos[kPos]] = 'K';
rank[pos[rPos2]] = 'R';
swap(rPos1,7);
swap(rPos2,6);
swap(kPos,5);
do{
bPos1 = rand()%5;
bPos2 = rand()%5;
}while(((pos[bPos1]-pos[bPos2])%2==0)||(bPos1==bPos2));
rank[pos[bPos1]] = 'B';
rank[pos[bPos2]] = 'B';
swap(bPos1,4);
swap(bPos2,3);
do{
qPos = rand()%3;
nPos1 = rand()%3;
}while(qPos==nPos1);
rank[pos[qPos]] = 'Q';
rank[pos[nPos1]] = 'N';
for(i=0;i<8;i++)
if(rank[i]=='e'){
rank[i] = 'N';
break;
}
}
void printRank(){
int i;
#ifdef _WIN32
printf("%s\n",rank);
#else
{
setlocale(LC_ALL,"");
printf("\n");
for(i=0;i<8;i++){
if(rank[i]=='K')
printf("%lc",(wint_t)9812);
else if(rank[i]=='Q')
printf("%lc",(wint_t)9813);
else if(rank[i]=='R')
printf("%lc",(wint_t)9814);
else if(rank[i]=='B')
printf("%lc",(wint_t)9815);
if(rank[i]=='N')
printf("%lc",(wint_t)9816);
}
}
#endif
}
int main()
{
int i;
srand((unsigned)time(NULL));
for(i=0;i<9;i++){
generateFirstRank();
printRank();
}
return 0;
}

View file

@ -1,30 +1,30 @@
# placeholder knights
rank1 = ['♘', '♘', '♘', '♘', '♘', '♘', '♘', '♘']
function generateposition()
# Placeholder knights
rank = ['♘', '♘', '♘', '♘', '♘', '♘', '♘', '♘']
lrank = length(rank)
# function to check if a space is available
isfree(x::Int) = rank1[x] == '♘'
# Check if a space is available
isfree(x::Int) = rank[x] == '♘'
# place king
king = rand(2:7)
rank1[king] = '♔'
# Place the King
rank[indking = rand(2:lrank-1)] = '♔'
# place rooks
rook1 = rand(filter(isfree, 1:8))
rank1[rook1] = '♖'
# Place rooks
rank[indrook = rand(filter(isfree, 1:lrank))] = '♖'
if indrook > indking
rank[rand(filter(isfree, 1:indking-1))] = '♖'
else
rank[rand(filter(isfree, indking+1:lrank))] = '♖'
end
if rook1 > king
rank1[rand(filter(x -> isfree(x) && x < king, 1:8))] = '♖'
else
rank1[rand(filter(x -> isfree(x) && x > king, 1:8))] = '♖'
# Place bishops
rank[indbish = rand(filter(isfree, 1:8))] = '♗'
pbish = filter(iseven(indbish) ? isodd : iseven, 1:lrank)
rank[rand(filter(isfree, pbish))] = '♗'
# Place queen
rank[rand(filter(isfree, 1:lrank))] = '♕'
return rank
end
# place bishops
bishop1 = rand(filter(isfree, 1:8))
rank1[bishop1] = '♗'
rank1[rand(filter(x -> isfree(x) && iseven(x) != iseven(bishop1), 1:8))] = '♗'
# place queen
rank1[rand(filter(isfree, 1:8))] = '♕'
# print first rank
println(join(rank1))
@show generateposition()

View file

@ -1,6 +1,4 @@
constant chess960 = eager
.subst(:nth(2), /''/, '')
if / '' [..]* '' /
for < ♛ ♜ ♜ ♜ ♝ ♝ ♞ ♞ >.permutations».join.uniq;
constant chess960 =
< ♛ ♜ ♜ ♜ ♝ ♝ ♞ ♞ >.permutations».join.unique.grep( / '' [..]* '' / )».subst(:nth(2), /''/, '');
.say for chess960;

View file

@ -1,4 +1,4 @@
constant chess960 = eager gather for 0..3 -> $q {
constant chess960 = gather for 0..3 -> $q {
(my @q = <♜ ♚ ♜>).splice($q, 0, '');
for 0 .. @q -> $n1 {
(my @n1 = @q).splice($n1, 0, '');

View file

@ -29,9 +29,7 @@ fn main() {
let mut chess960 = Chess960(BTreeSet::new());
chess960.invoke("", "KQRRNNBB");
let mut i = 0;
for p in chess960.0 {
for (i, p) in chess960.0.iter().enumerate() {
println!("{}: {}", i, p);
i += 1;
}
}

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)
}
}