Word Chain Game Class

Design a Python class, `WordChain`, for a game where each word starts with the last letter of the previoulsy stated word.

The task is to design a Python class `WordChain` which simulates the word chain game, adhering to the rule that the first letter of each subsequent word should be the last letter of the previous word, and no word can be used more than once in the game. ### Class **`WordChain`**: This class represents a game of word chain. #### Methods - **`__init__(self)`**: This method initializes a new game. The game starts with an empty word list and the game status set to active. - **`play(self, word: str) -> Union[List[str], str]`**: This method allows a player to attempt to extend the word chain with a new word. - **`restart(self) -> str`**: This method resets the game to its initial state, by clearing any previously stated words and setting the game status back to active. #### Return Value - **`play(word)`**: If a word adheres to the game rules, it returns a list of words successfully added to the chain; If the game rules are violated, it returns "game over". - **`restart()`**: Returns "game restarted", indicating that the game has been successfully reset. ### Examples ```python # Starting a new game and playing valid words game = WordChain() print(game.play('apple')) # ['apple'] print(game.play('elephant')) # ['apple', 'elephant'] # Attempting to play an invalid word print(game.play('rhino')) # "game over" # Resetting the game print(game.restart()) # "game restarted" print(game.words) # [] # Representation of game termination due to repetition print(game.play('dog')) # ['dog'] print(game.play('giraffe')) # ['dog', 'giraffe'] print(game.play('dog')) # "game over" ```