20
1
Goal
You're playing a computerised chess game. The display is in black and white only and the pixels are chunky. White pixels use a lot power compared to black pixels and you're concerned about your carbon footprint.
Given a square and a piece in chess notation, return the number of white pixels displayed in the square.
The solution may be in the form of a function or a complete program.
Input
A 4-character string defining:
- One of
wb
for a white or black piece. (Not part of normal Chess notation, but required for this puzzle.) - One of
KQBNRP
for a King, Queen, Bishop, kNight, Rook or Pawn. - One of
abcdefgh
for the piece's file (column). - One of
12345678
for the piece's rank (row).
Output
The number of white pixels used to draw the chess piece and the underlying square.
Requirements
- Chess squares are 8x8 pixels and are either all white or all black.
a1
is a black square.- White chess pieces are drawn as white with a black outline. Black pieces are black with a white outline. All pieces have transparent pixels which show the underlying square.
- Input is case-sensitive.
- Assume the input is valid.
The chess pieces have sprites as follows.
.
is the piece's colour.
#
is the inverse of the piece's colour.
/
is the underlying square's colour.
King Queen Bishop
//////// //////// ////////
///#.#// /#.#.#.# ///#.#//
//#...#/ //#...#/ //##..#/
///#.#// ///###// //#.#.#/
///###// //#...#/ ///###//
//#...#/ //#...#/ //#...#/
//#...#/ //#...#/ //#...#/
//#.#.#/ //#.#.#/ //#.#.#/
kNight Rook Pawn
//////// //////// ////////
//////// /#.#.#.# ////////
//#..#// /#.....# ////////
/#....#/ /##...## ///#.#//
///#..#/ //#...#/ //#...#/
//#..#// //#...#/ ///#.#//
//#...#/ //#...#/ //#...#/
//#...#/ //#...#/ //#...#/
The number of pixels in the piece's colour, piece's outline and underlying square for each piece is:
Piece Fill Outline Square
==============================
King 13 16 35
Queen 17 18 29
Bishop 13 18 33
Knight 16 12 36
Rook 23 18 23
Pawn 11 10 43
Test Cases
Input Output
wRa1 23
bRa1 18
wPc2 54
bKg8 51
Scoring
The shortest code in bytes by Christmas Day gets a little something extra in their stocking.