### ----------------------------------------------------
### -- Chess
### -- Licenses: Artistic-2.0
### -- Authors: Lucien Grondin
### -- File: lib/Chess/Position.rakumod
### ----------------------------------------------------
### -- Chunk 3 of 3
 * $rank + $file;
	$piece +^= RandomPiece[$offset-piece];
    }

    if kingside  ∈ %!castling-rights{white} { $castle +^= RandomCastle[0] }
    if queenside ∈ %!castling-rights{white} { $castle +^= RandomCastle[1] }
    if kingside  ∈ %!castling-rights{black} { $castle +^= RandomCastle[2] }
    if queenside ∈ %!castling-rights{black} { $castle +^= RandomCastle[3] }

    if $!en-passant.defined {
	my &up-or-down = $!turn == white ?? *+16 !! *-16;
	my @left-or-right;
	given file($!en-passant) {
	    when 0 { @left-or-right = *+1 }
	    when 7 { @left-or-right = *-1 }
	    default  { @left-or-right = *-1, *+1 }
	}
	for @left-or-right X∘ &up-or-down -> &direction {
	    if my $left-or-right = self{&direction($!en-passant)} {
		if $left-or-right ~~ pawn and $left-or-right ≡ $!turn {
		    $en-passant +^= RandomEnPassant[file($!en-passant)];
		    last;
		}
	    }
	}
    }

    if $!turn == white { $turn +^= RandomTurn[0] }

    return my uint64 $ = $piece +^ $castle +^ $en-passant +^ $turn;
}


# vi: shiftwidth=4 nu nowrap


