Generate random chess position: Difference between revisions

improved function pawn_on_extreme_ranks
(added tag language rsplus)
(improved function pawn_on_extreme_ranks)
Line 1,533:
}
 
pawn_on_promotion_squarepawn_on_extreme_ranks <- function(pc, pr){
###
# Function that checks whether a pawn is on athe promotionfirst squareor eight rank
# (such a situation is not possible in chess)
###
if (pc ==%in% c("P","p") & pr ==%in% c(1,8))
return(TRUE)
else if (pc == "p" & pr == 8)
return(TRUE)
else
Line 1,549 ⟶ 1,547:
###
# Function that puts pieces on the board making sure that they
# are not on the same squares, and verifying for pawn_on_promotion_squarepawn_on_extreme_ranks
###
# initialization
Line 1,567 ⟶ 1,565:
piece_rank <- sample(1:8, 1) ; piece_file <- sample(1:8, 1)
piece <- sample(pieces, 1)
# check if square is empty and it is not a pawn on aan promotionextreme squarerank
if (brd[piece_rank, piece_file] == " " & !pawn_on_promotion_squarepawn_on_extreme_ranks(piece, piece_rank)){
brd[piece_rank, piece_file] <- piece
n_pieces <- n_pieces - 1
Line 1,614 ⟶ 1,612:
{{out}}
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] " " "R " "Rn" " " "n " "nr" " " " "
[2,] "p " " " " " " " " " " B" "k " "b "
[3,] " " " " "B " " " "pk" " p" "N " "r "
[4,] " " " r" "N " "q" " " "q " "nb" "q "
[5,] " " " " " " " r" "bn" " " " r" " "
[6,] " " " " " " " Q" "qb" "nr" " " " K"
[7,] " " " n" " " " " "K " " b" " p" " "
[8,] " " "Q " "q " "R " "P " "b " " " " "
 
1R1n22n2r2/p5kb5B2/2B1p1Nr4kp2/2Nq1qnq1r1q2b1/4b33rn1r1/4qn23Qbr1K/4K31n3bp1/1QqRPb28 w - - 0 1
 
=={{header|Raku}}==