Skip to content

Commit

Permalink
es02 ex03 final
Browse files Browse the repository at this point in the history
  • Loading branch information
kainoj committed Apr 11, 2018
1 parent 2c0e0c3 commit b28d3be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 115 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__/
data/
*.gz
*.txt
*.txt
es*/.vscode/
112 changes: 0 additions & 112 deletions es02/.vscode/.ropeproject/config.py

This file was deleted.

14 changes: 12 additions & 2 deletions es02/ex3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
import heapq
import queue
import sys
from math import sqrt

class Sokoban(ex2.Sokoban):

def dist(self, a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])

def dist2(self, a, b):
x = a[0] - b[0]
y = a[1] - b[1]
return sqrt(x**2 + y**2)

def computeH(self, state):
"""
Computes heuristic function and retruns modified (soko) state
state.h = state.depth <=> BFS
"""
state.h = state.depth
d = [min([self.dist(b, g) for g in self.goals]) for b in state.boxes]
state.h = sum(d)/len(d)
return state

def bestFirstSearch(self):
Expand Down Expand Up @@ -71,5 +82,4 @@ def bestFirstSearch(self):
ans = soko.bestFirstSearch()
fout = open(foutput,"w")
print(ans, file=fout)
print(ans)

0 comments on commit b28d3be

Please sign in to comment.