Skip to content

Commit

Permalink
bit comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-atul committed Nov 11, 2020
1 parent 112997f commit 1f937e1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions astar.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ def getDistances(self, goal, current, snake):
if self.collides((x, y), snake):
continue

distances.put((self.moves + abs(x - goal_x) + abs(y - goal_y),
path))
gn = self.moves
hn = abs(x - goal_x) + abs(y - goal_y)
fn = gn + hn

# add to queue
distances.put((fn, path))

return distances

Expand Down
8 changes: 4 additions & 4 deletions components.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def position(self):
class Food(object):
""" Food with random location """
def __init__(self, window, snake, char=FOOD_CHAR):
self.x = randint(10, MAX_X - 10)
self.y = randint(10, MAX_Y - 10)
self.x = randint(10, MAX_X)
self.y = randint(10, MAX_Y)
self.char = char
self.window = window
self.snake = snake
Expand All @@ -29,8 +29,8 @@ def render(self):
self.window.addstr(self.y, self.x, self.char)

def reset(self):
self.x = randint(10, MAX_X - 10)
self.y = randint(10, MAX_Y - 10)
self.x = randint(10, MAX_X)
self.y = randint(10, MAX_Y)

if self.collides():
self.reset()
Expand Down
2 changes: 1 addition & 1 deletion constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
HEIGHT = 30
MAX_X = WIDTH - 5
MAX_Y = HEIGHT - 5
TIMEOUT = 100
TIMEOUT = 60
SNAKE_LEN = 5
SNAKE_X = SNAKE_LEN + 1
SNAKE_Y = 3
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def startGame():

if snake.head.x == food.x and snake.head.y == food.y:
snake.eatFood(food)
curses.beep()

event = astar.getKey(food, snake)
# print(event)
Expand Down

0 comments on commit 1f937e1

Please sign in to comment.