34 lines
664 B
Plaintext
34 lines
664 B
Plaintext
// placeholder knights
|
|
rank = ["♘"] * 8
|
|
|
|
// function to get a random free space from a to b, inclusive
|
|
randFree = function(a, b)
|
|
free = []
|
|
for i in range(a, b)
|
|
if rank[i] == "♘" then free.push i
|
|
end for
|
|
return free[rnd * free.len]
|
|
end function
|
|
|
|
// place the king
|
|
kingIdx = randFree(1, 6)
|
|
rank[kingIdx] = "♔"
|
|
|
|
// place rooks
|
|
rank[randFree(0, kingIdx - 1)] = "♖"
|
|
rank[randFree(kingIdx + 1, 7)] = "♖"
|
|
|
|
// place bishops
|
|
bishIdx = randFree(0, 7)
|
|
rank[bishIdx] = "♗"
|
|
while true
|
|
i = randFree(0, 7)
|
|
if i % 2 != bishIdx % 2 then break
|
|
end while
|
|
rank[i] = "♗"
|
|
|
|
// place queen
|
|
rank[randFree(0, 7)] = "♕"
|
|
|
|
print join(rank, " ")
|