Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mastermind
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
seilenthalma100744
Mastermind
Commits
e6c5c5c3
Commit
e6c5c5c3
authored
4 months ago
by
Seilenthal
Browse files
Options
Downloads
Patches
Plain Diff
MastermindGame V1 (Code Generation)
parent
3df9b14d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MastermindGame.cs
+97
-0
97 additions, 0 deletions
MastermindGame.cs
with
97 additions
and
0 deletions
MastermindGame.cs
0 → 100644
+
97
−
0
View file @
e6c5c5c3
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
()
{
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment