[SOLVED] 代写 algorithm Scheme game Java graph software Go COMP1022P Assignment:

30 $

File Name: 代写_algorithm_Scheme_game_Java_graph_software_Go_COMP1022P_Assignment:.zip
File Size: 687.66 KB

SKU: 6754740129 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


COMP1022P Assignment:
Resources
Starting project
Sample demo program (no source code)
Demo procedures (will be posted here; please refresh this webpage after its release)
到时发给你
Mastermind
Submission method Frequently asked questions
Please check the sample demo program and FAQ first before you ask for clarifications. For fairness, we also won’t debug or fix your coding problems for anyone as explained in FAQ.
Introduction
可以查⼀一下,感觉对了了解问题很有帮助
You are going to complete a classic board game called Mastermind in this assignment. Some background information about the game may be found here if you are interested in that. While there are different variations of the game, you will need to follow exactly what is described in this assignment description for this assignment.
There are 2 parts of this game. You are only required to finish the part 1 and submit it before the part 1 deadline on or before 11:59:00am, Nov 9th (Saturday morning), and then demonstrate your work during your lab section on Nov 12th – 15th (you must go to the lab section to which you are officially enrolled). For part 2, the submission deadline is 11:59:00am, Nov 23th (Saturday morning), and the demonstration shall be done during your lab section on Nov 26th – 29th. Demonstration is required for getting your assignment score after you submit your work to Canvas. No demo make-up will be arranged unless you have received prior email approval from Wallace or your instructor, or you are absent due to a justified reason (e.g. sick leave, with a medical certificate as the proof).
The demo procedure for each part will be posted on this page a day after the deadlines, i.e.,
Part 1 demo procedure will be posted here sometime on Nov10th (Sunday) afternoon. Part 2 demo procedure will be posted here sometime on Nov24th (Sunday) afternoon.
You are required to study and practice the demo procedure before you attend your demo session to make sure you know how to demo your work properly and smoothly. Your demo time is limited. Procedure will be posted and announced before the demo sessions.
After you have finished Part 1, you are advised to start Part 2 as soon as you can. Due to the packed schedule, no postponement of the deadlines is possible, so please start early.
The board
A mastermind game board looks like this at the beginning:

The top row is reserved for the special characters which will be introduced later.
第⼀一⾏行行预留留给special characters,稍后将介绍这些字符。
在它下⾯面,有两个区域被中间的棕⾊色块(即 Block ojects)分隔开。
The left 7×3 region is the play area where any of the 4 peg objects (i.e. the Wombat, Dolphin, Pig, and Elephant objects) can be placed by the user to guess the secret. 左边的7×3区域是游戏区,在这⾥里里⽤用户可以放置4个peg objects
(即袋熊 Wombat、海海豚 Dolphin、猪 Pig 和⼤大象 Elephant objects)中的任何⼀一个来猜测密码。
The right 7×3 region is the balloon area where a judge would put balloons (i.e. the YellowBalloon and OrangeBalloon objects) to indicate how
correct the user guess is. 右边的7×3区域是⽓气球区域,在这⾥里里裁判会放⽓气球(即YellowBalloon和Orange Ballon ojects)来指出我们猜测的正确程度。
There are 3 judges, and a naughty guy sitting at the top-left on the top-row brown blocks. From left to right, they are the Judge, the NiceJudge,
FriendJudge, and the NaughtyGuy. 有3名裁判,在第⼀一排棕⾊色积⽊木的左上⻆角坐着⼀一个淘⽓气的家伙。从左到右,他们是Judge,NiceJudge,FriendJudge,和NaugthyGuy。
The secret
密码
When the game starts (i.e. when the Mastermind world is being constructed), a secret will be chosen randomly. The secret is a string that represents the peg sequence that the user has to guess. The secret string always consists of exactly 3 lowercase characters, and each character represents a peg at the corresponding position. ‘w’ represents a wombat peg, ‘d’ represents a dolphin peg, ‘p’ represents a pig peg, and ‘e’ represents an elephant peg. For example,
Just below it, there are two areas that are separated by the brown blocks (i.e. the Block objects) in the middle.
“wde” represents
当游戏开始时(例例如,当Mastermind World正在构建时),⼀一个密码将被随机选择。 秘密是⼀一个字符串串,它表示⽤用户必须猜测的动物的序列列。 密码字符串串总是由3个⼩小写字符组成,每个字符表示对应位置的⼀一个peg。 “w”代表⼀一个袋熊 Wombat,“d”代表⼀一个海海豚 Dolphin,“p”代表⼀一个猪 Pig,“e”代表⼀一个⼤大象 Elephant。 例例如,“wde”表示
Guessing the secret
The user can guess the secret by placing pegs to the play area. It is illustrated as follows.
⽤用户可以通过在游戏区域放置动物来猜测这个秘密。如下图所示。

Create a new peg object (any of the 4):
e.g. right click on Pig and choose “new Pig()”
Place it to the play area:

What it looks like after completing the guess (3 pegs in a row) that represents “pdw”:
猜完代表“pdw”的动物后(连续猜3个)后,它是这个样⼦子的:

