diff --git a/Constants.py b/Constants.py index 0cec2b4d..a27d3830 100644 --- a/Constants.py +++ b/Constants.py @@ -10,7 +10,7 @@ UP = 'UP' DOWN = 'DOWN' LEFT = 'LEFT' RIGHT = 'RIGHT' -DEFUSE = 'DEFUSE' +DEFUSE = 'defuse' MOVE = 'MOVE' DECOY = 'Decoy' @@ -28,4 +28,6 @@ NO = "no" NONE = "none" IMMEDIATE = "immediate" MEDIUM = 'medium' +POLIGON = 'poligon' +DETONATE = 'detonate' diff --git a/DecisionTree.json b/DecisionTree.json index 66f06078..01219de4 100644 --- a/DecisionTree.json +++ b/DecisionTree.json @@ -1,165 +1 @@ -{ - "defusable": { - "no": { - "bomb_type": { - "Atomic Bomb": { - "detonation_area": { - "large": "poligon", - "small": "detonate" - } - }, - "Chemical Bomb": { - "detonation_duration": { - "immediate": { - "detonation_area": { - "large": "poligon", - "small": { - "size": { - "large": "detonate", - "medium": "detonate", - "small": "poligon" - } - } - } - }, - "long": { - "size": { - "large": { - "detonation_area": { - "large": "poligon", - "small": "detonate" - } - }, - "medium": "poligon", - "small": "poligon" - } - }, - "none": "poligon", - "short": "detonate" - } - }, - "Claymore": { - "detonation_area": { - "large": { - "detonation_duration": { - "immediate": { - "size": { - "large": "detonate", - "medium": "poligon", - "small": "poligon" - } - }, - "long": "poligon", - "none": "poligon", - "short": "poligon" - } - }, - "small": { - "size": { - "large": { - "detonation_duration": { - "immediate": "poligon", - "long": "poligon", - "none": "detonate", - "short": "detonate" - } - }, - "medium": { - "detonation_duration": { - "immediate": "detonate", - "long": "poligon", - "none": "poligon", - "short": "poligon" - } - }, - "small": "detonate" - } - } - } - }, - "Decoy": "poligon", - "Land Mine": { - "detonation_duration": { - "immediate": "detonate", - "long": { - "size": { - "large": "poligon", - "medium": "detonate", - "small": "detonate" - } - }, - "none": "poligon", - "short": "poligon" - } - } - } - }, - "yes": { - "bomb_type": { - "Atomic Bomb": { - "detonation_area": { - "large": "defuse", - "small": "detonate" - } - }, - "Chemical Bomb": "defuse", - "Claymore": { - "detonation_duration": { - "immediate": { - "detonation_area": { - "large": { - "size": { - "large": "poligon", - "medium": "defuse", - "small": "poligon" - } - }, - "small": { - "size": { - "large": "detonate", - "medium": "poligon", - "small": "detonate" - } - } - } - }, - "long": { - "size": { - "large": { - "detonation_area": { - "large": "detonate", - "small": "defuse" - } - }, - "medium": "defuse", - "small": "defuse" - } - }, - "none": "defuse", - "short": { - "size": { - "large": "defuse", - "medium": { - "detonation_area": { - "large": "poligon", - "small": "detonate" - } - }, - "small": "defuse" - } - } - } - }, - "Decoy": "poligon", - "Land Mine": { - "detonation_duration": { - "immediate": "defuse", - "long": "defuse", - "none": "poligon", - "short": "defuse" - } - } - } - } - } -} \ No newline at end of file +{"defusable": {"no": {"bomb_type": {"Atomic Bomb": {"detonation_area": {"large": "poligon", "small": "detonate"}}, "Chemical Bomb": {"detonation_duration": {"immediate": {"detonation_area": {"large": "poligon", "small": {"size": {"large": "detonate", "medium": "detonate", "small": "poligon"}}}}, "long": {"size": {"large": {"detonation_area": {"large": "poligon", "small": "detonate"}}, "medium": "poligon", "small": "poligon"}}, "none": "poligon", "short": "detonate"}}, "Claymore": {"detonation_area": {"large": {"detonation_duration": {"immediate": {"size": {"large": "detonate", "medium": "poligon", "small": "poligon"}}, "long": "poligon", "none": "poligon", "short": "poligon"}}, "small": {"size": {"large": {"detonation_duration": {"immediate": "poligon", "long": "poligon", "none": "detonate", "short": "detonate"}}, "medium": {"detonation_duration": {"immediate": "detonate", "long": "poligon", "none": "poligon", "short": "poligon"}}, "small": "detonate"}}}}, "Decoy": "poligon", "Land Mine": {"detonation_duration": {"immediate": "detonate", "long": {"size": {"large": "poligon", "medium": "detonate", "small": "detonate"}}, "none": "poligon", "short": "poligon"}}}}, "yes": {"bomb_type": {"Atomic Bomb": {"detonation_area": {"large": "defuse", "small": "detonate"}}, "Chemical Bomb": "defuse", "Claymore": {"detonation_duration": {"immediate": {"detonation_area": {"large": {"size": {"large": "poligon", "medium": "defuse", "small": "poligon"}}, "small": {"size": {"large": "detonate", "medium": "poligon", "small": "detonate"}}}}, "long": {"size": {"large": {"detonation_area": {"large": "detonate", "small": "defuse"}}, "medium": "defuse", "small": "defuse"}}, "none": "defuse", "short": {"size": {"large": "defuse", "medium": {"detonation_area": {"large": "poligon", "small": "detonate"}}, "small": "defuse"}}}}, "Decoy": "poligon", "Land Mine": {"detonation_duration": {"immediate": "defuse", "long": "defuse", "none": "poligon", "short": "defuse"}}}}}} \ No newline at end of file diff --git a/Engine/Agent.py b/Engine/Agent.py index 675d6a70..42a24c00 100644 --- a/Engine/Agent.py +++ b/Engine/Agent.py @@ -1,5 +1,5 @@ import pygame -from Constants import ROWS, COLS, UP, LEFT, DOWN, RIGHT +from Constants import ROWS, COLS, UP, LEFT, DOWN, RIGHT, DETONATE, DEFUSE, POLIGON class Agent(object): @@ -28,7 +28,12 @@ class Agent(object): def getOrientation(self): return self.orientation - + def changeImage(self, imageType): + if imageType == DETONATE: + self.image = pygame.image.load('Engine/' + DETONATE + '.png') + if imageType == DEFUSE: + self.image = pygame.image.load('Engine/' + DEFUSE + '.png') + self.image = pygame.image.load('Engine/agent.png') # def ifNotOnEdge(self, destination): diff --git a/Engine/BfsPathFinder.py b/Engine/BfsPathFinder.py index a843c277..2c7644ef 100644 --- a/Engine/BfsPathFinder.py +++ b/Engine/BfsPathFinder.py @@ -109,8 +109,6 @@ class BfsPathFinder: def checkGoal(self, current): if current.state.getPoint() in self.board.bombMap: - bomb = self.board.getBomb(current.state.getPoint()) - self.dTree.key(self.dTree.tree, bomb) self.goal = Node(current,DEFUSE) return True return False diff --git a/Engine/Game.py b/Engine/Game.py index a07e8bf9..a258e1fd 100644 --- a/Engine/Game.py +++ b/Engine/Game.py @@ -1,7 +1,7 @@ import random import pygame -from Constants import SQUARE_SIZE, GREEN, RIGHT, LEFT, UP, DOWN, COLS, ROWS, DECOY, ATOMIC_BOMB, CHEMICAL_BOMB, MOVE, CLAYMORE, LAND_MINE +from Constants import SQUARE_SIZE, GREEN, RIGHT, LEFT, UP, DOWN, COLS, ROWS, DECOY, ATOMIC_BOMB, CHEMICAL_BOMB, MOVE, CLAYMORE, LAND_MINE, DEFUSE, DETONATE, POLIGON from Engine.Board import Board from Engine.Agent import Agent from Engine.BombFactory import BombFactory @@ -13,6 +13,8 @@ from Engine.PathFinder import PathFinder from Engine.Mud import Mud from Engine.DecisionTree import DecisionTree + + class Game: def __init__(self, win): self._init(win) @@ -29,7 +31,6 @@ class Game: self.dTree = DecisionTree(False) def update(self): - self.defuseBomb() self.board.drawSquares(self.win) self.board.drawBombs() self.board.drawStones() @@ -108,6 +109,7 @@ class Game: return BombFactory.create(LAND_MINE) def findBomb(self): + self.agent.changeImage("default") # return BfsPathFinder(self.board).findBomb(State(self.agent.getOrientation(),Point(self.agent.getPoint().getX(),self.agent.getPoint().getY()))) return PathFinder(self.board,self.dTree).findBomb(State(self.agent.getOrientation(),Point(self.agent.getPoint().getX(),self.agent.getPoint().getY()))) @@ -163,6 +165,23 @@ class Game: self.agent.point.y += 1 else: self.agent.point.y -= 1 + elif action == DEFUSE: + self.defuseAction() + elif action == DETONATE: + self.detonateAction() + elif action == POLIGON: + self.poligionAction() + + def defuseAction(self): + self.agent.changeImage(DEFUSE) + self.defuseBomb() + + def detonateAction(self): + self.agent.changeImage(DETONATE) + + def poligionAction(self): + self.defuseBomb() + diff --git a/Engine/__pycache__/Agent.cpython-39.pyc b/Engine/__pycache__/Agent.cpython-39.pyc index 84649e83..add4a4f2 100644 Binary files a/Engine/__pycache__/Agent.cpython-39.pyc and b/Engine/__pycache__/Agent.cpython-39.pyc differ diff --git a/Engine/__pycache__/BfsPathFinder.cpython-39.pyc b/Engine/__pycache__/BfsPathFinder.cpython-39.pyc index e1fbeabe..59cce1d5 100644 Binary files a/Engine/__pycache__/BfsPathFinder.cpython-39.pyc and b/Engine/__pycache__/BfsPathFinder.cpython-39.pyc differ diff --git a/Engine/__pycache__/DecisionTree.cpython-39.pyc b/Engine/__pycache__/DecisionTree.cpython-39.pyc index bdea8b89..26378add 100644 Binary files a/Engine/__pycache__/DecisionTree.cpython-39.pyc and b/Engine/__pycache__/DecisionTree.cpython-39.pyc differ diff --git a/Engine/__pycache__/Game.cpython-39.pyc b/Engine/__pycache__/Game.cpython-39.pyc index 5e509e7b..976e0209 100644 Binary files a/Engine/__pycache__/Game.cpython-39.pyc and b/Engine/__pycache__/Game.cpython-39.pyc differ diff --git a/Engine/defuse.png b/Engine/defuse.png new file mode 100644 index 00000000..144058af Binary files /dev/null and b/Engine/defuse.png differ diff --git a/Engine/detonate.png b/Engine/detonate.png new file mode 100644 index 00000000..a663b69c Binary files /dev/null and b/Engine/detonate.png differ diff --git a/__pycache__/Constants.cpython-39.pyc b/__pycache__/Constants.cpython-39.pyc index 312847c7..281be3a3 100644 Binary files a/__pycache__/Constants.cpython-39.pyc and b/__pycache__/Constants.cpython-39.pyc differ