Homework 1 - PGN Reader

Introduction

In this assignment you will practice

You may use File IO, stream scanning (java.util.Scanner) and regular expression classes from the Java standard library, but you may not use any collections classes or write your own classes other than the single class that holds your static methods. You may only use language features we’ve covered through arrays. If you already know some object-oriented programming this restriction may frustrate you. But this restriction will gain confidence with Java control structures and arrays, and you will appreciate data abstraction with classes.

Problem Description

Over the course of this semester you will write a chess game database that will import chess games in PGN format. As a first step you will write code to read PGN games and resolve board positions.

Solution Description

Write a class called PgnReader that contains the following public static methods:

Write a main method that reads the file named in the PgnReader’s first command-line argument into a String and uses that String as the argument to each method above in order to print game information to the console. First, print the tag names and associated values for the core seven tags of the PGN standard: Event, Site, Date, Round, White, Black, Result. Then print a line reading “Final Position:” and a line displaying the final game position in FEN. Note that in this assignment we only care about the piece placement data, not the other elements of FEN such as active color or castling availability.

Each PGN file will contain a single game and you may assume that the PGN files are valid, and the move text contains only moves, no annotation text. Moves may end in check symbols (‘+’) or strength judgements (‘!’, ‘?’).

As your program reads the moves in a game it will need to maintain the state of the board, which you should store in a 2-d array. You will also need to translate between the algebraic notation used to represent moves in PGN, and the internal representation you use for board state, e.g., array indices.

You may use this skeleton file which contains a completed main method and code to read a file and return its content as a String: PgnReader.java. This skeleton file also contains stubbed tagValue and finalPosition methods. A stubbed method is a method that returns a dummy type-correct value (if applicable) so that you can successfully compile code that uses the method. Stubbed methods are useful in incremental program development. You will want to write many helper methods.

Example

Using the fegatello.pgn, a shell session with your program would look like this:

$ java PgnReader fegatello.pgn
Event: Fegatello Attack
Site: NOT GIVEN
Date: NOT GIVEN
Round: NOT GIVEN
White: NOT GIVEN
Black: NOT GIVEN
Result: NOT GIVEN
Final Position:
r1bqkb1r/ppp2Npp/2n5/3np3/2B5/8/PPPP1PPP/RNBQK2R

Domain Knowledge

You don’t need to know how to play chess, you only need to know how the pieces and pawns move and how to record chess moves. Use the following links for this purpose:

And, of course, you need to know the PGN Standard. You only need sections 2.3, 8.1-8.2.3.6, 16.1.3.1 and 16.1.4. PGN is simple, and you can learn it well enough by simply looking at example PGN games.

Tips

Grading

There are 30 bonus points on this assignment.

Checkstyle deduction will be capped at 10 points for this homework.

Turn-in Procedure

Submit your PgnReader.java file on T-Square as an attachment. When you’re ready, double-check that you have submitted and not just saved a draft.

Verify the Success of Your Submission to T-Square

Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.