6 kyu

Pawn Promotion

257 of 272Eyad Hantouli

Description:

Welcome To Pawn Promotion Kata.

In this kata you will write a program that studies a chess board that contains only two pieces (pawn) and (king).

The pawn is always in the last row as it will now turn into one of the four pieces [queen , rook , bishop , knight] in a process called {pawn promotion}.

Your task is to locate the king and the pawn and choose the appropriate piece to promote it and put the king in check.

The letter P represents the pawn

The letter K represents the king

Examples:

input:
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
['P', ' ', ' ', 'K', ' ', ' ', ' ', ' '],

output:
['queen', 'rook']
input:
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', 'K', ' '],
[' ', ' ', ' ', ' ', 'P', ' ', ' ', ' '],

output:
['knight']
input:
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', 'K', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', 'P', ' ', ' ', ' ', ' ', ' '],

output:
[]

Q&A:

Q:- Why was the order of the pieces in the first example as ['queen', 'rook']
and not the other way around ?
A:- In the event that there is more than one option that achieves check,
return the order of the pieces as follows [queen, rook, bishop, knight]

special cases:

  • If there is no piece that can make check immediately upon upgrade, return [].

  • If there is no pawn on the board, return [].

  • If there is no king on the board, return [].

Fundamentals

More By Author:

Check out these other kata created by Eyad Hantouli

Stats:

CreatedApr 24, 2022
PublishedApr 24, 2022
Warriors Trained652
Total Skips8
Total Code Submissions1649
Total Times Completed272
Python Completions257
COBOL Completions5
C Completions20
Total Stars28
% of votes with a positive feedback rating93% of 76
Total "Very Satisfied" Votes67
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes2
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Eyad Hantouli Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
Ad