Write a terminal-based version of the game wordle

Assignment Help C/C++ Programming
Reference no: EM133141675

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

Reference no: EM133141675

Questions Cloud

What was be the issuance price of the bonds : The face value of the bonds is $10,000,000 with a stated interest rate of 7%. What was be the issuance price of the bonds
Use soldiworks simulation for task : Use soldiworks simulation for this task - The idea of the design is to help the workers to don''t ruined their backs (vertebrates ) while working
Compute SSCL basic EPS : The bonds are convertible into 80 common shares for each $1,000 bond. Bond interest expense was $403,000 for the year. Compute SSCL's basic EPS for 20X5
Toyota production system : Why Companies adopted Lean Thinking and JIT model? Discuss major types of Waste, companies must keep in mind during production.
Write a terminal-based version of the game wordle : Write a terminal-based version of the game Wordle. Please refer to their website for rules of the game - what colours/symbols represent what.
What is the minimum number of jars of silver polish : What is the minimum number of jars of silver polish that would have to be sold to justify further processing of Grit 337
What is the relationship between risk and return : Question - What is the relationship between risk and return? What is the significance of this relationship for the investor? In 300 or more words
Forward with obtaining funding for business : Were there any surprises in your financial situation? Are you able to move forward with obtaining funding for your business?
What amount should Jenny report as cash payments : Assuming all inventory is purchased on credit, what amount should Jenny report as cash payments to suppliers for 2021 using the direct method of cash flows

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program toinsert and delete any element anywhere in the list

You are to implement a 'List' class to handle a list with general operations. That means you can insert and delete any element anywhere in the list. The list has no order, except for the order you insert or delete. The methods you are to implement..

  Write an application for between two players

Use C# Write an application for between two players like Jack and Jil.

  Average of the bowler raw score

Display for each bowler the bowler name and the average of the bowler's raw score. Calcualte the current average and handicap for each bowler.

  Calculate the potential energy of a rock with a mass of 55

calculate the potential energy of a rock with a mass of 55 kg while sitting on a cliff that is 27 m

  Prepare a program to find the area of a triangle

Write a program that prompts the user to enter three point (x1, y1), (x2, y2), (x3, y3) of a triangle and display its area.

  Write program that stores the numbers in array

Write a c++ program that stores the following numbers in the array named miles: 15,22,16,18,27,23, and 20. have your program copy the data stored in miles to another array.

  C Programming Assignment - Calculate factorial of number

C Programming Assignment - Write a C program that convert a temperature from Centigrade to Fahrenheit. Write C program to calculate factorial of a given number

  Write a function that takes an integer array

1. Write a function that takes an integer array and the array's size as parameters. The function will check if the array is sorted. If it is, it will return a 1. If it is not sorted it will return 0. The function should not  sort the array.

  Write a program which allows the user to perform simple task

Write a program which allows the user to perform simple tasks on a calculator. A series of functions allows the user to select an operation to perform and then enter operands.

  Write a program that stimulates a bouncing ball

Write a program that stimulates a bouncing ball by computing its height in feet at each second as time passes on a simulated clock. At time zero, the ball begins at height zero.

  Write a program to print the permutation

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation.

  Write a program that will take in a unsigned short integer

Write a program that will take in a unsigned short integer and then swap the contents of the upper eight bits with the lower eight bits.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd