June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue