Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,11 @@
#.#.#.#.065*0#v_1-\>>?1v
v,":".:%*8"x"$<^!:\*2<+<
>48*,:4%2*1#v+#02#\3#g<<
v"B"*2%4:/4p<vg0:+1<\-1<
>\0p4/:6%0:0g>68*`#^_\:|
v"RKRNN"p11/6$p0\ "Q" \<
>"NRNKRRNNKRNRKNRRNKNR"v
v"NRNKRNRKNRNRKRNRNNKR"<
>"RKRNN"11g:!#v_\$\$\$\v
v _v#!`*86:g0:<^!:-1$\$<
>$\>,1+ :7`#@_^> v960v <

View file

@ -2,68 +2,56 @@
#include <string>
#include <time.h>
using namespace std;
class chess960
namespace
{
void placeRandomly(char* p, char c)
{
int loc = rand() % 8;
if (!p[loc])
p[loc] = c;
else
placeRandomly(p, c); // try again
}
int placeFirst(char* p, char c, int loc = 0)
{
while (p[loc]) ++loc;
p[loc] = c;
return loc;
}
string startPos()
{
char p[8]; memset( p, 0, 8 );
// bishops on opposite color
p[2 * (rand() % 4)] = 'B';
p[2 * (rand() % 4) + 1] = 'B';
// queen knight knight, anywhere
for (char c : "QNN")
placeRandomly(p, c);
// rook king rook, in that order
placeFirst(p, 'R', placeFirst(p, 'K', placeFirst(p, 'R')));
return string(p, 8);
}
} // leave local
namespace chess960
{
public:
void generate( int c )
{
for( int x = 0; x < c; x++ )
cout << startPos() << "\n";
}
private:
string startPos()
{
char p[8]; memset( p, 0, 8 );
int b1, b2; bool q;
// bishops
while( 1 )
{
b1 = rand() % 8; b2 = rand() % 8;
if( !( b1 & 1 ) && b2 & 1 ) break;
}
p[b1] = 'B'; p[b2] = 'B';
// queen, knight, knight
q = false;
for( int x = 0; x < 3; x++ )
{
do
{ b1 = rand() % 8; }
while( p[b1] );
if( !q )
{ p[b1] = 'Q'; q = true; }
else p[b1] = 'N';
}
// rook king rook
q = false;
for( int x = 0; x < 3; x++ )
{
int a = 0;
for( ; a < 8; a++ )
if( !p[a] ) break;
if( !q )
{ p[a] = 'R'; q = true; }
else
{ p[a] = 'K'; q = false; }
}
string s;
for( int x = 0; x < 8; x++ )
s.append( 1, p[x] );
return s;
}
};
}
int main( int argc, char* argv[] )
{
srand( time( NULL ) );
chess960 c;
c.generate( 10 );
chess960::generate( 10 );
cout << "\n\n";
return system( "pause" );
}

View file

@ -0,0 +1,30 @@
# placeholder knights
rank1 = ['♘', '♘', '♘', '♘', '♘', '♘', '♘', '♘']
# function to check if a space is available
isfree(x::Int) = rank1[x] == '♘'
# place king
king = rand(2:7)
rank1[king] = '♔'
# place rooks
rook1 = rand(filter(isfree, 1:8))
rank1[rook1] = '♖'
if rook1 > king
rank1[rand(filter(x -> isfree(x) && x < king, 1:8))] = '♖'
else
rank1[rand(filter(x -> isfree(x) && x > king, 1:8))] = '♖'
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))

View file

@ -0,0 +1,9 @@
Print[StringJoin[
RandomChoice[
Select[Union[
Permutations[{"\[WhiteKing]", "\[WhiteQueen]", "\[WhiteRook]",
"\[WhiteRook]", "\[WhiteBishop]", "\[WhiteBishop]",
"\[WhiteKnight]", "\[WhiteKnight]"}]],
MatchQ[#, {___, "\[WhiteRook]", ___, "\[WhiteKing]", ___,
"\[WhiteRook]", ___}] &&
OddQ[Subtract @@ Flatten[Position[#, "\[WhiteBishop]"]]] &]]]];

View file

@ -1,6 +1,7 @@
constant chess960 =
map *.subst(:nth(2), /''/, ''),
grep rx/ '' [..]* '' /,
< ♛ ♜ ♜ ♜ ♝ ♝ ♞ ♞ >.pick(*).join xx *;
sub chess960 {
.subst(:nth(2), /''/, '') given
first rx/ '' [..]* '' /,
< ♛ ♜ ♜ ♜ ♝ ♝ ♞ ♞ >.pick(*).join xx *;
}
.say for chess960[^10];
say chess960;

View file

@ -1,15 +1,13 @@
sub insert(@a,$p,$e) { @a[^$p], $e, @a[$p..*] }
constant chess960 = eager gather for 0..3 -> $q {
my @q = insert <♜ ♚ ♜>, $q, '';
(my @q = <♜ ♚ ♜>).splice($q, 0, '');
for 0 .. @q -> $n1 {
my @n1 = insert @q, $n1, '';
(my @n1 = @q).splice($n1, 0, '');
for $n1 ^.. @n1 -> $n2 {
my @n2 = insert @n1, $n2, '';
(my @n2 = @n1).splice($n2, 0, '');
for 0 .. @n2 -> $b1 {
my @b1 = insert @n2, $b1, '';
(my @b1 = @n2).splice($b1, 0, '');
for $b1+1, $b1+3 ...^ * > @b1 -> $b2 {
my @b2 = insert @b1, $b2, '';
(my @b2 = @b1).splice($b2, 0, '');
take @b2.join;
}
}

View file

@ -1,26 +1,26 @@
/*REXX pgm generates a random starting position for the Chess960 game.*/
parse arg seed . /*allow for (RAND) repeatability.*/
if seed\=='' then call random ,,seed /*if SEED specified, use the seed*/
@.=. /*define the (empty) first rank. */
r1=random(1,8) /*generate the first rook, rank 1*/
@.r1='R' /*place the first rook on rank1.*/
/*REXX program generates a random starting position for the Chess960 game. */
parse arg seed . /*allow for (RANDOM BIF) repeatability.*/
if seed\=='' then call random ,,seed /*if SEED was specified, use the seed.*/
@.=. /*define the first rank as being empty.*/
r1=random(1,6) /*generate the first rook: rank 1. */
@.r1='R' /*place the first rook on rank1. */
do until r2\==r1 & r2\==r1-1 & r2\==r1+1
r2=random(1,8) /*find placement for the 2nd rook*/
r2=random(1,8) /*find placement for the 2nd rook. */
end /*forever*/
@.r2='r' /*place the second rook on rank 1*/
_=random(min(r1, r2)+1, max(r1, r2)-1) /*find a random possition of king*/
@._='K' /*place king between the 2 rooks.*/
do _=0 ; b1=random(1,8); if @.b1\==. then iterate; c=b1//2
do forever; b2=random(1,8) /* c=color of bishop ►──────*/
if @.b2\==. | b2==b1 | b2//2==c then iterate /*bad position*/
@.r2='r' /*place the second rook on rank 1. */
k=random(min(r1, r2)+1, max(r1, r2)-1) /*find a random position for the king. */
@.k='K' /*place king between the two rooks. */
do _=0 ; b1=random(1,8); if @.b1\==. then iterate; c=b1//2
do forever; b2=random(1,8) /* c=color of bishop ►── */
if @.b2\==. | b2==b1 | b2//2==c then iterate /*is a bad position?*/
leave _ /*found position for the 2 clergy*/
end /*forever*/ /* [↑] find a place: 1st bishop.*/
end /* _ */ /* [↑] " " " 2nd " */
@.b1='B' /*place the 1st bishop on rank1*/
@.b2='b' /* " " 2nd " " " */
/*place the two knights on rank 1*/
do until @._='N'; _=random(1,8); if @._\==. then iterate; @._='N'; end
do until @.!='n'; !=random(1,8); if @.!\==. then iterate; @.!='n'; end
_= /*only the queen is left to place*/
do i=1 for 8; _=_ || @.i; end /*construct output: first rank. */
say translate(translate(_, 'q', .)) /*stick a fork in it, we're done.*/
end /*forever*/ /* [↑] find a place for the 1st bishop*/
end /* _ */ /* [↑] " " " " " 2nd " */
@.b1='B' /*place the 1st bishop on rank 1. */
@.b2='b' /* " " 2nd " " " " */
/*place the two knights on rank 1. */
do until @._='N'; _=random(1,8); if @._\==. then iterate; @._='N'; end
do until @.!='n'; !=random(1,8); if @.!\==. then iterate; @.!='n'; end
_= /*only the queen is left to be placed. */
do i=1 for 8; _=_ || @.i; end /*construct the output: first rank only*/
say translate(translate(_, 'q', .)) /*stick a fork in it, we're all done. */

View file

@ -1,38 +1,38 @@
/*REXX pgm generates all random starting positions for the Chess960 game*/
parse arg seed . /*allow for (RAND) repeatability.*/
if seed\=='' then call random ,,seed /*if SEED specified, use the seed*/
x.=0; #=0
do t=1 /*═══════════════════════════════════════════════════════════════*/
if t//1000==0 then say right(t,9) 'random generations: ' # " unique starting positions."
@.=. /*define the (empty) first rank. */
r1=random(1,8) /*generate the first rook, rank 1*/
@.r1='R' /*place the first rook on rank1.*/
do until r2\==r1 & r2\==r1-1 & r2\==r1+1
r2=random(1,8) /*find placement for the 2nd rook*/
end /*forever*/
@.r2='r' /*place the second rook on rank 1*/
_=random(min(r1, r2)+1, max(r1, r2)-1) /*find a random possition of king*/
@._='K' /*place king between the 2 rooks.*/
do _=0 ; b1=random(1,8); if @.b1\==. then iterate; c=b1//2
do forever; b2=random(1,8) /* c=color of bishop ►──────*/
if @.b2\==. | b2==b1 | b2//2==c then iterate /*bad position*/
leave _ /*found position for the 2 clergy*/
end /*forever*/ /* [↑] find a place: 1st bishop.*/
end /* _ */ /* [↑] " " " 2nd " */
@.b1='B' /*place the 1st bishop on rank1*/
@.b2='b' /* " " 2nd " " " */
/*place the two knights on rank 1*/
do until @._='N'; _=random(1,8); if @._\==. then iterate; @._='N'; end
do until @.!='n'; !=random(1,8); if @.!\==. then iterate; @.!='n'; end
_= /*only the queen is left to place*/
do i=1 for 8; _=_ || @.i; end /*construct output: first rank. */
upper _ /*uppercase all the chess pieces.*/
if x._ then iterate /*was this position found before?*/
x._=1 /*define this position as found. */
#=#+1 /*bump the unique positions found*/
if #==960 then leave
end /*t ══════════════════════════════════════════════════════════════*/
/*REXX program generates all random starting positions for the Chess960 game. */
parse arg seed . /*allow for (RANDOM BIF) repeatability.*/
if seed\=='' then call random ,,seed /*if SEED was specified, use the seed.*/
x.=0; #=0; rg='random generations: ' /*initialize game placeholder; # games.*/
/*▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒*/
do t=1 /* [↓] display every 1,000 generations*/ /**/
if t//1000==0 then say right(t,9) rg # " unique starting positions." /**/
@.=. /*define the first rank as being empty.*/ /**/
r1=random(1,6) /*generate the first rook: rank 1. */ /**/
@.r1='R' /*place the first rook on rank1. */ /**/
do until r2\==r1 & r2\==r1-1 & r2\==r1+1 /**/
r2=random(1,8) /*find placement for the 2nd rook. */ /**/
end /*forever*/ /**/
@.r2='r' /*place the second rook on rank 1. */ /**/
k=random(min(r1, r2)+1, max(r1, r2)-1) /*find a random position for the king. */ /**/
@.k='K' /*place king between the two rooks. */ /**/
do _=0 ; b1=random(1,8); if @.b1\==. then iterate; c=b1//2 /**/
do forever; b2=random(1,8) /* c=color of bishop ►── */ /**/
if @.b2\==. | b2==b1 | b2//2==c then iterate /*is a bad position?*/ /**/
leave _ /*found position for the 2 clergy*/ /**/
end /*forever*/ /* [↑] find a place for the 1st bishop*/ /**/
end /* _ */ /* [↑] " " " " " 2nd " */ /**/
@.b1='B' /*place the 1st bishop on rank 1. */ /**/
@.b2='b' /* " " 2nd " " " " */ /**/
/*place the two knights on rank 1. */ /**/
do until @._='N'; _=random(1,8); if @._\==. then iterate; @._='N'; end /**/
do until @.!='n'; !=random(1,8); if @.!\==. then iterate; @.!='n'; end /**/
_= /*only the queen is left to be placed. */ /**/
do i=1 for 8; _=_ || @.i; end /*construct the output: first rank only*/ /**/
upper _ /*uppercase all the chess pieces. */ /**/
if x._ then iterate /*This position found before? Skip it.*/ /**/
x._=1 /*define this position as being found. */ /**/
#=#+1 /*bump the # of unique positions found,*/ /**/
if #==960 then leave /**/
end /*t ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒*/
say # 'unique starting positions found after ' t "generations."
/*stick a fork in it, we're done.*/
/*stick a fork in it, we're all done. */ /**/

View file

@ -0,0 +1,60 @@
/*---------------------------------------------------------------
* Compute the 960 possible solutions
* There must be at least one field between the rooks
* The king is positioned on any field between the rooks
* The queen is placed on any unoccupied field
* bishops are placed so that they are on different colored fields
* what remains are the kNights...
*--------------------------------------------------------------*/
cnt.=0
Call time 'R'
Do r1=1 To 6
Do r2=r1+1 To 8
Do kk=r1+1 To r2-1
poss=space(translate('12345678',' ',r1||kk||r2),0)
Call rest
End
End
End
say cnt.1 'solutions'
Say time('E')
Exit
rest:
Do i=1 To 5
q=substr(poss,i,1)
br=space(translate(poss,' ',q),0)
Do b1i=1 To 3
Do b2i=b1i+1 To 4
Call finish
End
End
End
Return
finish:
b1=substr(br,b1i,1)
b2=substr(br,b2i,1)
If (b1+b2)//2>0 Then
Call out
Return
out:
pos.='N'
pos.r1='R'
pos.r2='R'
pos.kk='K'
pos.q='Q'
pos.b1='B'
pos.b2='B'
ol=''
Do k=1 To 8
ol=ol||pos.k
End
cnt.1+=1
If cnt.1<4 |,
cnt.1>957 Then
Say format(cnt.1,3) poss r1 kk r2 ol
If cnt.1=4 Then
Say ' ...'
Return