Judging the guess
After placing the pegs to the play area, any of the 3 judges can be asked to judge the guess and provide feedback with balloons.
In the following illustration, we will continue with our last example where the user guessed “pdw”. Also, assume the random secret is “wde”. Right-click on the first judge (Judge) and choose “void judgeRow(int row)” of “Judge”:
在把球钉放到游戏区后,3位裁判中的任何⼀一位都可以被要求判断猜测的结果,并⽤用⽓气球提供反馈。 在下⾯面的插图中,我们将继续我们的最后⼀一个示例例,其中⽤用户猜测“pdw”。 另外,假设随机的密码是“wde”。右击第⼀一个裁判(judge),选择“裁判”的“void judgeRow(int row)”:

On the dialog that just appears, input the row number that you want the judge to look at. Notice that the row number starts from 1 as the row 0 is used by the judges and the naughty guy. That is, the first row in the play area is row 1, and the last row in the play area is row 7. After inputting the row number, click “OK”.
在刚刚出现的对话框中,输⼊入您希望裁判判断的⾏行行号。 注意⾏行行号从1开始,因为第0⾏行行被裁判和淘⽓气的家伙使⽤用。 也就是说,游戏区域的第⼀一⾏行行是第1⾏行行,游戏区域的最后⼀一⾏行行是第7⾏行行。 输⼊入⾏行行号后,单击“OK”。
Then, the judge result will be shown on the same row in the balloon area. The judge result is “1 orange balloon” as there is only one correctly guessed peg (the dolphin peg in the 2nd position). Different judges have different judging criteria. Those different criteria will be explained in another section.
然后,判断结果将显示在⽓气球区域的同⼀一⾏行行。 裁判结果为“1只橙⾊色⽓气球”,因为只猜对了了⼀一只动物(第⼆二名的海海豚 d)。 不不同的评委有不不同的评判标准。这些不不同的标准将在另⼀一节中解释。

Testing the static methods
You will complete many static methods. To test them, you may call them from the menu that can be invoked by right-clicking on the corresponding class item on the right.
您将完成许多静态⽅方法。要测试它们,您可以从菜单中调⽤用它们,右键单击右侧相应的类项即可调⽤用菜单。

Part 1 requirements
Download the starting project, and complete the implementation of following methods:
In the MastermindWorld class:
public static void initialize()
public static void generateSecret() public static void clearBalloons(int row) public static void clearAllBalloons()
In the Judge class:
public void judgeRow(int row) public void judgeCurrentRow() public void judgeAllRows()
Read the detailed descriptions of those methods here. You are welcome to add new methods and variables if you think they would be helpful. Part 2 requirements
Continue with the finished work you did in part 1, and complete the implementation of following methods:
In the MastermindWorld class:
public static void saveGame() throws Exception public static void loadGame() throws Exception public static void showScore()
public static int calculateRowScore(int row) public static int calculateMaxScore()
public static void updateHighscores() throws Exception (optional bonus part; see here for explanation) In the NiceJudge class:
public void judgeRow(int row) In the FriendJudge class:
public void judgeRow(int row) In the NaughtyGuy class:
public void cheat() public void superCheat()

Read the detailed descriptions of those methods here. You are welcome to add new methods and class properties if you think they would be helpful.
Submission
For each part, you must zip your whole mastermind assignment folder and submit the zip file only. For how to zip the whole folder, you may refer to the video here (for Windows 7) or here (for MacOS). Only a zip file should be uploaded – not rar file, not 7z file, not tar file, etc.. You may make multiple submissions and only the latest submission will be graded.
You will be using Canvas to submit your zip file. Go here for Part 1 or here for Part 2. You should submit your work early to avoid any kind of submission problem in the last minute.
After your submission, you must download your submitted zip file back from Canvas, unzip it, and open it in Greenfoot to make sure it works. It is very important because submitting the wrong file may give you zero mark for all the hardwork you put in.
There will be a penalty of -1 point (out of a maximum 100 points) for every minute you are late for the first 30 minutes. For instance, since the deadline of part 1 is 11:59:00 on Nov 9th, if you submit your solution at 12:20:00 on the same day, there will be a penalty of -21 points from your assignment part 1. After the first 30 minutes, until exactly 24 hours after the deadline (i.e. 11:59:00am on Nov 10th for part 1), the penalty remains -30 points. However, if you are late for more than 24 hours, you will get 0 for your assignment. The lowest grade you may get from an assignment is zero: any negative score after the deduction due to late penalty (and any other penalties) will be reset to zero.
About plagiarism
If you get caught cheating, both you and the other person get zero for the assignment. It doesn’t matter if you only copied a little. UST rules say that the penalty is the same for both people. There may also be additional penalties other than just getting zero for the assignment. You are responsible for keeping your own work safe from being accessed or “referenced” by others in any way. However, discussing with others is fine as that’s different from direct copying. Also be reminded that the plagiarism detection software are very robust nowadays, and on top of that we will also examine your works manually.
FAQ
1. Q: My code doesn’t work / there is an error, here is the code, can you help me fix it?
A: As the assignment is a major course assessment, to be fair, you are supposed to work on it on your own and we should not finish the tasks for you. We might provide some very general hints to you, but we shall not fix the problem for you.
2. Q: Some strange problem happens with the Greenfoot. For example, the terminal/console window doesn’t open properly. What can I do? A: In that case, you may try to use the latest version here. Windows users may use the standalone version on that page.
3. Q: When I tried to drag the NaughtyGuy, the Block under the NaughtyGuy was dragged instead. What to do?
A: Apparently this is a Greenfoot-version-specific problem when a newer version of Greenfoot (e.g. 3.6) is used. In that case, you can
simply drag the Block away and then drag the NaughtyGuy. In the demo session, we don’t mind you doing that as well, so don’t worry.
4. Q: Can I produce extra output in the console? Can I change the given code? Can I use an alternative approach?
A: Yes, yes, and yes. As long as your work fulfills all the written description. It is recommended that you follow our suggested approach, but feel free to use an alternative one. However, during the live demo session, we may ask you to make changes to your code so that the secret is always a certain secret (e.g. “pwd”) for testing purposes – you need to be confident that you know your own code very well so that you can make the changes correctly in your alternative solution. Again, demo procedure will be released beforehand, so be prepared.

Part 1 requirements
For all the methods, you may also try the demo program to see what is expected. After reading the descriptions carefully and checking with the demo program, you are welcome to ask us for clarification if the requirement is still unclear to you. We also maintain a FAQ for frequently asked questions, if any, at the bottom of the previous page.
In the MastermindWorld class:
public static void initialize()
This method is called in the MastermindWorld constructor as you can see from the provided source code. It should create the initial board by placing the objects in the world exactly as shown below. Read the previous description to see what each object is. 从提供的源代码可以看到,这个⽅方法在MastermindWorld构造函数中被调⽤用。
它应该通过将对象精确地放置在世界中来创建初始板,如下所示。阅读前⾯面的描述,看看每个对象是什什么。
Hint: You may use the static method “MastermindWorld.addObject” to easily add an object to the world. Read the
documentation of the method (above the method in the code) to learn how to use it. Those provided methods are
already completed and you are not required to understand the code inside them to utilize them.
提示:您可以使⽤用静态⽅方法“MastermindWorld”。addObject可以很容易易地向世界添加对象。 请阅读该⽅方法的⽂文档(在代码中的⽅方法之上)以了了解如何使⽤用它。这些提供的⽅方法已经完成,您不不需要理理解其中的代码来使⽤用它们。
public static void generateSecret()
This method is also called in the MastermindWorld constructor. It is used to generate a 3-character secret and put that to the static variable “secret” and also print it out on the terminal.

此⽅方法也在MastermindWorld构造函数中调⽤用。它⽤用于⽣生成⼀一个3个字符的密码,并将其放⼊入静态变量量“secret”中,然后在终端上打印出来。
If implemented correctly, the secret is very likely to be different everytime you restart your program by clicking the “Reset” button at the bottom of Greenfoot as it is randomly chosen.
如果运⾏行行正确,每次通过单击Greenfoot底部的“Reset”按钮重新启动程序时,密码很可能是不不同的,因为它是随机选择的。
Hint: Use the provided method “getRandomNumber” to generate a random number in a specific range. A usual, read its documentation for usage instruction. Think about how to use a random number to pick a random peg character (i.e., ‘w’, ‘d’, ‘p’, or ‘e’). 提示:使⽤用提供的⽅方法“getRandomNumber”⽣生成特定范围内的随机数。⼀一个常⻅见的,阅读其⽂文档使⽤用说明。
考虑⼀一下如何使⽤用⼀一个随机数来选择⼀一个随机的动物peg字符(即:“w”、“d”、“p”或“e”)。
Hint: Use “+” to append a character to the end of secret. For example, the statement secret = secret + ‘w’; can be used to add the character ‘w’ to the end of the secret. Repeat that 3 times, and you will have “www” in the secret. Be reminded to set the secret to an empty string first, i.e., secret = “”;
Hint: Use System.out.println(“The secret is ” + secret); to print the message in the terminal. 提示:使⽤用“+”将字符附加到secret的末尾。例例如,语句句secret = secret + ‘w’;可以⽤用来添加字符“w”的秘密结束。
重复三次,你就会得到密码中的“www”。提醒您⾸首先将secret设置为空字符串串,即, secret = “”;
public static void clearBalloons(int row) 使⽤用system.out.println(“The secret is ” + secret), 在终端打印消息。
It removes all the existing balloons in the balloon area on the specified row (specified by a row number). Other rows should not be affected.
它删除指定⾏行行(由⾏行行号 row number 指定)上的⽓气球区域中的所有现有⽓气球。其他⾏行行不不应该受到影响。
Note: You can assume that the “row” parameter is always in the valid range of [1,7].
注意:您可以假设“row”参数总是在[1,7]的有效范围内。
Hint: Use the “removeBalloons” method. Read the documentation in the code for its usage instruction.
提示:使⽤用“移除⽓气球”⽅方法。请阅读代码中的⽂文档了了解其使⽤用说明。
public static void clearAllBalloons()
It removes all the existing balloons in the balloon area on all rows. 它将移除所有⾏行行上⽓气球区域中的所有现有⽓气球。
In the Judge class:
public void judgeRow(int row)
Judge the row as specified by the parameter. Among the 3 different judges, the Judge’s rule is the simplest. Only orange balloons will be placed as the feedback. An orange balloon is placed when a peg is guessed completely correctly (both the type (i.e. which animal it is) and position). The orange balloons should be placed left-aligned in the balloon area on the same row. The following is an example. Assume the secret is “wde”.
You guess “edp” by placing the pegs (elephant, dolphin, pig) in the play area on the first row (i.e. row 1):
判断由参数指定的⾏行行。在三个不不同的裁判中,法官的规则是最简单的。只有橙⾊色的⽓气球将被放置作为反馈。 当⼀一个动物完全被猜对了了(动物的类型(即它是哪种动物)和位置),就会放⼀一个橙⾊色的⽓气球。 橙⾊色的⽓气球应该放置在⽓气球区域的同⼀一⾏行行左对⻬齐。下⾯面是⼀一个例例⼦子。假设秘密是“wde”。

