Introduction
Aron Nimzowitsch was a leading chess master and a influential chess writer.
In his book 'My System', the first chapter deals about the importance of the center and why you should dominate it. The simple reason is that your pieces have more possible direct next moves when being in the center which again gives the player more power.
This gets very clear when looking at different positions of a knight and its potential next moves (shown in pink) on an empty board:
Objective
Evaluate the number of potential direct next moves of a knight on an empty board based on its position.
Input Specs
The position of the knight.
First the x (column) and then the y (row). 0 0
is the left bottom corner.
For simplicity, I changed the labels of a chess board to numbers only. For our examples and test cases we use a 0-based index, you are free to use a 1-based index though.
You can use any type of possible input formats, an array, function arguments, etc.
Output Specs
The number of potential direct next moves for a knight on an empty board.
Test Cases
3 4 => 8
4 6 => 6
7 7 => 2
1 0 => 3
Test cases are employing a 0-based index. The full grid of values is:
2 3 4 4 4 4 3 2
3 4 6 6 6 6 4 3
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
3 4 6 6 6 6 4 3
2 3 4 4 4 4 3 2