gpt4 book ai didi

java - 作业概览 说明

转载 作者:行者123 更新时间:2023-12-02 07:07:58 29 4
gpt4 key购买 nike

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

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

最佳答案

我将尝试在这里重申明显的(?)。老师给你提供了一个抽象类Player并要求你实现SimplePlayerRandomPlayer类。您应该实现各自的构造函数,并实现抽象方法和更新方法。

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

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

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

希望这有帮助,祝实现顺利。

关于java - 作业概览 说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15870402/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com