Skip to content

Commit

Permalink
es02 4+5 reading from file refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
kainoj committed Apr 10, 2018
1 parent 790e49e commit c8f2451
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 7 additions & 5 deletions es02/ex4.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def playBfs(self):

return self.traceback(state)

def readBoard(finput):
board = []
with open(finput) as f:
board = [list(line.strip('\n')) for line in f]
return board


if __name__ == '__main__':

Expand All @@ -151,11 +157,7 @@ def playBfs(self):
if len(sys.argv) == 2:
finput = sys.argv[1]

board = []
with open(finput) as f:
board = [list(line.strip('\n')) for line in f]

coma = Commando(board, uncert=True)
coma = Commando(readBoard(finput), uncert=True)

ans = coma.playBfs()
print(ans)
Expand Down
4 changes: 1 addition & 3 deletions es02/ex5.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def astar(self):
if len(sys.argv) == 2:
finput = sys.argv[1]

board = []
with open(finput) as f:
board = [list(line.strip('\n')) for line in f]
board = ex4.readBoard(finput)

coma = Commando(board)
ans = coma.astar()
Expand Down

0 comments on commit c8f2451

Please sign in to comment.