COMP1010 FUNDAMENTALS OF COMPUTER SCIENCE ASSIGNMENT 4 Last updated: May 23, 2021 Assignment Details • The assignment will be marked out of 100 and it is worth 5% of your total marks in COMP1010. •...

1 answer below »
Complete game.java, deck.java, hand.java , word.java and make all the methods pass in the junit test. This java assignment is based on a word-solitaire game using linked lists. I have attached the PDF document with the instructions and please pay attention to the penalties. None of the methods can be hardcoded or use inbuilt libraries.


COMP1010 FUNDAMENTALS OF COMPUTER SCIENCE ASSIGNMENT 4 Last updated: May 23, 2021 Assignment Details • The assignment will be marked out of 100 and it is worth 5% of your total marks in COMP1010. • Due date: Sunday, 6 June 2021 at 21:00 AEST. • Late penalty: 20% per day or part of (if you submit an hour late, you will be given a 20% penalty). • Topics assessed: Linked List, Classes and Objects Background For your final assignment, you are going to write an implementation of a word-solitaire game using linked lists, and since many of you probably have not seen this kind of game before, I will start by explaining how the game works. The objective of the game is to gain score by creating words from letter tiles, just like in a game of Scrabble. The game board consists of four main components as depicted in Figure 1: the deck button, the hand, the word1 and the score button. At the start of the game, both the player’s hand and word are empty, as shown in Figure 2. Figure 1: The game board. The player obtain letter tiles by clicking on the deck button, which will add a letter tile to the player’s hand (we refer to this as drawing a tile from the deck). Letter tiles are added to the left of the other tiles in the hand (see Figure 3). Player use the letter tiles to form a word, but the main rule of the game is that the player can only move the leftmost letter tile from the hand, and can only extend a word by adding the letter to the start or to the end of the word. Letter tiles already added to the word cannot be removed. 1Even though we call the component the word, it may not actually be a valid word because the player construct it one letter at a time. For the rest of the document, I will try to differentiate between the two by using the term valid word to refer to an actual word, while using word to refer to the player’s word (which may not be a valid word). 1 Figure 2: Board state at start of the game Figure 3: Drawing a tile from the deck. Tiles are added to the left of existing tiles in the hand. Figure 4: Tiles can only be added to the start or end of the word Of course when the word is empty there is only one place to put the leftmost letter (the yellow box), but once the player have moved at least one letter to the word, then the player can add more letters by moving the letter to either the left or the right slot (corresponding to the start and end of the word respectively). Once the player has formed a word with at least three letters, the player can click on the score button to score the word, that is, if the word is a valid word, then it will be removed and its score added to the score total. The score of a word is obtained by adding the score on each tile (see Figure 5). However, if the word is not a valid word, then there are two possibilities. If the word can be extended to a valid word, then no point will be added to the score, but the word will remain on the board. For example, if the player tries to score the word WHAL, then nothing will happen, because we can extend WHAL to WHALE (among other 2 words). On the other hand, if the word cannot be extended to form a valid word, for example, WHL, then the word will be discarded and no points will be awarded. A player can choose to discard the current word by adding letters so that it becomes invalid and then clicking on the score button. Figure 5: Clicking on the score tile scores the word, adding points to the total score, and removes the word. For example, the word WHALE adds up to 11 points. The game ends when there are no more letter tiles in the hand or the deck, although with the way I implemented right now, the game does not actually end. The player simply won’t have any more moves to make and so must restart the game. Your Task Your task is to implement the logic of the game by completing the methods in the following four classes: • Deck.java • Hand.java • Word.java • Game.java The first three classes correspond to the game components described earlier, namely the deck, the hand, and the word. The final class, Game.java controls the interactions between the other classes. The deck, the hand, and the word should all be implemented as a linked list of Letter objects, which is a representation of the letter tiles. The code for the Letter class, in Letter.java, is already written for you, and it is not part of your submission (so please do not modify it). The linked list implementations of the deck, the hand, and the word have slight differences. The deck is implemented as a queue, that is, the first letter added to deck should be placed at the top of the deck (i.e. the first letter to be drawn). Conversely, the hand is implemented as a stack, since the first letter added to the hand will be the last letter that can be moved (the last letter added to the hand is placed leftmost, and so it is the only letter that can be moved by the player). We cannot remove any tile from the word, but we can add a letter to either end, so this is yet another kind of linked list that must be implemented differently. To implement the linked lists, you are free to add more attributes (class variables) and methods to the four files that you have to submit, except that you are not allowed to use arrays unless the method requires it. You are also not allowed to import any packages. See the section Limitations further below for more details. You can find the exact marks allocated for each method that you have to implement in Marks and Grade Distribution section further down in this document. The details of what each of these methods do can be found in the code template given to you. However, here is a general outline of the tasks that you need to complete and a rough guide on the order that you should attempt them: 1. Implement the add methods in for the Deck, Hand, and Word classes (addToStart and addToEnd), for a total 3 of 16 marks. Completing these methods allows you to start populating the linked list which makes it easier to test the other methods. 2. Implement the size methods for the Deck, Hand, and Word classes, for a total of 12 marks, which gets you to start traversing the linked list. 3. Implement the constructors for Deck and Game, for a total of 7 marks. 4. Implement getScore, isWord, and isPossibleWord in Word.java, and then scoreWord in Game.java, for a total of 16 marks. Completing all the above methods should give you all the pass marks of 51 out of 80 (the marks distribution is shown later in this document). You may not be able to follow this exact order because there are inter-dependencies between the classes, so you are definitely free to complete the tasks in the order of your choosing. Once you complete these pass-level methods, you can start concentrating on the rest of the Credit and Distinction level methods. Important: when you add a Letter to either the deck, the hand, or the word, or move a Letter between them, you should NOT make a new instance of the Letter. Instead you should just add the reference to the linked list. The only exception is the add method in Deck.java since you are not given a Letter as an input parameter, but the actual character and its score. For the High Distiction level, one of the tasks require you to implement the method toArray in Word.java, but the other two tasks do not actually ask you to write any new methods. They only test if you have implemented the size and add methods efficiently, so you may not have to do any extra work! Limitations The assignment assesses your understanding of linked lists, therefore you are NOT allowed to use an array in any of your methods unless it is given as an input, or if you are required to return an array. The exceptions for the above rule are: • The constructor for the Game class (since both input parameters are arrays). • The constructor for the Deck class (since the input parameter is an array). • The methods isWord, isPossibleWord, and toArray in class Word. You may be severely penalised for using arrays instead of linked lists in any other methods. You must also not use the ArrayList class or any other Java container classes. In fact, you are not allowed to have any import statements in any of the classes that you are submitting for this assignment. JUnit Tests As in previous assignments, you are given a JUnit test (UnitTest.java) which you should use to ensure that your code meets all the requirements. The assignment will be automarked using a similar test suite. Obviously the values used in the tests will be modified when your assignment is being marked, but the tests themselves should be very similar. Visualisation For this assignment, I have added a visualiser that you can use to check if you have implemented the game logic correctly. As in the previous assignment, the graphics are implemented using the Java Swing library, and all relevant classes can be found in the graphics package. To run the game, you need to run the GameBoard class. Of course 4 you need to finish some parts of the assignment before the visualiser starts working, and it will properly work only when you have finished every method. The GameBoard class creates an instance of Game and uses it to access the game components (the deck, the hand, and the word). The visualisation is done by simply drawing whatever is in the game components after every move, so whatever letters you have in the deck, the hand, or the word, will be drawn on screen. The implementation is much more complex than the one I did for the previous assignment, so I will not go into the details. However, here is something that may help you complete the assignment; the code that is used to create the dictionary and the array of letters for the game in the following lines inside the main method in GameBoard.java: public void run() {
Answered 2 days AfterMay 31, 2021COMP1010

Answer To: COMP1010 FUNDAMENTALS OF COMPUTER SCIENCE ASSIGNMENT 4 Last updated: May 23, 2021 Assignment Details...

Rushendra answered on Jun 01 2021
148 Votes
COMP1010_S1_2021_Assignment_4_Text_Game/.classpath

    
        
            
        
    
    
    
    
COMP1010_S1
_2021_Assignment_4_Text_Game/.project

     COMP1010_S1_2021_Assignment_4_Text_Game
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
        ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here