Permalink
Browse files

Replaced inefficient A* in Python with a C++ built Windows executable…

…. Plus some fixes.
  • Loading branch information...
1 parent 1d4994d commit f4e69b5c5b445780df10350a17acfaf90c86487d @Aramgutang committed Jan 29, 2011
Showing with 21 additions and 12 deletions.
  1. BIN AStar.exe
  2. BIN assets/levels.png
  3. +9 −9 lingua/entities/peasant.py
  4. +6 −1 lingua/utils/__init__.py
  5. +1 −1 lingua/utils/astar.py
  6. +1 −1 play.py
  7. +4 −0 setup.py
View
BIN AStar.exe
Binary file not shown.
View
BIN assets/levels.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
18 lingua/entities/peasant.py
@@ -2,36 +2,34 @@
from random import randint
from . import Person
-from ..utils import fstar
+from ..utils import astar
STARTS = []
HOMES = []
TARGETS = []
WHARFS = [(53, 430), (104, 253), (264, 80)]
-ACTIVE_PEASANTS = 4
+ACTIVE_PEASANTS = 40
class Peasant(Person):
def __init__(self, levels, position, game):
super(Peasant, self).__init__(levels)
+ self.wait()
self.game = game
self.target = None
self.image = pygame.image.load('assets/player.png')
self.rect = self.image.get_rect()
self.rect.midbottom = position
- self.wait()
def wait(self):
self.waiting = True
- self.wait_counter = randint(60,2400)
+ self.wait_counter = randint(60,240)
def walk(self, target):
self.target = None
self.waiting = False
- self.path = fstar(self.rect.midbottom, target, self.levels)
- if not self.path:
- self.wait()
- elif self.path[0] != target:
+ self.path = astar(self.rect.midbottom, target, self.levels)
+ if self.path and self.path[0] != target:
self.target = target
def get_busy(self):
@@ -47,4 +45,6 @@ def update(self):
self.get_busy()
super(Peasant, self).update()
if not self.path and self.target:
- self.walk(self.target)
+ self.walk(self.target)
+ elif not self.path and not self.waiting:
+ self.wait()
View
7 lingua/utils/__init__.py
@@ -1,5 +1,10 @@
+from subprocess import Popen, PIPE
+
class NoPathFound(Exception):
pass
-from .astar import astar, fstar
+#from .astar import astar, fstar
from .path import find_closest_path
+
+def astar(start, end, levels):
+ return list(reversed(eval(Popen("AStar.exe %s %s %s %s" % (start+end), stdout=PIPE, shell=True).stdout.read())))
View
2 lingua/utils/astar.py
@@ -116,7 +116,7 @@ def fstar(start, end, levels):
counter += 1
node = open.pop()
closed.append(node)
- if node.start == end or counter > 150:
+ if node.start == end or counter > 200:
return node.path()
for next in node.next():
if next not in open and next not in closed:
View
2 play.py
@@ -9,7 +9,7 @@
from lingua import Game
pygame.init()
-screen = pygame.display.set_mode((800, 600))
+screen = pygame.display.set_mode((800, 600))#, FULLSCREEN)
pygame.display.set_caption('Lingua Franca')
game = Game(screen)
clock = pygame.time.Clock()
View
4 setup.py
@@ -0,0 +1,4 @@
+from distutils.core import setup
+import py2exe
+
+setup(console=['play.py'])

0 comments on commit f4e69b5

Please sign in to comment.