Package javachess.parser
Class Parser
java.lang.Object
javachess.parser.Parser
Parser class that parses a PGN file and extracts the headers and moves.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetGameFromPath(String path) Reads a PGN file from the given path and returns its content as a string.getHeaders(String unparsedHeader) Parses the headers from the unparsed header string.getMoves()Parses the moves from the unparsed moves string.parseMove(String move, PieceColor pieceColor) Parses a move string into an Instruction object.voidsplitParts(String game) Splits the game string into headers and moves.
-
Constructor Details
-
Parser
public Parser()
-
-
Method Details
-
getMoves
-
getGameFromPath
Reads a PGN file from the given path and returns its content as a string.- Parameters:
path- the path to the PGN file- Returns:
- the content of the PGN file as a string
-
splitParts
Splits the game string into headers and moves.- Parameters:
game- the game string
-
getHeaders
Parses the headers from the unparsed header string.- Parameters:
unparsedHeader- the unparsed header string- Returns:
- a map of headers
-
getMoves
Parses the moves from the unparsed moves string.- Parameters:
unparsedMoves- the unparsed moves string- Returns:
- a list of instructions
-
parseMove
Parses a move string into an Instruction object.- Parameters:
move- the move stringpieceColor- the color of the piece- Returns:
- an Instruction object representing the move
-