6
The challenge
Create a program that mimics a chessboard.
The datails
The chessboard must be surrounded by the labels of each row and column, being the columns labeled from 'a' to 'h' and the rows labeled from '1' to '8'. Also, place the default position for each chess piece (blacks are on the top). Each piece is represented by the first letter of his name:
King = K
Queen = Q
Rook = R
Bishop = B
Knight = N
Pawn = P
Also by his colour
W = White
B = Black
So any given piece is recognized by his name and colour. E.G: NB = Black Knight. Empty squares are represented by a hyphen (-).
The program must show the chess board with the pieces. Then it should ask the user to make a move with the message "Move". The program must read user input by console or equivalent. We don't care if the move is legal or not. The program must reprint the chess board with the piece moved, deleting any piece it was on that square. The move is represented origin square destination square
. E.g:
2c 5d = Moves the piece in square 2c to square 5d
If the program detects there is not piece in the origin square or an invalid input, it must show the message "Invalid move" and ask again for another move. If the program detects the final square is occuped by another piece it must show the message "[Name of the moving piece] x [Name of the captured piece]". Eg:
PB x KW
The program is intended to run in a loop, so after each user input the program will ask again for another move. There is no exit clause for the loop.
Example of a initial chessboard and first user's input and program's output:
- a b c d e f g h -
8 RB NB BB QB KB BB NB RB 8
7 PB PB PB PB PB PB PB PB 7
6 - - - - - - - - 6
5 - - - - - - - - 5
4 - - - - - - - - 4
3 - - - - - - - - 3
2 PW PW PW PW PW PW PW PW 2
1 RW NW BW QW KW BW NW RW 1
- a b c d e f g h -
Move
2a 4a
- a b c d e f g h -
8 RB NB BB QB KB BB NB RB 8
7 PB PB PB PB PB PB PB PB 7
6 - - - - - - - - 6
5 - - - - - - - - 5
4 PW - - - - - - - 4
3 - - - - - - - - 3
2 - PW PW PW PW PW PW PW 2
1 RW NW BW QW KW BW NW RW 1
- a b c d e f g h -
Move
2
I'll just leave this here, not as a submission, but as a reminder of history: http://en.wikipedia.org/wiki/1K_ZX_Chess
– nitro2k01 – 2014-01-14T16:45:21.4402>
My bad. I had a internet problem when posting the question and it seems that the one I finally posted was the first version. I have added info and fixed the numbers in the chessboard. Promotion is impossible. The program only have to move the pieces reading user's input. I'm not sure I get what do you ask in 2. If you need more info, feel free to ask. – Averroes – 2011-12-09T12:28:59.693
1So after checkmate the user has to kill the program with Ctrl-C or equivalent? Meh. Looks like a pretty boring problem anyway if it doesn't have to check legality of moves, to be honest. – Peter Taylor – 2011-12-09T13:11:33.877
1haha No prob :P When doing the question I was thinking checking the moves was adding a extra layer of difficult that people may consider excesive for making a program just for fun. Anyways, if the people wants to do it, I can change the question. – Averroes – 2011-12-09T13:44:49.813