Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add use case where player is on goal (symbol '+') #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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))