Pawn Move Validator

Problem #76

Tags: games implementation c-1 c-0

Who solved this?

No translations... yet

Recently I've been interviewed for some job position. To my surprise I was asked to sit at the computer and modify an existing program. The program performs tracking for chess game - i.e. moving pieces on the board according to given list of moves and printing out the resultant position.

I was required to add functionality to check the correctness of pawn moves and rotation of sides between moves (i.e. that none of players make two moves at once).

Those who are acquainted with Java (and have some idea of using JUnit, maven and github can amuse themselves with the full version of this task, as it was proposed to me (I only made some minor changes and translation).

For others here is the adaptation of the task.


Problem Statement

You are to track the sequence of moves in Chess game and check the validity of the pawn moves (other moves are considered correct). As an answer print the number of the incorrect move.

The game is each time started from the initial position:

  +-----------------+
8 | r n b q k b n r |
7 | p p p p p p p p |
6 | - - - - - - - - |
5 | - - - - - - - - |
4 | - - - - - - - - |
3 | - - - - - - - - |
2 | P P P P P P P P |
1 | R N B Q K B N R |
  +-----------------+
    a b c d e f g h

As you see we denote:

The move of a piece is described by its starting and ending coordinate, for example:

After these four moves the position will look like following:

  +-----------------+
8 | r n b q k b - r |
7 | p p p p p p p p |
6 | - - - - - - - - |
5 | - - - - - - - n |
4 | - - - - P - - - |
3 | - - - - - - - - |
2 | P P P P - P P P |
1 | R N B - K B N R |
  +-----------------+
    a b c d e f g h

Pawn move rules

You should check the moves of pawns according to following set of rules:

We do not regard or check the three special cases: the capture "en passant", the promotion of the pawn to other piece at the last row, the move which opens attack on the king or does not remove an existing one (it is illegal).


Input data will contain the number of testcases in the first line.
Next lines will contain one testcase - i.e. one sequence of moves to be checked - each. Of course each sequence should be started from initial position.
Answer should for each sequence tell the number of first incorrect move (starting from 1) or 0 if the whole sequence is valid. Separate answers for different test-cases with spaces.

Example:

input data:
3
b2b3 b8c6 c2c4 c7c5
e2e4 g8f6 d1h5 f6h5
d2d4 e7e5 g1f3 e5d4 c2d4 d8e7

answer:
4 0 5
You need to login to get test data and submit solution.