Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:move()缺少1个必需的位置参数:';HumanMove';_Python - Fatal编程技术网

Python TypeError:move()缺少1个必需的位置参数:';HumanMove';

Python TypeError:move()缺少1个必需的位置参数:';HumanMove';,python,Python,我的代码不起作用。它说必需的参数“HumanMove”。 我几乎不明白python想告诉我什么。 请参阅下面的代码 计算机在这行上安装了窃听器:HumanMove=self.HumanPlayer.move() 您使用参数HumanMove定义了move。调用该方法时,必须为该参数提供一个参数。您需要在move()中传递参数。谢谢,我会这样做的。 import random #Create player class class Player: def move(self):

我的代码不起作用。它说必需的参数“HumanMove”。 我几乎不明白python想告诉我什么。 请参阅下面的代码

计算机在这行上安装了窃听器:HumanMove=self.HumanPlayer.move()


您使用参数
HumanMove
定义了
move
。调用该方法时,必须为该参数提供一个参数。

您需要在
move()中传递参数。
谢谢,我会这样做的。
import random

#Create player class
class Player:
    def move(self):
        return 'rock'

    def learn(self, my_move, their_move):
        pass


#Create random player class
class RandomPlayer:
    def __init__(self):
        Player.__init__(self)

    def move(self, RandomPlayerMove):

        self.move = RandomPlayerMove
        #use imported random function
        RandomPlayerMove = random.randint(1,3) 

        #Computer choice is either rock, paper, or scissors 
        if RandomPlayerMove == ("Rock"): 
            print("The computer choses ROCK") 
        elif RandomPlayerMove == ("Paper"): 
            print("The computer choses PAPER") 
        else: 
            print("The computer choses SCISSORS") 

        #return value 
        return RandomPlayerMove 



#Create human player class        
class HumanPlayer:
    def __init__(self):
        Player.__init__(self)



    def move(self, HumanMove):
        return HumanMove



##class that remembers what move the opponent played last round
class ReflectPlayer:
    def __init__(self, ReflectPlayer):
        Player.__init__(self)
        self.ReflectPlayer = ReflectPlayer

    #def move
    def move(self, move):
        self.move = move

    def getmove(self, move):
        return self.move


#define cycleplayer class that remembers what move it played last round,
# and cycles through the different moves. 
class CyclePlayer:
    def __init__(self, CyclePlayer):
        Player.__init__(self)
        self.CyclePlayer = CyclePlayer

        self.human_player_history = {}  # stores the frequency of human player 
    moves
        for move in moves:
            self.human_player_history[move] = 0

    def move(self, max_move):
        max_move = max(self.human_player_history.items(), key=lambda elem: 
    elem[1])[0]
        if max_move == 'rock':
            return 'paper'
        if max_move == 'scissors':
            return 'rock'
        if max_move == 'paper':
            return 'rock' 


    def beats(one, two):
    return ((one == 'rock' and two == 'scissors') or
            (one == 'scissors' and two == 'paper') or
            (one == 'paper' and two == 'rock'))

#Create game class
class Game:
    def __init__(self, HumanPlayer, RandomPlayer):
        self.HumanPlayer = HumanPlayer
        self.RandomPlayer = RandomPlayer

    def play_round(self):
        HumanMove = self.HumanPlayer.move()
        RandomPlayerMove = self.RandomPlayer.move()
        print(f"HumanPlayer: {HumanMove}  RandomPlayer: {RandomPlayerMove}")
        self.HumanPlayer.learn(HumanMove, RandomPlayerMove)
        self.RandomPlayer.learn(RandomPlayerMove, HumanMove)

        if beats(HumanMove, RandomPlayerMove):
            print("HumanPlayer wins this round")
            self.HumanPlayer.score += 1

        elif beats(RandomPlayerMove, HumanMove):
            print("RandomPlayer wins this round")
            self.RandomPlayer.score += 1   
        else:
            print("It's Tie, Play again!")
            print(f"Scores, HumanPlayer: {self.p1.score} RandomPlayer: 
        {self.p2.score}")
    def move(self, HumanMove):
                   ^^^^^^^^^
        return HumanMove