Then you run the “judgeRow” method from the Judge (the left-most judge at the top), and input 1 as the parameter.
然后从Judge(顶部最左边的Judge)运⾏行行“judgeRow”⽅方法,并输⼊入1作为参数。
The feedback will be shown in the balloon area. Since the secret is “wde” and the guess is “edp”, only the 2nd peg is guessed completely correctly, so the feedback is “1 orange balloon”. Notice that the orange balloon is placed left-aligned in the balloon area on the same row.
反馈将显示在⽓气球区域。因为密码是“wde”,猜测是“edp”,所以只有第⼆二个动物d的猜测是完全正确的, 所以反馈是“1个橙⾊色的⽓气球”。请注意,橙⾊色⽓气球被放置在同⼀一⾏行行的⽓气球区域的左对⻬齐位置。

Then you try another guess on the second row (i.e. row 2). The guess this time is “pde”.
然后再猜第⼆二⾏行行(即row 2),这次猜的是“pde”。

And you run the “judgeRow” method with parameter being 2.
The result is “2 orange balloons” as the second peg and the third peg are guessed completely correctly.
然后运⾏行行参数为2的“judgeRow”⽅方法。 结果是“2个橙⾊色的⽓气球”,作为第⼆二个和第三个peg是完全正确的猜测。

You try another guess on the 3rd row (i.e. row 3). The guess this time is “wde”.
你再猜第三⾏行行(即row 3),这次猜的是“wde”。

And you run the “judgeRow” method with parameter being 3.
You get “3 orange balloons” as all 3 pegs are guessed completely correctly.
然后运⾏行行参数为3的“judgeRow”⽅方法。 你得到“3个橙⾊色的⽓气球”,因为所有3个动物都猜对了了。

Note: for simplicity, you can assume that when the method is called on row N, the row N already has exactly 3 pegs placed in the play area. 注意:为简单起⻅见,可以假设在第N⾏行行调⽤用该⽅方法时,第N⾏行行已经恰好有3个动物位于 play area。
Note: before placing the balloons, any existing balloon that is on the same row should be removed first through the use of the “MastermindWorld.clearBalloons” method which is to be completed by you. Because of that, in the source code we provided to you, the method “MastermindWorld.clearBalloons” is called at the beginning of the “judgeRow” method.
注意:在放置⽓气球之前,任何在同⼀一⾏行行的⽓气球都应该先通过MastermindWorld。⽤用“MastermindWorld.clearBalloons”⽅方法移除。因此,在我们提供给您的源代码中, Note: You can assume that the “row” parameter is always in the valid range of [1, 7]. 有⼀一个⽅方法叫做“MastermindWorld”。clear”在
注意,你可以假设”row”的有效范围是[1,7] “judgeRow”⽅方法的开头被调⽤用。 Hint: Use the “MastermindWorld.getObjectChar” and “MastermindWorld.addObject” methods. Read the documentation
in the code for their usage instructions.
提示:使⽤用“MastermindWorld”。getObjectChar”和“MastermindWorld。addObject”⽅方法。请阅读代码中的⽂文档以获得它们的使⽤用说明。
Hint: To get a character from the secret, you may use “MastermindWorld.secret.charAt(x)” where x is the character index (starts from 0) of the character that you want to retrieve. For example, assume the secret is “wde”, “MastermindWorld.secret.charAt(0)” will return ‘w’ and “MastermindWorld.secret.charAt(2)” will return ‘e’.
提示:要从secret获取字符,可以使⽤用“MastermindWorld.secret.charAt(x)”,其中x是要检索的字符的字符索引(从0开始)。例例如,假设密码 是“wde”,“MastermindWorld.secret.charAt(0)”将返回“w”,⽽而“MastermindWorld.secret.charAt(2)”将返回“e”。
public void judgeCurrentRow()
Judge the row which the judge is currently located at.
判断当前裁判所在的⾏行行。
For example, if the board is like the following at first. Notice that we have manually dragged the judge to row 2. You can assume the user would always drag the Judge to the middle column.
例例如,如果⿊黑板⼀一开始像下⾯面这样。注意,我们已经⼿手动将judge拖到第2⾏行行。您可以假设⽤用户总是将法官拖到中间⼀一列列。

Calling the method “judgeCurrentRow” would give the following where only row 2 has been judged (assume the secret is “dwp”):
调⽤用这个⽅方法“judgeCurrentRow”, 只会判断了了第2⾏行行(假设密码是“dwp”):

public void judgeAllRows()
Judge all the rows. You can assume every row is either totally complete with 3 pegs or have nothing on it.
For example, if the board is like this at first:
判断所有的⾏行行。你可以假设每⼀一⾏行行要么是完全完整的3个动物,要么什什么都没有。例例如,如果⼀一开始⿊黑板是这样的:

Calling the method “judgeAllRows” would give the following (assume the secret is “dwp”):
调⽤用⽅方法“judgeAllRows”将得到以下结果(假设密码是“dwp”):

