r/dailyprogrammer • u/Godspiral 3 3 • Nov 18 '15
[2015-11-18] Challenge # 241 [intermediate] ascii Bitmap Chess
1. unicode sucks
From Monday's challenge,
toascii '1r3rk1/1pnnq1bR/p1pp2B1/P2P1p2/1PP1pP2/2B3P1/5PK1/2Q4R'
.r...rk.
.pnnq.bR
p.pp..B.
P..P.p..
.PP.pP..
..B...P.
.....PK.
..Q....Rmake something like this:
┌─┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│8│ │X...X│ │.....│ │X...X│ X │.....│
│ │ │XXXXX│ │.....│ │XXXXX│XXXXX│.....│
│ │ │.XXX.│ │.....│ │.XXX.│ XXX │.....│
│ │ │.XXX.│ │.....│ │.XXX.│XXXXX│.....│
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│7│.....│ │.XXX.│ XXX │X.X.X│ │..X..│O O│
│ │.....│ X │XXXX.│XXXX │XXXXX│ │.XXX.│OOOOO│
│ │.....│ X │..X..│ X │.XXX.│ │..X..│ OOO │
│ │.....│ XXX │XXXX.│XXXX │X...X│ │..X..│ OOO │
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│6│ │.....│ │.....│ │.....│ O │.....│
│ │ X │.....│ X │..X..│ │.....│ OOO │.....│
│ │ X │.....│ X │..X..│ │.....│ O │.....│
│ │ XXX │.....│ XXX │.XXX.│ │.....│ O │.....│
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│5│.....│ │.....│ │.....│ │.....│ │
│ │..O..│ │.....│ O │.....│ X │.....│ │
│ │..O..│ │.....│ O │.....│ X │.....│ │
│ │.OOO.│ │.....│ OOO │.....│ XXX │.....│ │
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│4│ │.....│ │.....│ │.....│ │.....│
│ │ │..O..│ O │.....│ X │..O..│ │.....│
│ │ │..O..│ O │.....│ X │..O..│ │.....│
│ │ │.OOO.│ OOO │.....│ XXX │.OOO.│ │.....│
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│3│.....│ │..O..│ │.....│ │.....│ │
│ │.....│ │.OOO.│ │.....│ │..O..│ │
│ │.....│ │..O..│ │.....│ │..O..│ │
│ │.....│ │..O..│ │.....│ │.OOO.│ │
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│2│ │.....│ │.....│ │.....│ O │.....│
│ │ │.....│ │.....│ │..O..│OOOOO│.....│
│ │ │.....│ │.....│ │..O..│ OOO │.....│
│ │ │.....│ │.....│ │.OOO.│OOOOO│.....│
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│1│.....│ │O.O.O│ │.....│ │.....│O O│
│ │.....│ │OOOOO│ │.....│ │.....│OOOOO│
│ │.....│ │.OOO.│ │.....│ │.....│ OOO │
│ │.....│ │O...O│ │.....│ │.....│ OOO │
├─┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ │a │b │c │d │e │f │g │h │
└─┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘Here are some 4x5 crappy bitmaps to get started
O...O
OOOOO
.OOO.
.OOO.
;
.OOO.
OOOO.
..O..
OOOO.
;
..O..
.OOO.
..O..
..O..
;
O.O.O
OOOOO
.OOO.
O...O
;
..O..
OOOOO
.OOO.
OOOOO
;
.....
..O..
..O..
.OOO.
;
.....
..O..
.O.O.
.....the last one is that ghost square from Monday's challenge. Bitmaps differences for Starting, Regular, and Ghost Rooks is encouraged, as is code generating as much as possible of the variations.
2. Is the black king in check
The black king (k) is in a check position if
- He pretends he is a bishop(b), and can capture a B or Q(ueen)
- He pretends he is a rook(r), and can capture a R or Q(ueen)
- He pretends he is a knight(n), and can capture a N
- He pretends he is a pawn(p), and can capture a P
(note that pieces are blocked by other friend and foe pieces from "checking" the king)
For output, list all squares that have a piece that is holding the black king in check.
** sample input **
1r3rk1/1pnnq1bR/p1pp2B1/P2P1p2/1PP1pP2/2B3P1/5PK1/2Q4R
** sample output **
empty - no checks.
** challenge input **
'1r3kR1/4P3/6NB/8/8/Q7/8/4KR2'
2
u/Godspiral 3 3 Nov 18 '15 edited Nov 19 '15
the check challenge in J
all the code here:
https://github.com/Pascal-J/Jchess/blob/master/chess.ijs
indexes are 0 based with 0 0 at a8
just the rook check, Rmax returns the maximum indexes in each "rook" direction from the piece. Query those squares to see if it holds a rook or queen.
2 rooks can capture the king
both rooks can capture the same king.
Rooks and bishops,
others are easier
full list,
11
u/lukz 2 0 Nov 18 '15
Z80 assembly
For Monday challenge I used the built-in characters of an 8-bit computer, which is like using an existing font on a desktop system. Because today's challenge is about bitmaps I want to design some bitmaps for the 8-bit computer.
I have spent some time designing my 8x7 bitmaps in Windows Paint and then converted them to hex codes. The Sharp MZ-800 computer has a programmable character generator. It means you can redefine the bitmaps that it uses in text mode. My program works in the following way. First, you should clear the screen and type in the chess pieces into the top left 8x8 character positions using letters RNBKQPrnbkqp. Then, you run the program. The program will first redefine the characters that belong to letters BNKPQR and then it will analyze the 8x8 character positions and set the correct colour according to letter case. Program length is 108 bytes.
Here is a screenshot of the input and the corresponding output.
Code:
1
u/Godspiral 3 3 Nov 18 '15 edited Nov 18 '15
in J,
Monday's 8th move position, with ghost pawn and starting rook variations.
challenge check position,
5
u/13467 1 1 Nov 18 '15
A simple ANSI C solution. Example output.
4
u/cheers- Nov 18 '15 edited Nov 19 '15
Java
EDIT: I've added few things for the ASCIIart and I've added challenge 2
It uses regex to verify if black King is in check.
Output: Imgur Link
2
u/FelixMaxwell 1 0 Nov 18 '15
C++
This is a solution for both part 1 and part 2. It prints the board, then whether the king is in check. It takes as input the board as a first line followed by a number of 9 line sets defining the pieces like so:
I used /u/13467 's pieces as I rather liked the look of them. The solution ended up being quite long; you can find it here.
Challenge Output:
2
u/BlueFireAt Nov 20 '15
It's strange that this is so much easier than the House of Ascii [Easy] Challenge.
Java: pastebin, due to large code
Feedback welcome. In particular, making printBoard and fillEmpties smaller. Determining if the King's in check hasn't been done, but I'm thinking about it.
1
u/Mr_Tensor Nov 23 '15 edited Nov 24 '15
My solution to part one in python: