Configurations of White and Black Knights on a 3x3 chessboard
Description:
Overview
In this kata you will be working on a 3x3 chessboard. In each test case you will be given:
- A starting 3x3 board configuration with some White and Black Knights on the 3x3 board.
- An ending 3x3 board configuration with some White and Black Knights.
Your goal is to determine if you can reach the end board configuration from the start board configuration.
This is a simple puzzle version of Knight movement, so some rules are different compared to real chess:
Firstly, you may not capture pieces - so for example a White knight can not move to a square that's occupied by a Black knight and "remove" the piece. Therefore no pieces will be removed during each game.
Secondly, you may only move one Knight at a time, but - unlike in real chess - you may choose to move any number of White pieces without "swapping color" to Black, and vice versa for Black pieces. In other words, you can move 1,2,3,4,... White knights around the board before you move a single Black piece etc.
Finally, just like in standard chess moves, a Knight can move 2 horizontal and 1 vertical position, or 1 horizontal and 2 vertical positions.
Inputs
You will be given 2 lists
(Python), 1 list
called start_board
representing the 3x3 state in the starting configuration, and 1 list
called end_board
representing the ending configuration.
Each such list
contains 3 lists
, each of which consists of 3 strings
, to represent an entire 1x3 row of the chessboard.
3x3 board layout:
[ [top_left_square, top_middle_square, top_right_square],
[middle_left_square, middle_middle_square, middle_right_square],
[bottom_left_square, bottom_middle_square, bottom_right_square] ]
If a White Knight is on a given square, the corresponding location in the board will have an 'W'
string, if a Black Knight is on a square the location will have a 'B'
string. If a square is empty there will be a '_'
string.
Example input list:
start_board = [ ['B' , '_', '_' ], [ '_', '_', 'W'] , [ 'W', '_', '_'] ]
The above example represents a starting configuration where there is a Black Knight in the top_left_square, a White Knight in the middle_right_square, and a White Knight in the bottom_left_square.
Outputs
Return True
if it is possible to reach the given end_board
from the given start_board
using the legal moves.
Return False
if it is not possible.
Examples
Example 1
start_board = [ ['W' , '_', '_' ], [ '_', '_', '_'] , [ '_', '_', '_'] ]
end_board = [ ['W' , '_', '_' ], [ '_', '_', '_'] , [ '_', '_', '_'] ]
Expected solution is True
; there is only one White Knight and it doesn't need to move between start and end configuration.
Example 2
start_board = [ ['W' , '_', '_' ], [ '_', '_', '_'] , [ '_', '_', '_'] ]
end_board = [ ['_' , '_', '_' ], [ '_', '_', '_'] , [ '_', 'W', '_'] ]
Expected solution is True
; there is only one White Knight and it can reach the end configuration from the start configuration (in fact, it only requires one move to get there).
Example 3
start_board = [ ['W' , '_', '_' ], [ '_', '_', '_'] , [ '_', '_', '_'] ]
end_board = [ ['B' , '_', '_' ], [ '_', '_', '_'] , [ '_', '_', '_'] ]
Expected solution is False
; the start configuration has only one White Knight and the end configuration has only one Black Knight.
Example 4
start_board = [ ['_' , 'B', '_' ], [ '_', '_', '_'] , [ '_', '_', 'W'] ]
end_board = [ ['_' , '_', '_' ], [ 'W', '_', 'B'] , [ '_', '_', '_'] ]
Expected solution is True
; there is one White Knight and one Black Knight. It takes a minimum total of 1W+2B = 3 moves to get all the pieces from the start configuration to the end configuration.
Similar Kata:
Stats:
Created | Apr 29, 2022 |
Published | Apr 29, 2022 |
Warriors Trained | 241 |
Total Skips | 10 |
Total Code Submissions | 573 |
Total Times Completed | 42 |
Python Completions | 42 |
Total Stars | 10 |
% of votes with a positive feedback rating | 100% of 15 |
Total "Very Satisfied" Votes | 15 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |