forked from mattjegan/PathFinder
/
PathFinder.py
58 lines (44 loc) · 1.7 KB
/
PathFinder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# PathFinder.py
#
# Original Author: Matthew J Egan
# Github: mattjegan/PathFinder
#
# This file sets up the Kivy application and instantiates
# the world that the agent runs in.
from Settings import Settings
from World import World
import kivy
from kivy.app import App
from kivy.clock import Clock
from kivy.config import Config
from sys import stdin
class PathFinder(App):
title = 'PathFinder'
def __init__(self):
super().__init__()
self.settings = Settings()
# If there is piped input
if not stdin.isatty():
try:
cli_settings = stdin.read().rstrip().split(' ')
self.settings.CELL_SIZE = int(cli_settings[0])
self.settings.NUM_OBSTACLES = int(cli_settings[1])
self.settings.GRID_WIDTH = int(cli_settings[2])
self.settings.GRID_HEIGHT = int(cli_settings[3])
self.settings.HEURISTIC = str(cli_settings[4])
self.settings.WINDOW_WIDTH = str(self.settings.CELL_SIZE * self.settings.GRID_WIDTH)
self.settings.WINDOW_HEIGHT = str(self.settings.CELL_SIZE * self.settings.GRID_HEIGHT)
Config.set('graphics', 'width', self.settings.WINDOW_WIDTH)
Config.set('graphics', 'height', self.settings.WINDOW_HEIGHT)
except:
raise IOError
def build(self):
Config.set('graphics', 'width', self.settings.WINDOW_WIDTH)
Config.set('graphics', 'height', self.settings.WINDOW_HEIGHT)
game = World(self.settings)
game.draw()
Clock.schedule_interval(game.update, self.settings.UPDATE_SPEED)
return game
if __name__ == "__main__":
PathFinder().run()