Package test

Class Board

java.lang.Object
test.Board

public class Board extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static Board
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    The boardLegal function checks if the word is legal to be placed on the board.
    checkBonus(int row, int col)
    The checkBonus function checks the board for any bonus squares and returns a string that represents the type of bonus square.
    boolean
    The dictionaryLegal function checks if the word is a valid English word.
    static Board
    The getBoard function is a static function that returns the Singleton board object.
    int
    getFirstLetterRow(int row, int col)
    The getFirstLetterRow function takes in a row and column number and returns the first letter that is connected from there in that column.
    int
    getScore(Word word)
    The getScore function takes a Word object as an argument and returns the score of that word.
    Tile[][]
    The getTiles function returns a copy of the tiles array.
    getWords(Word word)
    The getWords function returns an ArrayList of Word objects that are formed by the tiles in the given word.
    boolean
    isEqual(Word w1, Word w2)
    The isEqual function checks if two words are equal.
    boolean
    isWordThere(Word word, int row, int col, boolean isVertical)
    The isWordThere function checks if the word is there in the board.
    int
    nonVerticalLength(int row, int col)
    The nonVerticalLength function is used to find the length of a non-vertical line.
    nonVerticalTileWord(int row, int col)
    The nonVerticalTileWord function takes in a row and column number as parameters.
    void
    The printBoard function prints the board to the console.
    sendToDictionaryLegal(Word submittedWord, Word wordToFinish)
    The sendToDictionaryLegal function takes in a submitted word and a word to finish.
    tileVerticalWord(int row, int col)
    The tileVerticalWord function takes in a row and column number, and returns the word that is formed by the tiles vertically above or below it.
    int
    The tryPlaceWord function takes in a word and checks if it is legal to place on the board.
    int
    verticalLength(int row, int col)
    The verticalLength function returns the length of a vertical line of tiles starting at (row,col) and extending in the positive row direction.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • board

      public static Board board
  • Method Details

    • getTiles

      public Tile[][] getTiles()
      The getTiles function returns a copy of the tiles array.
      Returns:
      A copy of the tiles array
    • isWordThere

      public boolean isWordThere(Word word, int row, int col, boolean isVertical)
      The isWordThere function checks if the word is there in the board.
      Parameters:
      word - Word -Get the length of the word
      row - int -Check if the word is in the same row as the letter
      col - int -Check if the column of the word is equal to the col parameter
      isVertical - boolean -Determine whether the word is vertical or horizontal
      Returns:
      True if the word is in the board
    • boardLegal

      public boolean boardLegal(Word word)
      The boardLegal function checks if the word is legal to be placed on the board. It checks if it's connected to other words, and that it doesn't overlap with any letters already on the board.
      Parameters:
      word - Word -Get the row, column, and tiles of the word
      Returns:
      True if the word is legal on the board and false otherwise
    • dictionaryLegal

      public boolean dictionaryLegal(Word word)
      The dictionaryLegal function checks if the word is a valid English word.
      Parameters:
      word - Word -Get the tiles from the word, and to see if it is vertical or horizontal
      Returns:
      True if the word is in the dictionary, false otherwise
    • getBoard

      public static Board getBoard()
      The getBoard function is a static function that returns the Singleton board object.
      Returns:
      The board object
    • getFirstLetterRow

      public int getFirstLetterRow(int row, int col)
      The getFirstLetterRow function takes in a row and column number and returns the first letter that is connected from there in that column.
      Parameters:
      row - int -Get the row of the first letter in a word
      col - int -Determine the column of the first letter in a word
      Returns:
      An int
    • tileVerticalWord

      public Word tileVerticalWord(int row, int col)
      The tileVerticalWord function takes in a row and column number, and returns the word that is formed by the tiles vertically above or below it. If there are no tiles above or below it, then null is returned.
      Parameters:
      row - int-Determine the row of the first letter in a word
      col - int-Determine the column of the first letter in a word
      Returns:
      A word object that represents the word formed by
    • verticalLength

      public int verticalLength(int row, int col)
      The verticalLength function returns the length of a vertical line of tiles starting at (row,col) and extending in the positive row direction. If there is no tile at (row,col), then 0 is returned.
      Parameters:
      row - int -Determine the row of the tile that is being checked
      col - int -Determine the column of the tile
      Returns:
      The number of tiles in a vertical line starting at the given row and column
    • nonVerticalLength

      public int nonVerticalLength(int row, int col)
      The nonVerticalLength function is used to find the length of a non-vertical line.
      Parameters:
      row - int -Determine the row that the tile is in
      col - int -Determine the column of the tile
      Returns:
      The length of the non-vertical line
    • nonVerticalTileWord

      public Word nonVerticalTileWord(int row, int col)
      The nonVerticalTileWord function takes in a row and column number as parameters. It then checks if the tile at that position is null, if it is not null, it will check to see how many tiles are connected to the right of this tile. If there are no tiles connected to the right of this tile, then we return null because there is no word formed by just one letter. Otherwise we create an array of Tiles with length equal to the number of letters in our non-vertical word (including our starting letter). We also keep track of which column contains our first letter so that when we add
      Parameters:
      row - int -Specify the row of the tile that is being checked
      col - int -Determine the column of the first letter in a word
      Returns:
      A word that is not vertical
    • getWords

      public ArrayList<Word> getWords(Word word)
      The getWords function returns an ArrayList of Word objects that are formed by the tiles in the given word.
      Parameters:
      word - Word -Get the tiles of the word
      Returns:
      An arraylist of words
    • sendToDictionaryLegal

      public Word sendToDictionaryLegal(Word submittedWord, Word wordToFinish)
      The sendToDictionaryLegal function takes in a submitted word and a word to finish. It then creates an array of tiles that is the same length as the word to finish, and fills it with tiles from both words. If there is no tile at that position in the WordToFinish, it will take one from submittedWord instead. The function returns this new Word object.
      Parameters:
      submittedWord - Word
      wordToFinish - Word
      Returns:
      A new word that is the combination of the submittedword and wordtofinish
    • isEqual

      public boolean isEqual(Word w1, Word w2)
      The isEqual function checks if two words are equal.
      Parameters:
      w1 - Word
      w2 - Word
      Returns:
      A boolean
    • checkBonus

      public String checkBonus(int row, int col)
      The checkBonus function checks the board for any bonus squares and returns a string that represents the type of bonus square. The function takes in two parameters, row and col, which are used to determine what kind of bonus square is at that location on the board.
      Parameters:
      row - int
      col - int
      Returns:
      A string
    • getScore

      public int getScore(Word word)
      The getScore function takes a Word object as an argument and returns the score of that word. The function first gets all the words in the board by calling getWords(Word) function. Then it iterates over each word, calculates its score and adds it to total score.
      Parameters:
      word - Word
      Returns:
      The score of the word that is placed on the board
    • tryPlaceWord

      public int tryPlaceWord(Word word)
      The tryPlaceWord function takes in a word and checks if it is legal to place on the board. If it is, then the function will try to place the word on the board with all the new words that been created as well checks if they are all valid.
      Parameters:
      word - Word
      Returns:
      An int - returns the score of the given word, if the word wasn't placed returns 0.
    • printBoard

      public void printBoard()
      The printBoard function prints the board to the console.