作业概述说明

时间:2013-04-08 02:36:17

标签: java oop

我有一份上学的任务。我觉得这个描述很模糊......如果有人会阅读它并给我他们的解释或者只是用老师的话来解释每个方法,我们将不胜感激。作业要求如下......注意:我只是觉得他的描述太模糊了。所以不,我不要求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()是比较不同手势的方法吗?

2 个答案:

答案 0 :(得分:1)

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

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

  • update()确定谁赢了,并为他们的胜利,损失或者加上+ 1          根据手势打平。

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

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

  • RandomPLayer()在每场比赛中将手势初始化为随机                它会播放。

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

答案 1 :(得分:1)

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

SimplePlayer类需要使用随机手势进行自举。您需要随机选择其中一种手势,无论是摇滚,剪刀还是纸张,并将其作为play方法的输出一致地返回。这意味着无论对手战略是什么SimplePlayer都需要保持不变。

相反,RandomPlayer每次都需要返回一个随机策略;具体来说,play方法需要返回一个随机方法。

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

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