Part 2 requirements
For all the methods, you may also try the demo program to see what is expected. After reading the descriptions carefully and checking with the demo program, you are welcome to ask us for clarification if the requirement is still unclear to you. We also maintain a FAQ for frequently asked questions, if any, at the bottom of the previous page.
In the NiceJudge class:
It is the second judge at the top. It inherits from Judge, that means you can use all the public methods that are defined there.
这是第⼆二位裁判。它继承了了Judge,这意味着你可以使⽤用这⾥里里定义的所有public⽅方法。 public void judgeRow(int row)
Judge the row as specified by the parameter. 判断由参数指定的⾏行行。
Similar to the Judge in part 1, put the balloons in the balloon area on the same row. 与第1部分的判断相似,将⽓气球放在同⼀一⾏行行的⽓气球区域。
NiceJudge uses both orange balloons and yellow balloons. Orange balloons mean a peg was guessed completely correctly, i.e., both its position and type are correct.
NiceJudge既使⽤用橙⾊色的⽓气球,也使⽤用⻩黄⾊色的⽓气球。橙⾊色的⽓气球表示动物完全猜对了了。它的位置和类型都是正确的。
Yellow balloons are for the pegs that are guessed partially correctly – the type is correct but wrong position. Note that yellow balloons are only awarded for pegs that are not awarded with orange balloons.
⻩黄⾊色的⽓气球是指那些部分被猜对的动物——类型是正确的,但是位置是错误的。请注意,⻩黄⾊色的⽓气球只授予没有授予橙⾊色⽓气球的动物。 To help you understand the rules, refer to the following example. The secret is “wde”.

Notice that, in the example above at row 6, only 1 yellow balloon has been awarded for the elephant peg for its correct
type (but wrong position). Even tho there are 2 elephant pegs in the guess, there is only 1 elephant in the secret.
请注意,在上⾯面的第6⾏行行示例例中,只有获得了了1个⻩黄⾊色⽓气球,⽤用于指示类型正确(但位置错误)的⼤大象。即使有两个⼤大象放在play area,但是密码只有⼀一个⼤大象。 Note: The orange balloons always appear before (i.e. on the left-hand side of) the yellow balloons, and all balloons have to be left-aligned in the balloon area just like what the Judge does in part 1.
注意:橙⾊色的⽓气球总是出现在⻩黄⾊色⽓气球之前(即在左边),所有的⽓气球必须在⽓气球区域内左对⻬齐,就像第⼀一部分中裁判所做的那样。
To make your task easier, you may follow the algorithm below for counting how many yellow balloons and orange balloons should be placed. However, you are welcome to use your own algorithm if you want.
为了了让你的任务更更简单,你可以按照下⾯面的算法来计算应该放置多少个⻩黄⾊色⽓气球和橙⾊色⽓气球。但是,如果您愿意,欢迎您使⽤用⾃自⼰己的算法。
2.数⼀一数我们应该分发 1. 多少个橙⾊色的⽓气球。
将结果存储到⼀一个变量量中,
⽐比如O。
2. 3.
Y. 1. 数⼀一数我们应该分发的⻩黄⾊色⽓气球的数量量,假设我们根本不不分发任何橙⾊色⽓气球。 只需使⽤用我们提供的“getnumberofyellow”⽅方法,并将结果存储到⼀一个变量量(⽐比如Y)中。
Count the number of yellow balloons that we should give out, assuming we do not give out any orange balloon at all. Simply use the “getNumberOfYellowBalloons” method that we provided, and store the result to a variable, say,
Count the number of orange balloons that we should give out. Store the result to a variable, say, O.
Update Y with “Y = Y – O”, because a yellow balloon is only awarded to a peg when the peg wasn’t awarded with
an orange balloon already. ⽤用“Y = Y – O”来更更新Y,因为⼀一个⻩黄⾊色的⽓气球只有在没有奖励的时候橙⾊色⽓气球的时候才会奖励给⼀一个动物 Now, O and Y respectively store the number of orange balloons and th。e number of yellow balloons that you need
to place. 现在,O和Y分别存储你需要的橙⾊色⽓气球的数量量和⻩黄⾊色⽓气球的数量量 到另⼀一个地⽅方。
4.
In the FriendJudge class:
It is the third judge at the bottom. It inherits from Judge, that means you can use all the public methods that are defined
It should be the same as the one in NiceJudge class except for one difference – the orange balloons are always placed at the exact positions of the pegs that are guessed completely correctly. That is, by looking at the position of the orange balloons, the player would know which particular pegs are guessed completely correctly. The yellow balloons can be placed anywhere that is available (i.e. anywhere that is not already occupied by other balloons) and the balloons do not have to be left-aligned this time.
To help you understand the rules, refer to the following example. The secret is “wde”.
它应该和NiceJudge班上的那个是⼀一样的,除了了⼀一个不不同之外——橙⾊色的⽓气球总是被放在正确的位置上, ⽽而且猜对了了。也就是说,通过观察橙⾊色⽓气球的位置,玩家将知道哪些特定的动物被猜对了了。 ⻩黄⾊色的⽓气球可以放置在任何地⽅方(即没有被其他⽓气球占⽤用的地⽅方),⽽而且⽓气球这次不不必左对⻬齐。
there.
这是第三个裁判。它继承了了Judge,这意味着你可以使⽤用这⾥里里定义的所有公共⽅方法。 public void judgeRow(int row)

