私は助けが必要です。私のコードは異なるノードのリストを生成していません。むしろ、それらはすべて同じであり、その理由はわかりません。
def init(logger, playerId, numWalls, playerHomes):
"""
Part 1 - 4
The engine calls this function once at the beginning of the game.
The student player module uses this function to initialize its data
structures to the initial game state.
Parameters
logger: a reference to the logger object. The player model uses
logger.write(msg) and logger.error(msg) to log diagnostic
information.
playerId: this player's number, from 1 to 4
numWalls: the number of walls each player is given initially
playerHomes: An ordered tuple of player locations
A location is a 2-element tuple of (row,column).
If any player has already been eliminated from
the game (rare), there will be a bool False in
that player's spot in the tuple instead of a
location.
returns:
a PlayerData object containing all of this player module's data
"""
class Node:
#online lecture notes for class
"""
Node represents a node in a graph using adjacency lists.
Node.name is a String.
Node.neighbors is a ListOfNode.
"""
__slots__ = ( 'name', 'neighbors' )
def __init__(self, name):
"""
__init__: Node * String -> None
Constructs a node object with the given name and no neighbors.
"""
self.name = name
self.neighbors = []
NodeList = []
row = 0
col = 0
while row < 9:
while col < 9:
Node.name = (row,col)
Node.neighbors = neigh(Node.name)
print(str(Node))
NodeList.append(Node)
col = col + 1
print(str(Node.name))
print(str(Node.neighbors))
col = 0
row = row + 1
count = 0
print(NodeList[0])
print(Node.neighbors)
def neigh(node):
name=node
if name == (0, 0): #top left corner
neighbors = [ None, ( 0+1, 0 ), ( 0, 0+1), None]
elif name == (0, 8): #top right corner
neighbors = [ None, ( 0+1, 8 ), None, (0, 8-1)]
elif name == (8, 0): #bot left corner
neighbors = [ (8-1, 0) , None, (8, 0+1), None]
elif name == (8, 8): #bot right corner
neighbors = [ (8-1, 8), None, None, (8,8-1)]
elif name[0] < 1:
neighbors = [ None, (name[0]+1, name[1] ), (name[0], name[1]+1 ), (name[0], name[1]-1)]
elif name[0] > 7:
neighbors = [ (name[0]-1, name[1] ), None, (name[0], name[1]+1 ), (name[0]-1, name[1]-1)]
elif name[1] < 1:
neighbors = [ (name[0]-1, name[1] ), (name[0]+1, name[1] ), (name[0], name[1]+1 ), None]
elif name[1] > 7:
neighbors = [ (name[0]-1, name[1] ), (name[0]+1, name[1] ), None, (name[0], name[1]-1)]
else:
neighbors = [ (name[0]-1, name[1] ), (name[0]+1, name[1] ), (name[0], name[1]+1 ), (name[0], name[1]-1)]
return neighbors
init(1, 1, 1, 1)