Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sokoban.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ def transferToGameState(layout):
elif layout[irow][icol] == 'B': layout[irow][icol] = 3 # box
elif layout[irow][icol] == '.': layout[irow][icol] = 4 # goal
elif layout[irow][icol] == 'X': layout[irow][icol] = 5 # box on goal
elif layout[irow][icol] == '+': layout[irow][icol] = 6 # player on goal
colsNum = len(layout[irow])
if colsNum < maxColsNum:
layout[irow].extend([1 for _ in range(maxColsNum-colsNum)])
return np.array(layout)

def PosOfPlayer(gameState):
"""Return the position of agent"""
return tuple(np.argwhere(gameState == 2)[0]) # e.g. (2, 2)
return tuple(np.argwhere((gameState == 2) | (gameState == 6))[0]) # e.g. (2, 2)

def PosOfBoxes(gameState):
"""Return the positions of boxes"""
Expand All @@ -57,7 +58,7 @@ def PosOfWalls(gameState):

def PosOfGoals(gameState):
"""Return the positions of goals"""
return tuple(tuple(x) for x in np.argwhere((gameState == 4) | (gameState == 5))) # e.g. like those above
return tuple(tuple(x) for x in np.argwhere((gameState == 4) | (gameState == 5) | (gameState == 6))) # e.g. like those above

def isEndState(posBox):
"""Check if all boxes are on the goals (i.e. pass the game)"""
Expand Down Expand Up @@ -282,4 +283,4 @@ def readCommand(argv):
else:
raise ValueError('Invalid method.')
time_end=time.time()
print('Runtime of %s: %.2f second.' %(method, time_end-time_start))
print('Runtime of %s: %.2f second.' %(method, time_end-time_start))