Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
CS 240
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
BYU Computer Science
CS 240
Commits
e7ae16a0
Commit
e7ae16a0
authored
5 years ago
by
Josue Lopez
Browse files
Options
Downloads
Patches
Plain Diff
Passed all tests
parent
0fb5ebe4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
EvilHangman/out/production/EvilHangman/hangman/EvilHangmanGame.class
+0
-0
0 additions, 0 deletions
.../out/production/EvilHangman/hangman/EvilHangmanGame.class
EvilHangman/src/hangman/EvilHangmanGame.java
+19
-33
19 additions, 33 deletions
EvilHangman/src/hangman/EvilHangmanGame.java
with
19 additions
and
33 deletions
EvilHangman/out/production/EvilHangman/hangman/EvilHangmanGame.class
+
0
−
0
View file @
e7ae16a0
No preview for this file type
This diff is collapsed.
Click to expand it.
EvilHangman/src/hangman/EvilHangmanGame.java
+
19
−
33
View file @
e7ae16a0
...
...
@@ -8,10 +8,11 @@ import java.util.*;
public
class
EvilHangmanGame
implements
IEvilHangmanGame
{
private
SortedSet
<
Character
>
guessedLetters
=
new
TreeSet
<
Character
>();
private
SortedSet
<
String
>
words
=
n
ew
TreeSet
<
String
>()
;
private
SortedSet
<
String
>
words
=
n
ull
;
@Override
public
void
startGame
(
File
dictionary
,
int
wordLength
)
throws
IOException
,
EmptyDictionaryException
{
words
=
new
TreeSet
<
String
>();
if
(
dictionary
.
length
()
==
0
||
wordLength
==
0
)
throw
new
EmptyDictionaryException
(
"File is empty"
);
//Setup for loading dictionary
FileReader
fr
=
new
FileReader
(
dictionary
);
...
...
@@ -37,6 +38,16 @@ public class EvilHangmanGame implements IEvilHangmanGame {
HashMap
<
Integer
,
SortedSet
<
String
>>
partition
=
new
HashMap
<
Integer
,
SortedSet
<
String
>>();
groupWords
(
partition
,
guess
);
int
finalKey
=
getGroupKey
(
partition
);
words
=
partition
.
get
(
finalKey
);
return
words
;
}
private
void
groupWords
(
HashMap
<
Integer
,
SortedSet
<
String
>>
partition
,
char
guess
){
for
(
String
word
:
words
)
{
int
count
=
0
;
int
hash
=
1
;
...
...
@@ -52,47 +63,22 @@ public class EvilHangmanGame implements IEvilHangmanGame {
);
partition
.
get
(
hash
).
add
(
word
);
}
}
private
int
getGroupKey
(
HashMap
<
Integer
,
SortedSet
<
String
>>
partition
){
int
maxSize
=
0
;
int
finalKey
=
0
;
for
(
Map
.
Entry
<
Integer
,
SortedSet
<
String
>>
entry:
partition
.
entrySet
()){
int
currSize
=
entry
.
getValue
().
size
();
SortedSet
<
String
>
currGroup
=
entry
.
getValue
();
int
currSize
=
currGroup
.
size
();
int
currKey
=
entry
.
getKey
();
if
(
currSize
==
maxSize
){
// 1. Choose the group in which the letter does not appear at all.
if
(
currKey
<
finalKey
)
finalKey
=
currKey
;
// 2. If each group has the guessed letter, choose the one with the
// fewest letters.
// 3. If this still has not resolved the issue, choose the one with the
// rightmost guessed letter.
// 4. If there is still more than one group, choose the one with the next
// rightmost letter. Repeat this step (step 4) until a group is
// chosen.
}
if
(
currSize
==
maxSize
)
if
(
currKey
<
finalKey
)
finalKey
=
currKey
;
if
(
currSize
>
maxSize
)
{
maxSize
=
currSize
;
finalKey
=
entry
.
get
Key
()
;
finalKey
=
curr
Key
;
}
}
words
=
partition
.
get
(
finalKey
);
//Add letter to the set
return
words
;
}
static
void
print
(
String
out
){
System
.
out
.
println
(
out
);
}
int
charCount
(
String
word
,
char
guess
){
int
count
=
0
;
for
(
int
i
=
0
;
i
<
word
.
length
();
i
++){
if
(
guess
==
word
.
charAt
(
i
))
count
++;
}
return
count
;
return
finalKey
;
}
@Override
...
...
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