2013-04-08 36 views
0

我有一份学校作业。我发现这个描述很模糊......如果有人会仔细阅读并给我解释,或者用老师以外的其他语言解释每种方法,那么我们将不胜感激。作业要求如下...注意:我只是发现他的描述太模糊。所以没有即时通讯不要求code.thanks。作业概述说明

The players will be children of the following (partially defined) class: 

public abstract class Player implements Comparable{ 
    public String name; // name of player 
    public int id;  // identifier for the player 
    protected int wins; 
    protected int losses; 
    protected int ties; 

    public abstract String play(Player opponent); 
    // returns one of "rock", "paper", or "scissors" 

    public void update(String myGesture, 
         String opponentGesture, 
         Player opponent); 
    // this method will update the player's stats 
    // (wins, losses, ties) based on the gestures (inputs) 
    // for a recent game played against opponent (also input) 

    public Player(String name, int id){...} 
    // constructor that initializes player's name and id 
You will need to fill in the code for the constructor and the update methods for the Player class. You can add other "hidden" attributes and methods as you wish (Note: if you add things to Player, be sure it is something that ALL children classes will also use). You will also need to implement three classes that extend the Player class: 

public class SimplePlayer extends Player{...} 
// A SimplePlayer will always play the same 
// gesture (either rock, paper, or scissors) 
// in every game it plays, regardless 
// of who its opponent is. The gesture is 
// randomly chosen when the SimplePlayer is created. 


public class RandomPlayer extends Player{...} 
// A RandomPlayer will always play a random 
// gesture (rock, paper, or scissors) in 
// every game it plays, regardless of who 
// its opponent is. 


public class SmartPlayer extends Player{...} 
// A SmartPlayer will try to use past knowledge 
// of games played against a particular 
// opponent when playing them again. 
You can add any hidden attributes and methods to the children classes as you wish. 

编辑:由于此类实现了Comparable,play()是比较不同手势的方法吗?

+0

该网站主要是为了代码。这听起来像你应该问你的老师。 – chris 2013-04-08 02:39:23

+0

除非您有具体问题,否则我们无法为您提供帮助。这不是* Java翻译成简单英语的地方。例如,你知道'抽象类'是什么吗? – 2013-04-08 02:49:19

回答

1

我会尝试在此处重述明显的(?)。老师为您提供了一个抽象类Player,并要求您实施SimplePlayerRandomPlayer班。你应该实现相应的构造函数,并且实现抽象和更新方法。

SimplePlayer类需要使用随机手势进行引导。您需要随机选择其中一个手势,无论是摇滚,剪刀或纸张,并始终以play方法的输出形式返回。这意味着无论对手策略是什么SimplePlayer都需要保持不变。

反之RandomPlayer每次都需要返回一个随机策略;具体而言,play方法需要返回一个随机数。

update(...)方法可能是一个有趣的方法。根据当前玩家和对手策略,您需要更新结果。如果您不熟悉规则,请参阅here。简单来说,你可能必须有一堆if..else块来比较当前和对手的球员战略。

希望这会有所帮助,祝你好运。

+0

你能看到更新,并给我你的想法! – choloboy7 2013-04-08 16:00:24

1

我用自己的话重新写下了他所要求的内容,而不是我们能做的其他事情。

  • play()返回玩家选择的任何手势。

  • update()决定谁赢了,并且根据手势添加+1到他们的胜利,损失或者 。

  • 播放器()初始化播放器的名称和ID

  • SimplePlayer()初始化要使用的手势。这将保持 不变

  • RandomPLayer()初始化一个手势,使其在每个游戏 上随机播放。

  • SmartPlayer()根据玩家通常使用的对手 的手势来选择手势。