Skip to content

Commit

Permalink
es02 4+5 refactored; ex6
Browse files Browse the repository at this point in the history
  • Loading branch information
kainoj committed Apr 10, 2018
1 parent c8f2451 commit 788dfe4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion es02/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ ex4:
python validator.py zad4 python3 ex4.py

ex5:
python validator.py zad5 python3 ex5.py
python validator.py zad5 python3 ex5.py

ex6:
echo Running As with non admissible heuristic
python validator.py zad5 python3 ex6.py
4 changes: 3 additions & 1 deletion es02/ex4.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ class Commando:
DIR = {"U": (-1, 0), "D": (1, 0), "L": (0, -1), "R": (0, 1), "B": (0, 0)}
MOVES = ["U", "D", "L", "R"]

def __init__(self, board, uncert=False):
def __init__(self, board, uncert=False, non_admissible=False):
self.board, self.goals, self.starts = self.stripBoard(board)

self.initState = ComaState(self.starts)

if uncert:
self.initState = self.uncertainty(self.initState)

self.non_admissible = non_admissible

def stripBoard(self, board):
"""
Expand Down
7 changes: 6 additions & 1 deletion es02/ex5.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ def computeF(self, state, goals):
Note: F = g = self.depth is just an ordinary BFS
"""
state.F = state.depth + max([self.dists[s] for s in state.state])
if self.non_admissible is True:
# Ex 6.
state.F = state.depth + sum([self.dists[s] for s in state.state])
else:
# Ex 5.
state.F = state.depth + max([self.dists[s] for s in state.state])
return state

def preProcessDists(self):
Expand Down
20 changes: 20 additions & 0 deletions es02/ex6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ex5 import Commando
from ex4 import readBoard
import sys


if __name__ == '__main__':

finput = 'zad_input.txt'
foutput = 'zad_output.txt'

if len(sys.argv) == 2:
finput = sys.argv[1]

board = readBoard(finput)

coma = Commando(board, non_admissible=True)
ans = coma.astar()

fout = open(foutput, "w")
print(ans, file=fout)

0 comments on commit 788dfe4

Please sign in to comment.