Class Parser

java.lang.Object
javachess.parser.Parser

public class Parser extends Object
Parser class that parses a PGN file and extracts the headers and moves.
  • Constructor Details

    • Parser

      public Parser()
  • Method Details

    • getMoves

      public ArrayList<Instruction> getMoves()
    • getGameFromPath

      public String getGameFromPath(String path)
      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

      public void splitParts(String game)
      Splits the game string into headers and moves.
      Parameters:
      game - the game string
    • getHeaders

      public HashMap<String,String> getHeaders(String unparsedHeader)
      Parses the headers from the unparsed header string.
      Parameters:
      unparsedHeader - the unparsed header string
      Returns:
      a map of headers
    • getMoves

      public ArrayList<Instruction> getMoves(String unparsedMoves)
      Parses the moves from the unparsed moves string.
      Parameters:
      unparsedMoves - the unparsed moves string
      Returns:
      a list of instructions
    • parseMove

      public Instruction parseMove(String move, PieceColor pieceColor)
      Parses a move string into an Instruction object.
      Parameters:
      move - the move string
      pieceColor - the color of the piece
      Returns:
      an Instruction object representing the move