using System.Collections.Generic;
public enum DifficultyLevel
public string Word { get; set; }
public bool[] CorrectSpot { get; set; }
public bool[] Present { get; set; }
public WordGuess(string word, bool[] correctSpot, bool[] present)
CorrectSpot = correctSpot;
private List<string> _wordList;
public int WordLength => _wordLength;
public WordleGame(List<string> wordList, Random random, DifficultyLevel difficulty)
SetWordList(wordList, difficulty);
private void SetWordList(List<string> wordList, DifficultyLevel difficulty)
case DifficultyLevel.LOW:
_wordList = wordList.Where(word => word.Length == 5).ToList();
case DifficultyLevel.MEDIUM:
_wordList = wordList.Where(word => word.Length == 6).ToList();
case DifficultyLevel.HIGH:
_wordLength = _random.Next(5, 7);
throw new ArgumentException("Invalid difficulty level.");
public WordGuess GuessWord(string guess)
if (guess.Length!= _wordLength)
throw new ArgumentException($"Invalid guess length. Please enter a {_wordLength}-letter word.");
var word = _wordList[_random.Next(_wordList.Count)];
var correctSpot = new bool[_wordLength];
var present = new bool[_wordLength];
for (int i = 0; i < _wordLength; i++)
correctSpot[i] = guess[i] == word[i];
present[i] = word.Contains(guess[i]);
return new WordGuess(word, correctSpot, present);
static void Main(string[] args)
var wordList = new List<string> { "house", "apple", "table", "chair", "mouse", "joevic" };
var random = new Random();
Console.WriteLine("Select difficulty level:");
Console.WriteLine("1. Low (5-letter words)");
Console.WriteLine("2. Medium (6-letter words)");
Console.WriteLine("3. High (random word length between 5 and 6)");
Console.Write("Enter your choice (1, 2, or 3): ");
if (int.TryParse(Console.ReadLine(), out difficultyChoice))
DifficultyLevel difficulty;
switch (difficultyChoice)
difficulty = DifficultyLevel.LOW;
difficulty = DifficultyLevel.MEDIUM;
difficulty = DifficultyLevel.HIGH;
Console.WriteLine("Invalid choice. Exiting.");
var game = new WordleGame(wordList, random, difficulty);
Console.Write($"Guess the {game.WordLength}-letter word: ");
var guess = Console.ReadLine();
var result = game.GuessWord(guess);
for (int i = 0; i < guess.Length; i++)
if (result.CorrectSpot[i])
Console.Write($"{guess[i]} is in the correct spot.\n");
else if (result.Present[i])
Console.Write($"{guess[i]} is present in the word but in the wrong spot.\n");
Console.Write($"{guess[i]} is not in the word.\n");
if (guess == result.Word)
Console.WriteLine("Congratulations! You guessed the word.");
catch (ArgumentException e)
Console.WriteLine(e.Message);
Console.WriteLine("Invalid input. Exiting.");