0

我有一个学校作业。我发现描述很模糊......如果有人会阅读它并给我他们的解释或简单地用老师以外的语言解释每种方法,将不胜感激。作业要求如下... 注意:我只是觉得他的描述太模糊了。所以我不要求代码。谢谢。

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() 会是比较不同手势的方法吗?

4

2 回答 2

1

我用我自己的话改写了他的要求,我们无能为力。

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

  • update() 确定谁赢了,并根据手势为他们的赢、输或平加 + 1。

  • Player() 初始化玩家名字和id

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

  • RandomPLayer() 将手势初始化为在它玩的每个游戏中都是随机的。

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

于 2013-04-08T03:01:15.550 回答
1

我会尝试在这里重述显而易见的(?)。老师为你提供了一个抽象类Player,并要求你实施SimplePlayerRandomPlayer上课。您应该实现各自的构造函数,并实现 abstract 和 update 方法。

该类SimplePlayer需要使用随机手势进行引导。您需要随机选择一种手势,无论是石头、剪刀还是纸,并将其作为play方法的输出始终如一地返回。这意味着无论对手的策略是什么,都SimplePlayer需要保持不变。

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

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

希望这会有所帮助,并祝您实施顺利。

于 2013-04-08T03:03:16.203 回答