首页 > > 详细

讲解Java程序、Java设计辅导、辅导Java设计、Java编程调试

Following is an example of the expected display of this command:
$startadvancedgame 10,lskywalker,artoo
Initial stone count: 10
Stones display:
Player 1: Luke Skywalker
Player 2: R2 D2
10 stones left:
Luke’s turn - which to remove?
3 2
8 stones left:
R2’s turn - which to remove?
6 stones left:
Luke’s turn - which to remove?
1 2
4 stones left:
R2’s turn - which to remove?
2 stones left:
Luke’s turn - which to remove?
5 1
1 stones left:
R2’s turn - which to remove?
Game Over
R2 D2 wins!
$
Any invalid input listed below shall be caught by try / catch syntax, and a line stating Invalid move.
should be printed out:
c The University of Melbourne 2018 7
invalid position; given N stones when the game commences, the position should be [1;N], any
other values are invalid;
invalid number of stones; the number should be either 1 or 2, any other values are invalid;
the stones at the speci ed positions have already been removed
Here is an example output:
6 stones left:
Luke’s turn - which to remove?
12 1
Invalid move.
6 stones left:
Luke’s turn - which to remove?
1 3
Invalid move.
6 stones left:
Luke’s turn - which to remove?
2 2
Invalid move.
6 stones left:
Luke’s turn - which to remove?
1 2
Invalid move.
6 stones left:
Luke’s turn - which to remove?
After implementing the game rules, you are also required to design the strategy for the AI player.
Because the game rules change in the advanced Nim game, the victory guaranteed strategy designed for
the original Nim game does not work in this new game. Your task here is to implement the AI in this
new game. The hints are: if the AI player is the rst one who moves when the game commences,
there is always a victory guaranteed strategy for the AI player; if the AI player is not the rst
one who moves when the game commences, it is still possible for the AI player to win as long as
the rival player does not play exactly following the winning strategy. Hence, the implementation of the
strategy for the AI player in this game should enable the AI player to:
win if it moves rst when game commences,
win if it moves second, given that the rival player does not follow exactly the wining strategy.
The details of the strategy are left for you to design. To simplify the code design, you may assume
a maximum of 11 stones in each game played. In order to get bonus marks, you need to
implement the strategy to meet all of the below requirements:
Your AI player class who can play the advanced game should be named as NimAIPlayer, please
note this name is case sensitive and mandatory;
Your AI player class should have a constructor with no parameters;
Your AI player class should implement the interface Testable (provided), which is listed as follows:
c The University of Melbourne 2018 8
public interface Testable {
public String advancedMove(boolean[] available, String lastMove);
}
Here, the boolean[] available represents the stones remained to be removed, true as remained
and false as removed, e.g., can be represented as [true false false false true]. The
lastMove represents the last move made by the rival player, e.g., if the rival player removed the
second stone in the last turn, then lastMove is of value \2 1", if the second and the third stones are
removed in the last turn, then lastMove is of value \2 2". The advancedMove() method returns
the move chosen by your AI player this turn, in the form. of position number. For example, if
your AI player chooses to remove the rst and the second stones, the returned string should be \1 2".
The de nition of this interface should be put into your source directory as a le named Testable.java
and submitted together with your solution. The victory guaranteed strategy designed by
you should be implemented in this advancedMove() method. This method will be invoked
when we test the correctness of your implementation of the victory guaranteed strategy.
Overall, your AI player class will look like (provided):
public class NimAIPlayer implements Testable ... {
// you may further extend a class or implement an interface
// to accomplish the task in Section 2.6
public NimAIPlayer() {}
...
public String advancedMove(boolean[] available, String lastMove) {
// the implementation of the victory
// guaranteed strategy designed by you
...
}
...
}
Your solution will be evaluated using test cases in three cases:
1. Your AI player moves rst to play against a dummy player, who moves randomly;
2. Your AI player moves rst to play against an oracle AI player, who enumerates all the possibilities
and try best to win;
3. Your AI player moves second to play against a dummy player, who moves randomly;
The solution will be assessed based on the wining ratio of your solution in the three cases. Figure 1
shows the testing procedure of a submitted solution. Speci cally, for three cases, case 1, case 2 and case
3, 0.5 marks will be granted ONLY if your AI winning ratio is 100% in each case, suggesting your AI
player passes all the test cases. Otherwise, a non-100% ratio for any case will not get any marks for that
particular case.
Checklist For Solution
Blank line and whitespace related issues
Make sure in terms of format, your output matches with the expected output on the submission
system.
c The University of Melbourne 2018 9
testing
sources
your
sources
test system
generated
submitted
classes
generated
testing
sources
winning
ratio
call
Figure 1: How testing on the advanced Nim game solution works; the testing procedure of the task in
Section 2.6, the submitted codes will be complied and run together with the testing sources, while the
generated testing classes will generate the winning ratio of the submitted solution.
File I/O mechanism related issues
Make sure your program runs ne no matter whether the players.dat le exists.
Make sure every exit command triggers data to be written to the players.dat le.
Polymorphism related issues
Make sure the AI player is implemented using inheritance mechanism.
Make sure you are leveraging the polymorphism to invoke the methods, i.e., using object
declared in parent class to invoke methods overridden in the child class.
If attempting for bonus marks, make sure the advanced game is implemented using either
inheritance or interface mechanism
Victory guaranteed strategy related issues
Make sure your AI player can play without errors whether it plays as the rst one or second
one to move.
Try your best to win as many test cases as possible on the submission system with your AI
player.
Submission issues
Make sure there is only one Scanner object throughout your program.
Other issues
The wining ratio of players with 0 games is 0.
The maximum number of players can be set as 100.
The maximum number of stones in each game is assumed to be 11 for the task of Section 2.6.
Collections such as ArrayList are acceptable.
Players are by default sorted according to the lexicographical order of the usernames.
Usernames can be assumed to be all lower-cased.
\What it means when lastMove is a blank String/null in the advanced Nim game?"
It means that there is no last move and your NimAIPlayer object is to make the rst move.
\My code works perfectly on my machine but it does not get any winning ratio in the last test."
First, check the FAQ items above and make sure you have handled each of them. Second,
make sure that you do not change the Boolean array input parameter in advancedMove().
We just need your move returned as a String, and we will update the Boolean array.
c The University of Melbourne 2018 10
Important Notes About Submission
Immediately after you make a submission using the \submit" command, computer automatic test will
be conducted on your program by automatically compiling, running, and comparing your outputs for
several test cases with generated expected outputs. The automatic test will deem your output wrong if
your output does not match the expected output, even if the di erence is just having an extra space or
missing a comma. Therefore it is crucial that your output follows exactly the same format shown
in the examples above.
The keyword import is available for you to use standard java packages. However, please DO NOT
use the package keyword to organise your source les into packages. The automatic test system cannot
deal with packages. If you are using Netbeans as the IDE, please be aware that the project name may
automatically be used as the package name. Please remove the line like
package ProjC;
at the beginning of the source les before you submit them to the system.
Please use ONLY ONE Scanner object throughout your program. Otherwise the automatic test will
cause your program to generate exceptions and terminate. The reason is that in the automatic test,
multiple lines of test inputs are sent all together to the program. As the program receives the inputs, it
will pass them all to the currently active Scanner object, leaving the rest Scanner objects nothing to read
and hence cause run-time exception. Therefore it is crucial that your program has only one Scanner
object. Arguments such as \It runs correctly when I do manual test, but fails under automatic test"
will not be accepted.
3 Your Task
Implement the new version of Nimsys in Java according to the above speci cation. Speci cally, it includes
following subtasks:
1. try / catch syntax to detect the listed invalid inputs in Section 2.2;
2. le based mechanism for player data as described in Section 2.3;
3. the AI player implemented using polymorphism mechanism in Section 2.4;
4. the victory guaranteed strategy in the original Nim game for the AI player in Section 2.5;
5. (bonus) the advanced Nim game and the corresponding victory guaranteed strategy for AI players
in Section 2.6. This is a challenging task. If you cannot work out the strategy, do not get stuck on
it. Please complete all other tasks rst and leave it as the last one.
6. See LMS for a detailed marking scheme.
4 Assessment
This project is worth 10% of the total marks for the subject. Remember that there is a 50% hurdle
requirement (i.e. 20/40) for the three projects.
Please note that if you attempt the bonus task, you can get 1.5 bonus marks. The total mark for Project
C is up to 11.5. However, the total mark for the three projects cannot exceed 40. This is a challenging
task and it takes time to complete, please allocate your time wisely.
The deadline for the project is 3pm, Friday 25 May, 2018. The allowed time is more than enough
for completing the project. Late submissions will NOT be accepted.
c The University of Melbourne 2018 11
Your Java program will be assessed based on correctness of the output as well as quality of code imple-
mentation. See LMS for a detailed marking scheme.
5 Submission
The entry point of your program should be in a class called Nimsys (in a le called Nimsys.java). Thus,
your program will be invoked via:
java Nimsys
Your Java classes should be stored together in their own directory under your home directory on the
student server. Then, you can submit your work using the following command:
submit 90041 projC *.java
Note that you must submit all Java les you have used for your project, not just Nimsys.java.
If you submit you code multiple times, the later submission will overwrite the previous one. If you submit
all your java source codes and then modify one source code, you need to submit all of your source codes
again, not just the modi ed one.
You should then verify your submission using the following command. This will store the veri cation
information in the le ‘feedback.txt’, which you can then view:
verify 90041 projC > feedback.txt
You should issue the above commands from within the same directory as where your project les are
stored (to get there you may need to use the cd ‘Change Directory’ command). Note that you can submit
as many times as you like before the deadline.
How you edit, compile and run your Java program is up to you. You are free to use any editor or
development environment. However, you need to ensure that your program compiles and runs
correctly on the student servers.
The test cases used to mark your submissions will be di erent from the sample tests given. You should
test your program extensively to ensure it is correct for other input values with the same format as the
sample tests. The tests for section 2.5 are hidden.
Submit your program to the student servers a couple of days before the deadline to ensure that they
work (you can still improve your program). \I can’t get my code to work on the student server
but it worked on my Windows machine" is not an acceptable excuse for late submissions.
6 Individual Work
Note well that this project is part of your nal assessment, so cheating is not acceptable. Any form. of
material exchange, whether written, electronic or any other medium is considered cheating, and so is
the soliciting of help from electronic newsgroups. Providing undue assistance is considered as serious
as receiving it, and in the case of similarities that indicate exchange of more than basic ideas, formal
disciplinary action will be taken for all involved parties. A sophisticated program that undertakes deep
structural analysis of Java code identifying regions of similarity will be run over all submissions in
\compare every pair" mode.
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!