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
e1cb1875
Commit
e1cb1875
authored
3 months ago
by
Seilenthal
Browse files
Options
Downloads
Patches
Plain Diff
Changes for small resource savings
parent
b5af5050
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MastermindGame.cs
+14
-14
14 additions, 14 deletions
MastermindGame.cs
with
14 additions
and
14 deletions
MastermindGame.cs
+
14
−
14
View file @
e1cb1875
...
...
@@ -22,7 +22,7 @@ namespace Game
private
readonly
int
maxAttempt
;
private
int
currentAttempt
;
private
int
[][]
attempts
;
// Jagged array (array of arrays) to save attempts
private
(
int
guess
,
Hints
hint
)[
,
]
feedback
;
private
(
int
guess
,
Hints
hint
)[]
feedback
;
private
const
string
SaveFilePath
=
"mastermind_gamehistorie.txt"
;
/// <summary>
...
...
@@ -56,7 +56,7 @@ namespace Game
}
attempts
=
new
int
[
maxAttempt
][];
feedback
=
new
(
int
,
Hints
)[
code_length
,
1
];
feedback
=
new
(
int
,
Hints
)[
code_length
];
// Initializes each inner array to avoid null reference later
for
(
int
i
=
0
;
i
<
maxAttempt
;
i
++)
...
...
@@ -129,9 +129,9 @@ namespace Game
int
[]
used
=
new
int
[
10
];
// Tracks used numbers to prevent duplicate hints
// Resets the feedback-array
for
(
int
i
=
0
;
i
<
feedback
.
Get
Length
(
0
)
;
i
++)
for
(
int
i
=
0
;
i
<
feedback
.
Length
;
i
++)
{
feedback
[
i
,
0
]
=
(-
1
,
Hints
.
None
);
feedback
[
i
]
=
(-
1
,
Hints
.
None
);
}
foreach
(
int
i
in
input
)
...
...
@@ -146,7 +146,7 @@ namespace Game
// If duplicates are not allowed, check if the number hasn't already been used
if
(
used
[
i
]
==
0
)
{
feedback
[
counter
,
0
]
=
(
i
,
Hints
.
Green
);
feedback
[
counter
]
=
(
i
,
Hints
.
Green
);
used
[
i
]
=
1
;
// Marks as used
}
...
...
@@ -154,7 +154,7 @@ namespace Game
else
{
// If duplicates are allowed, ignore used
feedback
[
counter
,
0
]
=
(
i
,
Hints
.
Green
);
feedback
[
counter
]
=
(
i
,
Hints
.
Green
);
}
counter
++;
check
=
true
;
...
...
@@ -172,7 +172,7 @@ namespace Game
// If duplicates are not allowed, check if the number hasn't already been used
if
(
used
[
i
]
==
0
)
{
feedback
[
counter
,
0
]
=
(
i
,
Hints
.
Yellow
);
feedback
[
counter
]
=
(
i
,
Hints
.
Yellow
);
used
[
i
]
=
1
;
// Marks as used
}
...
...
@@ -180,7 +180,7 @@ namespace Game
else
{
// If duplicates are allowed, ignore used
feedback
[
counter
,
0
]
=
(
i
,
Hints
.
Yellow
);
feedback
[
counter
]
=
(
i
,
Hints
.
Yellow
);
}
counter
++;
}
...
...
@@ -189,7 +189,7 @@ namespace Game
// Number is not present in the code
else
{
feedback
[
counter
,
0
]
=
(
i
,
Hints
.
None
);
feedback
[
counter
]
=
(
i
,
Hints
.
None
);
counter
++;
}
}
...
...
@@ -197,9 +197,9 @@ namespace Game
// Sets numbers to -1 if hint is not green or yellow
for
(
int
i
=
0
;
i
<
feedback
.
GetLength
(
0
);
i
++)
{
if
(
feedback
[
i
,
0
].
hint
!=
Hints
.
Green
&&
feedback
[
i
,
0
].
hint
!=
Hints
.
Yellow
)
if
(
feedback
[
i
].
hint
!=
Hints
.
Green
&&
feedback
[
i
].
hint
!=
Hints
.
Yellow
)
{
feedback
[
i
,
0
].
guess
=
-
1
;
feedback
[
i
].
guess
=
-
1
;
}
}
}
...
...
@@ -256,13 +256,13 @@ namespace Game
for
(
int
i
=
0
;
i
<
feedback
.
GetLength
(
0
);
i
++)
{
if
(
feedback
[
i
,
0
].
hint
==
Hints
.
Green
)
if
(
feedback
[
i
].
hint
==
Hints
.
Green
)
{
Console
.
ForegroundColor
=
ConsoleColor
.
Green
;
Console
.
Write
(
"X "
);
Console
.
ForegroundColor
=
ConsoleColor
.
Gray
;
}
else
if
(
feedback
[
i
,
0
].
hint
==
Hints
.
Yellow
)
else
if
(
feedback
[
i
].
hint
==
Hints
.
Yellow
)
{
Console
.
ForegroundColor
=
ConsoleColor
.
Yellow
;
Console
.
Write
(
"Y "
);
...
...
@@ -291,7 +291,7 @@ namespace Game
for
(
int
i
=
0
;
i
<
feedback
.
GetLength
(
0
);
i
++)
{
Console
.
WriteLine
(
$"Zahl:
{
feedback
[
i
,
0
].
guess
}
, Hinweis:
{
feedback
[
i
,
0
].
hint
}
"
);
Console
.
WriteLine
(
$"Zahl:
{
feedback
[
i
].
guess
}
, Hinweis:
{
feedback
[
i
].
hint
}
"
);
}
}
...
...
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