gpt4 book ai didi

python - 恰好接受 1 个参数(给定 2 个)错误?

转载 作者:太空宇宙 更新时间:2023-11-04 10:18:18 25 4
gpt4 key购买 nike

所以我得到了脚本:

    piece = raw_input(self.Player1["Name"] + ", pick a piece to move. Enter the coordinates (ex. A3, D4, etc.)." + "\n")
coordinatesX = self.Chessboard.position_to_xCoor(piece)
coordinatesY = self.Chessboard.position_to_yCoor(piece)

其中 position_to_xCoor 是 Chessboard 对象中的一个方法,它是 Gameboard 类的一部分。

def position_to_xCoor(self, position):
for i in range(0, 8):
if listofrows[i] == position[0]:
row = i + 1
return row

它应该在棋盘上占据一个位置(例如 A1、D3、B4)并返回 x 坐标(因此 A 为 1,C 为 3,等等)。但是,每当我将“片段”输入传递给该方法时,我都会收到“只接受一个参数”错误。我做错了什么?

游戏板类:

class Gameboard(object):

Matrix = [[0 for x in range(9)] for j in range(9)]
Board = [[0 for x in range(9)] for j in range(9)]

listOfColumns = ["A", "B", "C", "D", "E", "F", "G", "H"]

def __init__(self):
for row in range(0, 9):
for column in range(0, 9):
self.Matrix[row][column] = Square(row, column)
self.Matrix[row][column].Occupied = True

for column in range(1, 9):
self.addPiece("Black", "Pawn", 1, column)
self.addPiece("White", "Pawn", 6, column)
row = 0
self.addPiece("Black", "Rook", row, 1)
self.addPiece("Black", "Knight", row, 2)
self.addPiece("Black", "Bishop", row, 3)
self.addPiece("Black", "Bishop", row, 6)
self.addPiece("Black", "Knight", row, 7)
self.addPiece("Black", "Rook", row, 8)

row = 7
self.addPiece("White", "Rook", row, 1)
self.addPiece("White", "Knight", row, 2)
self.addPiece("White", "Bishop", row, 3)
self.addPiece("White", "Bishop", row, 6)
self.addPiece("White", "Knight", row, 7)
self.addPiece("White", "Rook", row, 8)

self.addPiece("White", "Queen", 7, 4)
self.addPiece("White", "King", 7, 5)
self.addPiece("Black", "Queen", 0, 4)
self.addPiece("Black", "King", 0, 5)

def __str__(self):
row1 = 0
for number in range(8, -1, -1):
self.Board[row1][0] = number
row1 += 1

for row in range (0, 9):
for column in range(1, 9):
self.Board[row][column] = self.Matrix[row][column].Piece

displayBoard = ""
for row in range (0, 8):
displayBoard += " " + "---" * 13 + "\n"
for column in range(0, 9):
displayBoard += str(self.Board[row][column]) + " | "
displayBoard += "\n"
displayBoard += " " + "---" * 13 + "\n"
displayBoard += " "
for column in range(0, 8):
displayBoard += " " + self.listOfColumns[column] + " "

return displayBoard

def addPiece(self, color, piece_type, row, column):
Information = {
"Type" : piece_type,
"Color" : color,
}
self.Matrix[row][column].setPiece(ChessPiece(Information))

@staticmethod
def coor_to_position(a, b):
row = self.listofrows[a]
return row + str(b)

@staticmethod
def position_to_xCoor(self, position):
for i in range(0, 8):
if listofrows[i] == position[0]:
row = i + 1
return row

@staticmethod
def position_to_yCoor(position):
column = int(position[1])
return column

def validMove(color, piece, row1, column1, row2, column2):
slopes = {
"Bishop" : [1, -1], # can diagonally
"Knight" : [2, -2, 0.5, -0.5],
"King" : [0, 1, -1, 10], #10 signifies the vertical movement
"Pawn" : [10],
"Queen" : [1, -1, 0, 10], # can move across the board
"Rook" : [0, 10], # can move across the board
}

if (column1 - column2) != 0:
slope = (row2 - row1)/(column2 - column1)
if slope == any(self.slopes[piece.Type]): #Is the slope correct for the given piece?
Occupied = False
if piece.Type == "Bishop":
if slope == 1:
Occupied = blockedMove(color, piece, 1, 1, column1, column2, row1, row2)
else:
Occupied = blockedMove(color, piece, -1, 1, column1, column2, row1, row2)

if piece.Type == "Knight":
if (row2 - row1 == any([2, -2, 1, -1])):
if slope == any(slopes["Knight"]) and piece.Color != color:
Occupied = False
if piece.Type == "King":
if (row2 - row1 == any([1, -1])):
if slope == any([-1, 1, 0]) and piece.Color != color:
Occupied = False
if piece.Type == "Queen":
if slope == 1:
Occupied = blockedMove(color, piece, 1, 1, column1, column2, row1, row2)
if slope == -1:
Occupied = blockedMove(color, piece, -1, 1, column1, column2, row1, row2)
if slope == 0:
Occupied = blockedMove(color, piece, 0, 1, column1, column2, row1, row2)
if piece.Type == "Rook":
Occupied = blockedMove(color, piece, 0, 1, column1, column2, row1, row2)
if Occupied == False: #If all the spaces in the path are empty, return True
return True
else:
return False
elif (column1 - column2) == 0:
slope = 10
if slope == any(self.slopes[piece.Type]): #Is the slope correct?
Occupied = False
if piece.Type == "King":
if (row2 - row1 == any([1, -1])) and piece.Color != color:
Occupied = False
if piece.Type == "Pawn":
if color == "White":
if (row2 - row1 == any([1, 2])) and piece.Color != color:
Occupied = False
if color == "Black":
if (row2 - row1 == any([-1, -2])) and piece.Color != color:
Occupied = False
if piece.Type == "Queen":
Occupied = blockedMove(color, piece, 1, 0, column1, column2, row1, row2)
if piece.Type == "Rook":
Occupied = blockedMove(color, piece, 1, 0, column1, column2, row1, row2)
if Occupied == False: #If all the spaces in the path are empty, return True
return True
else:
return False

def blockedMove(color, piece, rise, run, column1, column2, row1, row2):
rise1 = rise
run1 = run
Occupied = False
if column2 > column1:
while row1 != row2 and column1 != column2 and Occupied == False:
column1 += run
row1 += rise
if self.Matrix[column1 + run1][row1 + rise1].Occupied == True:
Occupied = True
else:
while row1 != row2 and column1 != column2 and Occupied == False:
column1 -= run
row1 -= rise
if self.Matrix[column1 - run1][row - rise1].Occupied == True:
Occupied = True

if column1 == column2 and row1 == row2 and piece.Color != color and Occupied == False:
return False
else:
return True

最佳答案

您的 position_to_xCoor 被装饰为静态的,但将 self 作为第一个参数。静态方法没有 self 参数。

关于python - 恰好接受 1 个参数(给定 2 个)错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33965308/

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