You can see that in the last row (row 7), two orange balloons were given at the last and the second last position. That means the dolphin peg (at the second last position) and the elephant peg (at the last position) are completely correctly guessed. 你可以看到在最后⼀一⾏行行(第七⾏行行),在最后⼀一个位置和第⼆二个最后⼀一个位置有两个橙⾊色的⽓气球。
这意味着海海豚(最后第⼆二个位置)和⼤大象(最后⼀一个位置)是完全正确的猜测。
In the second row (row 2), it shows that the last elephant peg is completely correctly guessed according to the orange balloon. There are also 2 yellow balloons at the beginning which means the other 2 pegs (dolphin and wombat) have the correct types but the positions of them are incorrect.
The player has to first move (drag and drop it with the mouse) the NaughtyGuy object from the top to the location where he/she wants the correct peg to reveal (in the play area), then run the “cheat” method. The procedure is illustrated below. Assume the secret is “wde”.
玩家必须⾸首先移动(⽤用⿏鼠标拖放)NaughtyGuy对象从顶部到他/她想要显示正确peg的位置(在play area), 然后运⾏行行“cheat”⽅方法。该过程如下图所示。假设秘密是“wde”。
In the NaughtyGuy class:
The player can use the NaughtyGuy to cheat.
在第⼆二⾏行行(第⼆二⾏行行),它表明,最后⼀一个⼤大象是完全正确的猜测根据橙⾊色⽓气球。还有两个⻩黄⾊色的⽓气球在开始, 这意味着其他两个动物(海海豚和袋熊)有正确的类型,但他们的位置是不不正确的。
public void cheat()

Note: You can assume that the NaughtyGuy is always dragged to a valid (empty) position in the play area when “cheat” is run. 注意:您可以假设,当运⾏行行“cheat”时,总是将NaughtyGuy拖到play区域的有效(空)位置。
Note: After the cheating is done, the NaughtyGuy should move itself back to its original location at the bottom as shown in the last screenshot. 注意:当cheat完成后,NaughtyGuy应该移动到底部的原始位置,如最后⼀一个截图所示。
Hint: Use the Actor methods “getX”, “getY”, and “setLocation” as NaughtyGuy is an Actor. See the documentation of those methods h⻅见er附e录.
提示:使⽤用Actor⽅方法“getX”、“getY”和“setLocation”,因为NaughtyGuy是⼀一个Actor。请参阅这些⽅方法的⽂文档。 public void supercheat()
“supercheat” is similar to “cheat”, but it shows even more. It reveals the whole row where the NaughtyGuy is at. The procedure is illustrated below. Assume the secret is “wde”.
“supercheat”与“cheat”类似,但它表现得更更多。它揭示了了整⾏行行,因为那个淘⽓气的家伙在哪⾥里里。该过程如下图所示。假设秘密是“wde”。

Note: You can assume that the NaughtyGuy is always dragged to a valid (empty) position in the play area when “supercheat” is run. 注意:你可以假设当运⾏行行“supercheat”时,NaughtyGuy总是被拖到⼀一个有效的(空的)位置。
Note: After the reveal is done, the NaughtyGuy should move itself back to its original location at the bottom.
In the MastermindWorld class:
注意:在显示完成后,NaughtyGuy应该把⾃自⼰己移回它原来在底部的位置。

