<jupyter_start><jupyter_text>Jon's ~~Wordle Clone~~ "Big Word Game"* Slide word_size to choose the number of letters* Slide number_attempts to choose the number of tries you get* The answer is tied to game_code, so if you use the same code as a friend, you'll both be guessing the same answer. Type in "RANDOM" to get a random word.↓ Click this circle to play!<jupyter_code># Peeking at the code, are we?

# Stuff for the colab form
#@title Settings { vertical-output: true, display-mode: "form" }
word_size = 6 #@param {type:"slider", min:4, max:12, step:1}
number_attempts = 7 #@param {type:"slider", min:3, max:20, step:1}
game_code = "HELLO THERE" #@param {type:"string"}

# Libraries and stuff
print("Importing")
import random # Select random words
import time # Calculate time taken

import pandas as pd
import nltk # Natural Language ToolKit, contains word lists
from google.colab import output # Clear the console output
from nltk.corpus import brown # Word corpus
from termcolor import colored # Colored console text

# download corpus (words) 
nltk.download("brown")

# Set the randomizer seed according to the room code
output.clear()
print("Setting room code")
if game_code == "RANDOM":
    pass
else:
    random.seed(a=game_code, version=2)

# Filter words from corpus depending on word length selected 
output.clear()
print(" Building word list")
word_list = [
    word.lower() for word in brown.words() if len(word) == word_size and word.isalpha()
]
print(f"{len(word_list)} word(s) found with {word_size} letters")

# Initial instructions
output.clear()
print(f"Guess a {word_size} letter word in {number_attempts} attempts!")
print(f"{colored('Green', 'green')} letters are in the right place")
print(f"{colored('Yellow', 'yellow')} letters are in the word, but at the wrong place")
print(f"{colored('Red', 'red')} letters are not in the word")

answer = random.choice(word_list) # Select a random word from the list
start = time.time() # Start the timer
keyboard = " Q W E R T Y U I O P \n  A S D F G H J K L \n   Z X C V B N M" # This is the keyboard display text
print(keyboard)
initial_number_attempts = number_attempts # Saving this here for later
# Initial checks for word length and validity
total_results = [] # List of results, empty for now
while number_attempts > 0: # While you've still got tries left
    while True:
        guess = str(input()).lower() # Convert to lowercase to check
        if len(guess) < word_size: # If the word is too small
            print("Too few letters")
            continue
        elif len(guess) > word_size: # If the word is too big
            print("Too many letters")
            continue
        elif guess not in word_list: # If the word isn't a word
            print("Word not in dictionary")
            continue
        else:
            break

# Main game loop
    result = "" # The result, empty for now
    for idx, letter in enumerate(guess): # iterate through every letter in your guess
        if guess[idx] == answer[idx]: # If it's in the right spot
            result += colored(letter, "green") # Color it green and add it to the results
            keyboard = keyboard.replace( # Also make the letter green in the keyboard display
                letter.upper(), (colored(letter.upper(), "green")) # Keyboard uses uppercase letters
            )
        elif guess[idx] in list(answer): # Otherwise, if the letter is in the word (but not in the right spot)
            result += colored(letter, "yellow") # Color it yellow
            keyboard = keyboard.replace(
                letter.upper(), (colored(letter.upper(), "yellow"))
            )
        else:
            result += colored(letter, "red") # Otherwise, color it red
            keyboard = keyboard.replace(
                letter.upper(), (colored(letter.upper(), "red"))
            )
    total_results.append(result) # Add this result to the list of all results

    if guess == answer: # If you get it right
        break # exit
    else: # otherwise show the previous words and the keyboard, and deduct a try
        output.clear()
        print(*total_results, sep="\n")
        print(keyboard)
        number_attempts -= 1

end = time.time() # End timer
output.clear()
# Results
print(*total_results, sep="\n")
print(f"The answer was {answer}")
print(f"{len(total_results)}/{initial_number_attempts} attempts used")
print(f"Time taken: {round(end-start)} seconds")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10359550561797753, 'fraction_numerical': 0.0029213483146067415, 'mean_word_length': 3.2880539499036607, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '157842', 'license': 'MIT', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1269, 'n_words': 530, 'path': 'BigWordGame.ipynb', 'repo_name': 'johnathanfernandes/Big-Word-Game', 'size': '4450'}