Chess-olition Derby

16

3

What could be more polar opposites than chess and demolition derby. You would think that no one who enjoys one would enjoy the other... until today.

Rules

The starting position is a standard chess board:

RNBQKBNR
PPPPPPPP 





PPPPPPPP 
RNBQKBNR

Looks normal enough, until you find out it's an EVERY PIECE FOR ITSELF, LAST PIECE STANDING competition:

  • On every turn, each piece on the board gets to make one randomly*-selected valid move (using it's standard move rules). However, the order the pieces move in is randomized every turn.
  • A piece can capture ANY PIECE, even if it's the same color as it, even a king.
  • Pawns can capture FORWARD, as well as diagonal. Moreover, like normal, if there is an empty space in front of it, a pawn can move two spaces on its first move (they can also capture that way.) Furthermore, pawns promote to any random piece (including king) other than a pawn.
  • The winner is the last piece standing. However if after 1000 turns, there is more than one piece left, all of the remaining pieces are winners.
  • No En Passants, Checks, Castles, etc.

Output

After every turn output the turn number, and what the board looks like. After a piece is killed it is removed from the board. After the first turn, the board may look like this:

1.
   K    
RBQ N BR  
NP  P P
  PP P P
R PP
BPN PNP
    K  R 
       Q

After 1000 moves the board may look like this:

1000.
  Q  K


P  N R

 R  B N   

  Q

And the game ends.

Or Maybe after 556 turns the board look like this:

556.


     R





So the game ends there.

*Please ensure all randomization done in this challenge is uniform (every possibility has an equal chance of occurring).

geokavel

Posted 2016-01-10T22:05:13.137

Reputation: 6 352

If a pawn can capture without moving diagonally, can it also move diagonally without capturing? – trichoplax – 2016-01-10T22:10:52.670

1@tri no, it cant. – geokavel – 2016-01-10T22:11:29.870

Can a pawn capture two pieces at once when it does a double move? – orlp – 2016-01-10T23:59:36.857

1@orlp No, i should clarify that. You can only move two, if there's an empty space in front of you. – geokavel – 2016-01-11T00:06:05.510

If a piece cannot move when it takes its turn, is it skipped? What about if it's skipped, then a move opens up due to the piece that moved after it? Can it move before the turn is over? – mbomb007 – 2017-01-05T22:52:02.483

1

Also, in your examples, you need to distinguish the pawns as black or white (p black and P white is standard in FEN), because they move different directions.

– mbomb007 – 2017-01-05T22:53:43.660

I think you should use 3 rounds as an example, not just randomized boards. – Magic Octopus Urn – 2017-10-27T19:56:23.597

Answers

3

Python 2, 862 846 844 bytes

from random import*
A=-1;a,b=[(0,1),(0,A),(A,0),(1,0)],[(A,A),(A,1),(1,A),(1,1)]
r=range(8)
C='RNBQK';q=C+'BNR'
def m(x,y,B,t):
 P=B[y][x];M=[]
 for w,z in dict(zip('pP'+C,[[],[],a,zip([A,1,-2,2]*2,[2,2,1,1,-2,-2,A,A]),b]+[a+b]*2))[P]:
	for i in r[1:]:
	 X,Y=x+z*i,y+w*i;M+=(X,Y),
	 if P in'NK'or 1-(8>X>A<Y<8)or' '<B[Y][X]:break
 if P in'pP':d=[A,1][P<'p'];M=zip((x-1,x,x+1)[B[y+d][x-1]<'!':2+(B[y+d][-~x%8]>' ')],(y+d,)*3)+[(x,y+2*d)]*(t*B[y+d][x]<'!')
 return choice([(X,Y)for X,Y in M if-1<X<8>Y>A])
B=map(list,[q,'P'*8]+[' '*8]*4+['p'*8,q])
t=0
while t<1e3:
 t+=1;p=[(x,y)for y in r for x in r if' '<B[y][x]];shuffle(p)
 if len(p)<2:break
 while p:x,y=p.pop();Z=X,Y=m(x,y,B,t<2);B[Y][X],B[y][x]=B[y][x],' ';Z in p and p.remove(Z)
 for j in 0,7:
	for i in r:
	 if B[j][i]in'pP':B[j][i]=choice(C)
 print t
 for l in B:print''.join(l).upper()

Try it online!

Saved 18 bytes thanks to Jonathan Frech

TFeld

Posted 2016-01-10T22:05:13.137

Reputation: 19 246

855 bytes (not fully tested). – Jonathan Frech – 2017-10-27T15:05:42.080

847 bytes. – Jonathan Frech – 2017-10-27T15:17:20.317

I think ...]+[(a+b)]*2 can be either ...]+[a+b]*2 or ...,a+b,a+b]. – Jonathan Frech – 2017-10-27T19:35:13.947

