How to resolve the algorithm Generate Chess960 starting position step by step in the APL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Generate Chess960 starting position step by step in the APL programming language
Table of Contents
Problem Statement
Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
With those constraints there are 960 possible starting positions, thus the name of the variant.
The purpose of this task is to write a program that can randomly generate any one of the 960 Chess960 initial positions. You will show the result as the first rank displayed using either the chess symbols in Unicode (♔♕♖♗♘), the letters King Queen Rook Bishop kNight, or the corresponding letters in a language other than English.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Generate Chess960 starting position step by step in the APL programming language
Source code in the apl programming language
⍝ Utility functions
divmod ← {(⌊⍺÷⍵),⍵|⍺}
indices ← {(⍺∊⍵)/⍳⍴⍺}
∇result ← place placement; array; index; piece; result
(array piece index) ← placement
array[(array indices '-')[index]] ← piece
result ← array
∇
∇result ← chess960 spid; array; n; b1; b2; n1; n2; q
spid ← 960 | spid
array ← 8/'-'
(n b1) ← spid divmod 4
array[2+2×b1] ← 'B'
(n b2) ← n divmod 4
array[1+2×b2] ← 'B'
(n q) ← n divmod 6
array ← place array 'Q' (1+q)
n1 ← 1⍳⍨n<4 7 9 10
array ← place array 'N' n1
n2 ← (1 2 3 4 2 3 4 3 4 4)[n+1]
array ← place array 'N' n2
array ← place array 'R' 1
array ← place array 'K' 1
array ← place array 'R' 1
result ← spid, array
∇
You may also check:How to resolve the algorithm Four bit adder step by step in the Swift programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Classes step by step in the Perl programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the Golfscript programming language
You may also check:How to resolve the algorithm Send an unknown method call step by step in the FreeBASIC programming language