Skip to content
Snippets Groups Projects
Commit e6c5c5c3 authored by Seilenthal's avatar Seilenthal
Browse files

MastermindGame V1 (Code Generation)

parent 3df9b14d
No related branches found
No related tags found
No related merge requests found
using System;
using PseudoRandomGenerator;
namespace Mastermind
{
public class MastermindGame
{
private int[] code;
private readonly int code_length;
private readonly bool duplicates;
public MastermindGame(string difficulty)
{
// Set parameters based on difficulty level
switch(difficulty.ToLower())
{
case "easy":
code_length = 4;
duplicates = false;
break;
case "medium":
code_length = 6;
duplicates = false;
break;
case "hard":
code_length = 8;
duplicates = true;
break;
default:
throw new ArgumentException("Invalid difficulty level");
}
GenerateCode();
}
public void GenerateCode()
{
LCG lcg = new LCG(DateTime.Now.Ticks);
code = new int[code_length];
if(duplicates)
{
// Allow duplicates
for(int i = 0; i < code_length; i++)
{
code[i] = lcg.Next(0, 9);
}
} else
{
// No duplicates allowed
for(int i = 0; i < code_length; i++)
{
int newNumber;
bool isDuplicate;
do
{
isDuplicate = false;
newNumber = lcg.Next(0, 9); // Generates a number between 0 and 9
//Check if the generated number is already in the code
for (int j = 0; j < i; i++)
{
if (code[i] == newNumber)
{
isDuplicate = true;
}
}
} while (isDuplicate); // Repeat if duplicate was found
code[i] = newNumber; // Assign the unique number
}
}
// For Testing this code:
// code = new int[] { 1, 3, 4, 2 };
}
public void GetHint()
{
}
public void CheckWin()
{
}
public void DisplayBoard()
{
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment