How to resolve the algorithm Generate Chess960 starting position step by step in the PARI/GP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Generate Chess960 starting position step by step in the PARI/GP 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 PARI/GP programming language
Source code in the pari/gp programming language
chess960() =
{
my (C = vector(8), i, j, r);
C[random(4) * 2 + 1] = C[random(4) * 2 + 2] = "B";
for (i = 1, 3, while (C[r = random(8) + 1],); C[r] = Vec("NNQ")[i]);
for (i = 1, 8, if (!C[i], C[i] = Vec("RKR")[j++]));
C
}
You may also check:How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Maple programming language
You may also check:How to resolve the algorithm Operator precedence step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Wordiff step by step in the Wren programming language
You may also check:How to resolve the algorithm Currying step by step in the Go programming language
You may also check:How to resolve the algorithm Naming conventions step by step in the Fortran programming language