Java代写 | COSC 1285 Assignment 2: Hangman

本次Java代写是实现一个hangman的儿童双人游戏
COSC 1285
Assignment 2: Hangman

Introduction
Hangman is a popular children 2-player game, where one player selects a word, phrase or
sentence and the other player guesses this by making a number of single letter guesses.
Each time the guessing player makes an incorrect guess (either letter or the whole
word/phrase/sentence), a part is added to a diagram (usually a hangman). The game
ends when either the guessing player guesses all the letters of the word correctly, guesses
the word/phrase/sentence correctly, or the diagram is complete. In this assignment you
will implement algorithms for the guessing player, that can solve hangman games and its
variants.
1 Learning Outcomes
This assessment relates to 3 learning outcomes of the course which are:
• CLO 1: Compare, contrast, and apply the key algorithmic design paradigms: brute
force, divide and conquer, decrease and conquer, transform and conquer, greedy,
dynamic programming and iterative improvement;
• CLO 3: Define, compare, analyse, and solve general algorithmic problem types:
sorting, searching, graphs and geometric; and
• CLO 5: Implement, empirically compare, and apply fundamental algorithms and
data structures to real-world problems.
Background
Hangman
In Hangman, the guessing player is given a word, phrase or sentence to guess. The length
of the word, phrase and sentence are given, and the guessing player makes a number
of single letter guesses to guess that unknown word, phrase and sentence. If a guess is
correct, the guessed letter in the unknown word will be revealed. If the guess is incorrect,
a piece is added to a drawing (typically a hangman), and if the hangman drawing is
complete, the guessing player loses. If all the letters of the word etc are correctly guessed
and revealed, then the guessing player wins.
In this assignment, we will implement a few different known strategies for the guessing
player and to explore and design algorithms for two variants of Hangman.
Random Guessing Strategy
This is the most basic strategy, but a good way to start the consideration of designing a
good Hangman guessing algorithm. In this strategy, the algorithm makes random guesses
of letters that it hasn’t guessed before. Consider it as sampling without replacement type
of guessing.
Dictionary Aware Statistics Strategy
This is a more advanced strategy. When we know the dictionary of words that Hangman
is generated from, we can compute statistics per letter of who many words they appear
in. We then guess according to the letter that appears in most words in the dictionary,
as that, if words are uniformly sampled from the dictionary, are most likely to result in
a correct letter guess.
Subsequently, the set of possible words are narrowed down according to each correct
guess. From the remaining possible words, we compute the frequency statistics again and
select the letter that is more frequent among the remaining possible words.
2
Hangman Variants
Two word Hangman
In this variant, instead of guessing one word, we guess two words, both from a known
dictionary.
This concludes the background. In the following, we will describe the tasks of this
assignment.
2 Tasks
The assignment is broken up into a number of tasks. Apart from Task A that should be
completed initially, all other tasks can be completed in an order you are more comfortable
with. Task D is considered a high distinction task and hence we suggest to tackle this
after you have completed the other tasks.
Task A: Implement Random guessing (5 marks)
To help to understand the problem and the challenges involved, the first task is to develop
a random guessing approach to Hangman game.
Task B: Implement Dictionary-Aware Guessing (8 marks)
In this task, you’ll implement the dictionary-aware guessing strategy.
Task C: Design and Implement Dictionary-Aware Guessing Strategy for Two Word Hangman (5 marks)
In this task, you’ll design and implement a guessing strategy/algorithm for the two word
Hangman variant.
Task D: Design and Implement an Algorithm for Wheel of Fortune Variant (6 marks)
In this task, you will implement an algorithm for the Wheel of Fortune Variant. We want
you to explore an algorithm for this.
3
3 Details for all tasks
To help you get started and to provide a framework for testing, you are provided with
skeleton code that implements some of the mechanics of the Hangman program. The main
class (RmitHangman.java) implements the main IO components the assignment, parsing
parameters and read in the details of the game. The list of main java files provided are
listed in Table 1.
file description
RmitHangman.java Class implementing basic IO and processing code. Do not modify, as we will
use this to do testing.
solver/HangmanSolver.java Abstract class for Hangman guessing
algorithms. Can add to, but don’t modify existing methods.
solver/RandomGuessSolver.java Class implementing the random guessing strategy (task A). Complete the implementation, particularly for IMPLEMENT ME! parts
solver/DictAwareSolver.java Class implementing the dictionaryware guessing strategy (task B). Complete the implementation, particularly
for IMPLEMENT ME! parts
solver/TwoWordHangmanGuessSolver.java Class implementing the two word hangman variant guessing strategy (task C).
Complete the implementation, particularly for IMPLEMENT ME! parts
solver/WheelOfFortuneGuessSolver.java Class implementing the Wheel of Fortune variant guessing strategy (task D).
Complete the implementation, particularly for IMPLEMENT ME! parts
game/HangmanGame.java Class implementing the mechanicisms
to run a hangman game. Do not modify, as we will use this to do testing.
trace/HangmanGameTracer.java Class to trace/log games. Do not modify, as we will use this to do testing.
Table 1: Table of supplied Java files.
We also strongly suggest to avoid modifying the “Do not modify” ones, as they form
the interface between the main class and algorithms. You may add java files and methods,
but it should be within the structure of the skeleton code, i.e., keep the same directory
structure and you must ensure they compile. Ensure your code and any modifications you
made to the structure compiles and runs on the core teaching servers. Note that the
onus is on you to ensure correct compilation and behaviour on the core teaching servers
4
before submission.
As a friendly reminder, remember how packages work and IDE like Eclipse will automatically add the package qualifiers to files created in their environments. This is a
large source of compile errors, so remove these package qualifiers when testing on the core
teaching servers and before submission.
Compiling and Executing
To compile the files, run the following command from the root directory (the directory
that RmitHangman.java is in):
javac *.java
Note we expect to be able to compile your implementation using the same command
on the core teaching server.
To run the framework:
java RmitHangman <hangman solver type> <dictionary filename> <maximum
incorrect number> <word(s) to guess> [(optional) game trace fileName]
where
• hangman solver type: type of Hangman solver, one of [random, dict, twoword,
wheel]
• dictionary filename: file of dictionary to use.
• maximum incorrect number: maximum number of incorrect guesses before game is
over.
• word/phrase to guess: word or phrase (in double quotes) to guess.
• game trace filename: Output file name of the trace of guessing.
The dictionary file should have one word per line (we provide a sample dictionary,
ausDict.txt, to get you started).
The word(s) to guess should be inputed in double quotes, and multiple words separated
by a space. For example, the following are valid command inputs:
java RmitHangman random ausDict.txt 7 “hello”
java RmitHangman twoword ausDict.txt 9 “hello bye” traceOutput.txt
3.1 Clarification to Specifications
Please periodically check the assignment FAQ for further clarifications about specifications. In addition, the lecturer will go through different aspects of the assignment each
week (typically via video recordings), so make sure to check the course material page on
Canvas to see if there are additional notes posted.
5
4 Assessment
The assignment will be marked out of 30.
The assessment in this assignment will be broken down into a number of components.
The following criteria will be considered when allocating marks. All evaluation will be
done on the core teaching servers.
Task A (5/30):
For this task, we will evaluate your implementation and algorithm on whether:
1. Implementation and Approach: It implements the random strategy to guess Hangman games.
2. Correctness: Over a large number of games, whether it has the same performance
(win/loss ratios, number of guesses for wins) as the standard implementation of
random guessing strategy.
Task B (8/30):
For this task, we will evaluate your implementation and algorithm on whether:
1. Implementation and Approach: It implements the dictionary-aware strategy to
guess Hangman games.
2. Correctness: Over a large number of games, whether it has the same performance
(win/loss ratios, number of guesses for wins) as the standard implementation of
dictionary aware guessing strategy. Note this is a deterministic algorithm, so performance should be the similar.
3. Efficiency: As part of correctness, your implementation should not take excessively
long to solve a puzzle. We will benchmark the running time against our nonoptimised solution and add a substantial margin on top, and solutions taking longer
than this will be timed out.
Task C (5/30):
For this task, we will evaluate your implementation and algorithm on whether:
1. Implementation and Approach: It takes a reasonable approach and can solve two
word Hangman games.
2. Correctness: Over a large number of games, whether statistically it has at least an
equal performance, in terms of win/loss ratios and number of guesses for wins, as
the standard implementations of two-word dictionary-aware guessing strategy.
3. Efficiency: As part of correctness, your implementation should not take excessively
long to solve a puzzle. We will benchmark the running time against our nonoptimised solution and add a substantial margin on top, and solutions taking longer
than this will be timed out.
4. Description of Approach: In addition to the code, you will be assessed on a description of your approach, which will help us to understand your approach (this
will help us with assessing the Implementation and Approach of all tasks). Include
6
how you approached solving two word Hangman and your rationale behind it. You
may cite other references you have researched upon and utilised the information
within. This should be no longer than 1 page and submitted as a pdf as part of
your submission. You will be assessed on the approach, its clarity and whether it
reflects your code.
Task D (6/30):
For this task, we will evaluate your implementation and algorithm on whether:
1. Implementation and Approach: It takes a reasonable approach and can Wheel of
Fortune Hangman games.
2. Performance: Over a large number of games, whether statistically it has equal or
greater performance, in terms of win/loss ratios and number of guesses for wins, as
our basic strategy for solving Wheel of Fortune games.
3. Efficiency: As part of correctness, your implementation should not take excessively
long to solve a puzzle. We will benchmark the running time against our nonoptimised solution and add a substantial margin on top, and solutions taking longer
than this will be timed out.