public void saveGame() throws Exception
Save the secret and the current game board to the file “save.txt” (which is located right under the project directory).
将密码和当前游戏板保存到⽂文件“Save.txt”(它位于项⽬目⽬目录下)。
The first line is the secret string. The remaining 56 lines store what to be placed on each of the 56 cells on the 8×7 game board (including the judges, naughty guy, pegs, and balloons; but blocks are not saved). The format of those 56 lines is always a character that represents the object (or ‘x’ for nothing) that has to be placed at the specified position, followed by a space, then the x-position, followed by a space, then the y-position. For example, the line “p 0 2” indicates that there is a pig at the position (0, 2) and the line “x 4 3” indicates that there is nothing at the position (4, 3). The characters used are the ones listed as constants in the MastermindWorld like MastermindWorld.PIG (‘p’) and MastermindWorld.NOTHING (‘x’). Blocks (i.e., ‘b’) should NOT be saved. If a location only has a Block, then save ‘x’ instead of ‘b’ for that location. If a location has both a Block and a Judge/NaughtyGuy, save the Judge/NaughtyGuy only.
第⼀一⾏行行保存)
Note: You can use the “getObjectChar” method to get the character representing the object or nothing (‘x’) at the specified location. If the specified location has both a Judge/NaughtyGuy and a Block, the Judge/NaughtyGuy character will be returned by “getObjectChar”. This is desirable because you do not need to save the Block objects in save.txt.
注意:您可以使⽤用“getObjectChar”⽅方法来获取在指定位置表示对象或不不表示对象的字符(‘x’)。如果指定的位置有⼀一个Judge/NaughtyGuy和⼀一个Block, Judge/NaughtyGuy字符将由“getObjectChar”返回。这是可取的,因为您不不需要将块对象保存在save.txt中。
public void loadGame() throws Exception
Load the secret and the game board from the file “save.txt”. The game board has to be cleared first using the “removeAllNonBlockObjects” method. Then, create and place the objects according to the data loaded from “save.txt”
using the “addObject” method. 从⽂文件“save.txt”中加载秘密和游戏板。⾸首先必须使⽤用“removeAllNonBlockObjects”⽅方法清除游戏板。 然后,根据从“save”中加载的数据创建并放置对象。使⽤用“addObject”⽅方法。
For the file format, see save.txt. 有关⽂文件格式,请参阅save.txt(附录2)
是秘密字T符he串串s。av剩e下.tx的t 5re6p⾏行行r存es储en了了ts要t放he置f在oll8oxw7游in戏g b板o上ar的d:56个单元格中的每个单元格上的内容(包括judge、naughtGuy、动物和⽓气球; 但是棕⾊色块没有被 这56⾏行行代码的格式通常是⼀一个字符,表示必须放在指定位置的对象(或“x”表示空),然后是空格,然后是x位置,然后是空格,最后是y位置。 例例如,⾏行行“p 0 2”表示有⼀一头猪在位置(0,2)和⾏行行“x 4 3”表示没有什什么位置(4,3)。所使⽤用的字符的列列为MastermindWorld像MastermindWorld.Pig(‘p’)和 MastermindWorld.NOTHING(“x”)。Blocks(譬如,“b”)不不应保存。如果⼀一个位置只有⼀一个块,那么保存该位置的“x”⽽而不不是“b”。 如果⼀一个位置有⼀一个Block和⼀一个Judge/NaughtyGuy,只保存Judge/NaughtyGuy。Save.txt 表示以下⾯面板:

public static int calculateRowScore(int row)
It calculates and returns the score of the specified row according to the current board. 它根据当前板计算并返回指定⾏行行的分数。
The formula for the score is (numberOfOrangeBalloons*3 + numberOfYellowBalloons)
分数计算公式为(numberoforangeballoon *3 + numberofyellowballoon) numberOfOrangeBalloons and numberOfYellowBalloons are the counts of the orange/yellow balloons in the specified
row.
If row is outside of the valid range [1,7], then it simply returns 0 as the score.
如果row在有效范围[1,7]之外,那么它只返回0作为分数。 For examples, with the following board:
calculateRowScore(0) should return 0. calculateRowScore(1) should return 9. calculateRowScore(2) should return 5. calculateRowScore(3) should return 5. calculateRowScore(4) should return 0. calculateRowScore(5) should return 2. calculateRowScore(6) should return 1.
numberoforange和numberofyellowballoon是指定⾏行行中橙⾊色/⻩黄⾊色⽓气球的数量量。

calculateRowScore(7) should return 6.
public static int calculateMaxScore()
It returns the maximum score of all rows. For the same example we used above, the calculateMaxScore() will return 9. If there is no balloon at all on the broad, then it simply returns 0.
它返回所有⾏行行的最⾼高分。对于上⾯面使⽤用的相同示例例,calculateMaxScore()将返回9。如果在⾯面板上根本没有⽓气球,那么它只返回0。 public static void showScore()
It shows the player’s current score (using calculateMaxScore()) together with a comment at the top-right corner.
它显示了了玩家当前的分数(使⽤用calculateMaxScore())和右上⻆角的注释。
The comment should be “Get good!” for score within [0,3], or “Good!” for score within [4,6], or “Excellent!” for score within [7,9].
对于[0,3]内的分数,评论应该是“Get good!”,对于[4,6]内的分数,评论应该是“good!”,对于[7,9]内的分数,评论应该是“Excellent!”。 For example, with the following board, the score is 6 according to calculateMaxScore(): 例例如,如下图所示,根据calculateMaxScore(),得分为6:
Running the showScore() method shows the message at the top-right corner:
运⾏行行showScore()⽅方法会在右上⻆角显示消息:

You may use the provided showMessage() method to display a message at the top-right corner.
The message should always be in the format “You scored (SCORE)! (COMMENT)” as shown above.
您可以使⽤用提供的showMessage()⽅方法在右上⻆角显示消息。 信息的格式应该是“You scored (SCORE)!”(COMMENT)“如上所示。
public static void updateHighscores() throws Exception (optional bonus part; see here for explanation)
There is a highscore.txt under the project directory. Here is an example h⽂文ig件h⾥里里sc⾯面or只e有.tx:t. 6 3 2 在项⽬目⽬目录下有⼀一个highscore.txt。这是⼀一个例例⼦子
The file always contains just three numbers that are separated by single spaces. The first number is the highest score, the second number is the second highest score, and the last number is the third highest score.
该⽂文件始终只包含三个数字,⽤用单个空格分隔。第⼀一个数字是最⾼高分,第⼆二个数字是第⼆二⾼高分,最后⼀一个数字是第三⾼高分。
When the method “updateHighscores” is ran, the following should happen:
运⾏行行“updateHighscores”⽅方法时,应发⽣生以下情况:
1. Use “calculateMaxScore” to calculate the current player’s score. 1. 使⽤用“calculateMaxScore”来计算当前玩家的分数。
updated scores to the “highscore.txt” file. The file should always store the top 3 scores, in descending order, and nothing else. 如果当前分数⾼高于任何⼀一个现有的⾼高分,则更更新highscore.txt 并保存
将分数更更新为“最⾼高分”。该⽂文件应该总是按降序存储前3个分数,⽽而不不存储其他内容。
Example 1: if the “highscore.txt” originally stores “6 3 2” and the player’s current score is 9, then the “highscore.txt” should store “9 6 3” after the method is ran.
例例1:如果“highscore.txt“原来存储的是”6 3 2“,⽽而玩家当前的分数是9,那么“highscore.txt“应该存储”9 6 3″后的⽅方法运⾏行行。
Example 2: if the “highscore.txt” originally stores “6 3 2” and the player’s current score is 4, then the “highscore.txt” should store “6 4 3” after the method is ran.
2. Load the 3 highest scores from the “highscore.txt” file.
3. If the current score is higher than any one of the existing high scores, update the high scores and save the
例例2:如果“highscore.txt“原来存储“6 3 2”,玩家当前的分数是4,然后“⾼高分”。txt”应该存储”6 4 3″后的⽅方法运⾏行行。
2. 从“highscore.txt”加载3个最⾼高的分数

Example 3: if the “highscore.txt” originally stores “6 3 2” and the player’s current score is 1, then the “highscore.txt” should store “6 3 2” after the method is ran. (no change)
例例3:如果“highscore.txt“原来存储“6 3 2”,玩家当前的分数是1,然后“⾼高分”。txt”应该存储”6 3 2″后的⽅方法运⾏行行。(没有变化)

Introduction to Computing with Java COMP1022P [2-0-2:3]
Menu
Home
Course Information Teaching staff
Grading and Bonus scheme Lecture notes and schedule Labs and schedule
About Final Exam
About Midterm Exam Assignments
Greenfoot resources Self-learning center Downloads
附录1:
Greenfoot resources Greenfoot installation
Greenfoot setup program for Microsoft Windows, Download 3.1.0 (includes JDK)
Greenfoot setup program for Microsoft Windows, Portable Version Download 3.1.0 (includes JDK) Greenfoot setup program for Mac OS X, for 10.8.3 or later Download 3.1.0 (includes JDK)
Greenfoot troubleshooting:
About new versions of Greenfoot: there is a newer version of Greenfoot available on the official website https://www.greenfoot.org/. If you use that instead to open our samples, you may be asked if you want to update your code. Just choose “Yes, update my code.”.
About terminal not showing up:: if you cannot see the console or terminal, hold down the shift button, then right-click the Greenfoot Terminal on the taskbar, try “maximize” or “move”. Alternatively, you may use the latest version downloaded from the official website. Link can be found in the previous paragraph.
COMP1022P_GreenfootStartUpProject.zip
Greenfoot tutorials
A step-by-step tutorial to Install and use Greenfoot (if JDK is needed, please follow from step 1; otherwise, start from step 2)
Using Greenfoot in CS Labs (Room 4213)
Using Greenfoot in ITSC Barns (Barn A, B and C)
Greenfoot start up project
COMP1022P_GreenfootStartUpProject.zip

Greenfoot API documentation
In this course, students are only required to learn a selected number of methods defined in the Greenfoot APIs. The list of API methods is summarized in the following table:
Class Name
Method Name
int getRotation();
void setRotation(int angle);
void act();
void setImage(String fileName);
int getX();
int getY();
void setLocation(int x, int y);
void setDirection( int direction );
int getDirection();
boolean canMove(int numOfSteps);
void move(int numOfSteps);
Constants:
Creature.EAST = 0; Creature.WEST = 1; Creature.NORTH = 2; Creature.SOUTH = 3;
int width() int height()
Description
Get the angle of rotation Set the angle of rotation
The act method is called by the Greenfoot framework to give actors a chance to perform some useful actions
Set the image of the actor.
Example: setImage(“wombat.jpg”);
Get the x-coordinate of the current actor
Get the y-coordinate of the current actor
Assign a new location for this actor
Set the current direction of the creature object
Get the current direction of the creature object
Return true if the move can be completed successfully. Otherwise, return false
Move the object using the current direction by the given number of steps
Pre-requesite: canMove(numOfSteps) returns true
Example
api_rotation.zip
A simple Greenfoot example to demonstrate “getRotation”, “setRotation” and “act” methods
api_location.zip
A simple Greenfoot example to demonstrate “getX”, “getY” and “setLocation” methods
Actor
Creature (extends Actor)
api_creature.zip
An example to program rotating picobot along the boundary of the world. It uses a combination of methods/constants defined in the Creature class
GWorld
Get the width of the world Get the height of the world
A simple Greenfoot example to change the width and the height of the world to 12 (the default value is 8)
api_gworld_width_height.zip

void removeOneObject(Actor obj)
void addOneObject (Actor obj, int x, int y)
Actor getOneObjectAt(int x, int y, String actorClassName)
int random(int lowerLimit, int upperLimit)
Actor[] getAllObjects(String actorClassName)
void removeObjectsFromWorld(Actor[] objArray)
Remove one actor object from the world
Add one actor object to the world
Get one object at the location specified by x and y coordinates and its class name
Return null if the actor object cannot be located at the given position
An example to illustrate “removeOneObject”, “addOneObject” and “getOneObjectAt” methods
Generate a random number
definied by the upper and
the lower limits (both limits
are inclusive) api_random_picobots.zip
Get all objects and store them to an array
An example to create a random number of picobots and demonstrate how to remove all picobots from the
Remove all objects from the world world
api_add_remove_objects.zip
Last modified on 09/19/2019 12:29:03
Maintained by COMP1022P Teaching Team
(Best viewed with resolution 1024×768)

wde j00 w01 d02 w03 p04 d05 e06 e07 n10 d11 w12 e13 p14 w15 e16 d17 f20 e21 e22 d23 p24 p25 p26 e27 c30 x31 x32 x33 x34 x35 x36 x37 x40 o41 o42 o43 x44 y45 y46 o47 x50 o51 y52 y53 x54 y55 x56 o57 x60 o61 y62 y63 x64 x65 x66 x67
附录2:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 algorithm Scheme game Java graph software Go COMP1022P Assignment:
30 $