Assignment Detail

Tutors

Write a terminal-based version of the game wordle

    Assignment Instructions

    Assignment ID: FG133141675

    CO7105 Advanced C++ Programming – University of Leicester

    Task 1
    The main concepts that you will be assessed in this task are memory management, operator overloading, templates, exceptions, in addition to general programming logic. You must not use any STL containers in this task.

    This task builds on what was in A ssignment 1. You need to understand all the requirements of that assignment;
    they will not be stated here again but they all still apply. But you do not need to “re-do” any of it: you are free to use the sample solution given there, or your previous attempt at it, as a starting point.
    You will make two major changes to the BucketList data structure in Assignment 1:

    Each data item to be stored is no longer just a string, but a (key, value) pair where the “keys” are strings,
    and the “values” are objects of a template type T. The template parameter T can be any primitive data type (int, double, etc) or any class that has its own default constructor, copy constructor and copy assignment
    (that performs deep copy where necessary), and output stream redirection operator. As long as the type T supports these operations, your code should work correctly. Note that as a result of this, the whole data structure is templated and therefore all the code should appear in BucketList.h; there will be no BucketList.cpp.

    The strings are how the data items are accessed; insertion, removal, search and the mash calculations are all based on the string only, as before. The “value” object of type T is just some arbitrary data that are “carried along”.

    The primary part of the data structure, i.e. the table pointed to by the buckets_ pointer, is no longer an
    array of Node pointers, but rather an array of Nodes. Each entry in the array is no longer a pointer to the head of a linked list, but rather the head of the linked list itself, storing the first item in this bucket. Any further entries that goes into this bucket are linked to by the next_ pointers in a linked list.

    The empty string should no longer be accepted as valid input as the “key” part of any data item. You can therefore use the empty string to indicate that an entry in the buckets_ table does not store any valid data item.

    As a result of these changes, the Node and BucketList classes should be modified as follows:

    // you probably need this “forward declaration” template <class T> class BucketList;

    template <class T> class Node {
    string s_; // string stored at this node T t_; // T object stored at this node
    Node* next_; // pointer to next Node in the list

    };

    template <class T> class BucketList {
    Node* buckets_; // pointer to an array of Node

    };

    As before, the buckets_ array will be dynamically resized, so instead of declaring it as Node[], it is declared as
    Node*.

    Here is a picture showing (conceptually) how seven data items (C++, 4), (F#, 3), (abc, 5), (apple, 7), (banana, 1), (blue, 2), (c, 3) might be stored in a BucketList<int> (i.e. the type T is int) with capacity 10:

    Supported operations

    You data structure should support all the functionalities in Assignment 1 (where you may need to make changes to the code to adapt to the changes above), plus the following changes/additions:

    The default constructor now initialises each bucket to contain a empty data item (i.e. the string part is the empty string).

    void insert(const string& s, const T& t): add the data item with key s and value t to the data structure. If the string s is already in the BucketList, replace the value object currently associated with s with the new value object t. If s is an empty string, do nothing. All other aspects are the same as before (mashing based on s, resizing, items in a bucket to be stored in alphabetical order of the strings, etc).

    T operator[](const string& s) const T& operator[](const string& s)

    Overloaded “subscript” operator that allows array-indexing like access of the data items. The first version returns a copy of the value object (of type T) associated the key string s stored in the data structure. The second version updates the value object associated with the key string s currently in the data structure, by returning a reference to it so that the caller can write a new value object to it.

    For example, if a BucketList b contains the 7 items in the example before, then b[“C++”] should return the value 4, and the line b[“C++”] = 5 should set it to a new value 5.

    In both cases, if there are no data item with key s in the data structure, it should throw a
    std::invalid_argument exception (and make no changes to the data structure).

    std::ostream& operator<<(ostream& os, const BucketList& bl): write to the output stream os a “visual” representation of the contents of the BucketList. More precisely, there should be one row per bucket. Each row begins with a number which is the index to the buckets_ array (i.e. the mash value of the strings in that bucket), followed by a space, then by each data item in the linked list of that bucket, in the order they are stored. For each data item, the key string is printed, followed by a space, followed by the value object. Between two data items, the string ” -> ” should be printed to separate them. The type T itself is assumed to support the << operator. For example, the BucketList above will be printed like this:

    0 F# 3 -> blue 2
    1
    2 banana 1 3
    4
    5 C++ 4
    6
    7
    8
    9 abc 5 -> apple 7 -> c 3

    The output consists of multiple lines, separated by the ‘\n’ character. Please take care not to include any extra invisible whitespaces. This is to be implemented as a friend function (not a member function of Node or BucketList).

    Task 2
    The main concepts that you will be assessed in this task are file I/O and STL, in addition to general program logic and program design.

    You will write a terminal-based version of the game Wordle. Please refer to their website for rules of the game.

    Your program should first read from a file called dict.txt, from the same directory (folder) where the program runs from. This file contains a list of 5-letter words, one on each line. You can assume this file only stores 5- letter words, and all letters of all words are in lowercase, but the words are not necessarily in any sorted order. Your program must not assume any arbitrary limit on the number of words in this file. An example file can be found below.
    The program should pick a random word from this file, which is going to be the answer to this game. Then the game begins: the user is given six attempts, and in each attempt is asked to type in a 5-letter word as their guess. If the user’s word is not in the dictionary, the word is rejected and the user is asked to enter again (without using up an attempt). Otherwise, the program checks each letter in the user’s guess and assigns a colour as follows:
    If a letter is present in the answer and at the correct position, it is shown in green.
    If a letter is present in the answer but not at the correct position, it is shown in yellow. If a letter is not present in the answer at all, it is shown in a normal colour.

    Note however that in situations where a letter appears more than once in the guess and/or the answer, the green/yellow colouring should apply only if the matching letter has not already been “used up”. For example, if

    the answer is COLOR and the user guess is HELLO, only the middle L should be in green, and the other L is in normal colour. On the other hand, if the answer is HELLO and the user guess is COLOR, then only one of the two O’s (doesn’t matter which one) is yellow and the other L is in normal colour. Finally, if the answer is COLOR and the user guess is COOLS, the first O should be green and the second O is yellow.

    If the user’s guess is correct (all letters green), the game should display some simple congratulatory message and ends. Otherwise one guess is used up and the user is asked to make another guess. If after 6 guesses the user still hasn’t got the correct answer, the game should display some simple “game over” message and ends.

    The program should not care whether the user’s inputs are uppercase or lowercase. The display of results (letters possibly with colours) should always be in uppercase.

    You are encouraged to use the method in the sample code below to display coloured texts, in terminals that support them. You do not have to stick to green and yellow; you may want to change to some other colours of better visibility. Alternatively you can use some other notation to indicate the correctness of the guesses. In either case you should make clear indications as to what colours/symbols represent what. See examples below.

    You are encouraged to write all your code in a single file wordle.cpp. Your program will be compiled simply by g++ wordle.cpp -o wordle. If however you choose to separate your code into multiple files, this is permitted but you must also supply a makefile so that when typing “make” it will compile your files into an executable called “wordle”.

    Attachment:- Advanced C++ Programming.rar

    Need fresh solution to this Assignment without plagiarism?? Get Quote Now

    Expert Answer

    Asked by: Anonymous
    Plagiarism Checked
    Answer Rating:
    4.6/5

    Plagiarism free Answer files are strictly restricted for download to the student who originally posted this question.

    Related Assignments

    //
    Our customer support team is here to answer your questions. You can send Assignments directly to support team.
    👋 Hi, how can I help?