2013-04-08 62 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()根據玩家通常使用的對手 的手勢來選擇手勢。