diff --git a/ScreenShots/Diagonal.png b/ScreenShots/Diagonal.png new file mode 100644 index 0000000..0f0a2d6 Binary files /dev/null and b/ScreenShots/Diagonal.png differ diff --git a/ScreenShots/Hop.png b/ScreenShots/Hop.png new file mode 100644 index 0000000..cce597c Binary files /dev/null and b/ScreenShots/Hop.png differ diff --git a/ScreenShots/Swamped.png b/ScreenShots/Swamped.png new file mode 100644 index 0000000..e79d49d Binary files /dev/null and b/ScreenShots/Swamped.png differ diff --git a/ScreenShots/cost_f.png b/ScreenShots/cost_f.png new file mode 100644 index 0000000..3aa59a7 Binary files /dev/null and b/ScreenShots/cost_f.png differ diff --git a/ScreenShots/cost_h.png b/ScreenShots/cost_h.png new file mode 100644 index 0000000..d70efef Binary files /dev/null and b/ScreenShots/cost_h.png differ diff --git a/ScreenShots/g_cost.png b/ScreenShots/g_cost.png new file mode 100644 index 0000000..b1c9333 Binary files /dev/null and b/ScreenShots/g_cost.png differ diff --git a/astar.py b/astar.py index 802abe5..bad1a48 100644 --- a/astar.py +++ b/astar.py @@ -57,8 +57,12 @@ def _is_occupied(self,cell_coord): return False def _add_swamp(self, mouse_pos): - #insert swamp code here. - pass + swamp_coord = (mouse_pos[0]/50, mouse_pos[1]/50) + if self._is_occupied(swamp_coord): + if self.actors[swamp_coord].unremovable == False: + self.actors.pop(swamp_coord, None) + else: + self.actors[swamp_coord] = ObstacleTile( swamp_coord, self, './images/swamp.jpg', is_unpassable = False, terrain_cost = 3) def _add_lava(self, mouse_pos): lava_coord = (mouse_pos[0]/50, mouse_pos[1]/50) @@ -68,6 +72,7 @@ def _add_lava(self, mouse_pos): else: self.actors[lava_coord] = ObstacleTile( lava_coord, self, './images/lava.jpg', is_unpassable = True, terrain_cost = 0) + def get_terrain_cost(self, cell_coord): try: actor = self.actors[cell_coord] @@ -91,14 +96,16 @@ def main_loop(self): elif event.type is pygame.MOUSEBUTTONDOWN: if self.add_tile_type == 'lava': self._add_lava(event.pos) - #insert swamp code here + if self.add_tile_type == 'swamp': + self._add_swamp(event.pos) elif event.type is pygame.KEYDOWN: if event.key == pygame.K_SPACE: self.paul.run_astar(self.cake.cell_coordinates, self) self.paul.get_path() elif event.key == pygame.K_l: self.add_tile_type = 'lava' - #insert swamp code here + elif event.key == pygame.K_s: + self.add_tile_type = 'swamp' class Actor(object): def __init__(self, cell_coordinates, world, image_loc, unremovable = False, is_obstacle = True): @@ -143,9 +150,9 @@ def f_cost(self): def draw(self): COST_TO_DRAW = '' - #COST_TO_DRAW = self.g_cost - #COST_TO_DRAW = self.h_cost - #COST_TO_DRAW = self.f_cost + # COST_TO_DRAW = self.g_cost # the number of steps it takes to get to that block + # COST_TO_DRAW = self.h_cost # an estimation as to how far Paul is from the cake + COST_TO_DRAW = self.f_cost # is g+h line_width = 2 rect = pygame.Rect((self.coordinates[0],self.coordinates[1]),(self.dimensions[0],self.dimensions[1])) pygame.draw.rect(self.draw_screen, self.color, rect, line_width) @@ -167,8 +174,8 @@ def get_h_cost(self, coord_a,coord_b): def get_open_adj_coords(self, coords): """returns list of valid coords that are adjacent to the argument, open, and not in the closed list.""" #modify directions and costs as needed - directions = [(1,0),(0,1),(-1,0),(0,-1)] - costs = [1,1,1,1] + directions = [(1,0),(0,1),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1),(2,0),(0,2),(-2,0),(0,-2)] + costs = [1,1,1,1,3,3,3,3,8,8,8,8] adj_coords = map(lambda d: self.world._add_coords(coords,d), directions) for i, coord in enumerate(adj_coords): costs[i] += self.world.get_terrain_cost(coord) @@ -244,3 +251,12 @@ def run_astar(self, destination_coord, world): if __name__ == "__main__": g = GridWorld() g.main_loop() + +# diagonals +# Since there's a set of diagonal wall, Paul must go diagonal to go through + +# hops +# Diagonals won't suffice this time: Paul needs to hop. + +# swamps +# Paul would rather go through the swamp than go the long way. He also goes diagonal 'cause he don't give a fuck (and to avoid the other swamp). \ No newline at end of file