0

PHP, 1849 bytes

<?$z=[R,N,B,Q,K,B,N,R];$y=[_,_,_,_,_,_,_,_];$u=shuffle;$b=[$z,[P,P,P,P,P,P,P,P],$y,$y,$y,$y,[p,p,p,p,p,p,p,p],$z];$z=[R,N,B,Q,K];for($i=0;$i<8;$i++)for($j=0;$j<8;$j++)$r[]=[$i,$j];for(;$c++<=999;){for($i=$_=0;$i<8;$i++)for($j=0;$j<8;$j++)if($b[$i][$j]!=_)++$_;if($_<2)break;$u($r);$n=[];foreach($r as$l){list($y,$x)=$l;$a=$y+1;$d=$y-1;$j=$x+1;$t=$x-1;$p=$b[$y][$x];if($n[$y][$x]!=1&&$p!=_){$v=$e=$f=$g=$h=$k=$o=$q=$s=[];if($p==R||$p==K||$p==Q){$m=($p==K)?2:9;for($i=1;$i<$m;$i++){if(!$e&&$y-$i>=0){$v[]=[$y-$i,$x];if($b[$y-$i][$x]!=_)$e=1;}if(!$f&&$y+$i<8){$v[]=[$y+$i,$x];if($b[$y+$i][$x]!=_)$f=1;}if(!$g&&$x-$i>=0){$v[]=[$y,$x-$i];if($b[$y][$x-$i]!=_)$g=1;}if(!$h&&$x+$i<8){$v[]=[$y,$x+$i];if($b[$y][$x+$i]!=_)$h=1;}}}if($p==B||$p==K||$p==Q){$m=($p==K)?2:9;for($i=1;$i<$m;$i++){if(!$k&&$y-$i>=0&&$x-$i>=0){$v[]=[$y-$i,$x-$i];if($b[$y-$i][$x-$i]!=_)$k=1;}if(!$o&&$y-$i>=0&&$x+$i<8){$v[]=[$y-$i,$x+$i];if($b[$y-$i][$x+$i]!=_)$o=1;}if(!$q&&$y+$i<8&&$x-$i>=0){$v[]=[$y+$i,$x-$i];if($b[$y+$i][$x-$i]!=_)$q=1;}if(!$s&&$y+$i<8&&$x+$i<8){$v[]=[$y+$i,$x+$i];if($b[$y+$i][$x+$i]!=_)$s=1;}}}if($p==N){if($y-2>=0&&$t>=0)$v[]=[$y-2,$t];if($y-2>=0&&$j<8)$v[]=[$y-2,$j];if($d>=0&&$x-2>=0)$v[]=[$d,$x-2];if($d>=0&&$x+2<8)$v[]=[$d,$x+2];if($a<8&&$x-2>=0)$v[]=[$a,$x-2];if($a<8&&$x+2<8)$v[]=[$a,$x+2];if($y+2<8&&$t>=0)$v[]=[$y+2,$t];if($y+2<8&&$j<8)$v[]=[$y+2,$j];}if($p==P){if($y==1&&$b[$a][$x]==_)$v[]=[$y+2,$x];if($j<8&&$b[$a][$j]!=_)$v[]=[$a,$j];if($t>=0&&$b[$a][$t]!=_)$v[]=[$a,$t];$v[]=[$a,$x];}if($p==p){if($y==6&&$b[$d][$x]==_)$v[]=[$y-2,$x];if($j<8&&$b[$d][$j]!=_)$v[]=[$d,$j];if($t>=0&&$b[$d][$t]!=_)$v[]=[$d,$t];$v[]=[$d,$x];}$u($v);$v=$v[0];$b[$y][$x]=_;$w=$p;if($w==P&&$v[0]>6&&$u($z)&&$w=$z[0]);if($w==p&&$v[0]<1&&$u($z)&&$w=$z[0]);$b[$v[0]][$v[1]]=$w;$n[$v[0]][$v[1]]=1;}}echo $c.".
";foreach($b as$a)echo str_replace([_,p],[' ',P],join("",$a))."
";}

Try it online!

It can definitely be golfed more, and it looks somewhat like the workings of a madman (which, I suppose, it may be).

I am impressed at how fast random moves can clear the board (I've seen 15 moves do it). Also, I think the only one I saw hit the 1000 limit was two bishops on different colors dancing.

Jo.

Posted 2016-01-10T22:05:13.137

Reputation: 974