def get_move(self, view): self.calls += 1 last_plant = self.log_last_plant(view) #return value of 1 signals plant we've seen before, so don't log it if last_plant == 2 or last_plant==3: self.visited[(self.lastX, self.lastY)] = last_plant if last_plant == 2: self.lastNutri = self.calls - 1 x = view.GetXPos() y = view.GetYPos() self.lastPlant = view.GetPlantInfo() self.visited[(x, y)] = view.GetPlantInfo() if (self.lastNutriX==0 and self.lastNutriY ==0): move = self.next_move_spiral_smart(x, y, self.centerX, self.centerY) elif self.lastNutri + (view.GetLife()/5) < self.calls \ and abs(self.lastX)+abs(self.lastY) < self.classifyDistance: move = self.next_move_spiral_smart(x, y, self.centerX, self.centerY) elif self.lastNutri + self.VI_EXPLORE_WINDOW + 1 > self.calls: PI, Q = self.VI((self.lastNutriX,self.lastNutriY), self.VI_H, self.VI_EXPLORE_WINDOW, self.calls, True, False) if (x,y) in PI: move = PI[(x, y)] else: move = game_interface.LEFT else: PI, Q = self.VI((x,y), self.VI_H, self.VI_EXPLORE_WINDOW, self.calls, False, False) if (x,y) in PI: move = PI[(x, y)] else: move = game_interface.LEFT self.lastX = view.GetXPos() self.lastY = view.GetYPos() self.lastLife = view.GetLife() if view.GetPlantInfo() == game_interface.STATUS_UNKNOWN_PLANT: # eat everything if not outside of cutoff radius if abs(self.lastX)+abs(self.lastY) < self.classifyDistance: return move, True # eat if health is low if self.lastLife < self.plant_penalty: return move, True # classify if outside cutoff and health is not low eat = [] num_images = round(abs((1.0*self.plant_bonus)/self.plant_penalty)/self.observation_cost) for i in range(int(num_images)): data = list(view.GetImage()) eat.append(classify.get_class(data, self.mSVM, self.mDT, self.mANN, self.mNBayes)) isNutritious = ((1.0*sum(eat))/len(eat) > 0.5) return move, isNutritious return move, False
def get_move(self, view): self.calls += 1 last_plant = self.log_last_plant(view) #return value of 1 signals plant we've seen before, so don't log it if last_plant == 2 or last_plant == 3: self.visited[(self.lastX, self.lastY)] = last_plant if last_plant == 2: self.lastNutri = self.calls - 1 x = view.GetXPos() y = view.GetYPos() self.lastPlant = view.GetPlantInfo() self.visited[(x, y)] = view.GetPlantInfo() if (self.lastNutriX == 0 and self.lastNutriY == 0): move = self.next_move_spiral_smart(x, y, self.centerX, self.centerY) elif self.lastNutri + (view.GetLife()/5) < self.calls \ and abs(self.lastX)+abs(self.lastY) < self.classifyDistance: move = self.next_move_spiral_smart(x, y, self.centerX, self.centerY) elif self.lastNutri + self.VI_EXPLORE_WINDOW + 1 > self.calls: PI, Q = self.VI((self.lastNutriX, self.lastNutriY), self.VI_H, self.VI_EXPLORE_WINDOW, self.calls, True, False) if (x, y) in PI: move = PI[(x, y)] else: move = game_interface.LEFT else: PI, Q = self.VI((x, y), self.VI_H, self.VI_EXPLORE_WINDOW, self.calls, False, False) if (x, y) in PI: move = PI[(x, y)] else: move = game_interface.LEFT self.lastX = view.GetXPos() self.lastY = view.GetYPos() self.lastLife = view.GetLife() if view.GetPlantInfo() == game_interface.STATUS_UNKNOWN_PLANT: # eat everything if not outside of cutoff radius if abs(self.lastX) + abs(self.lastY) < self.classifyDistance: return move, True # eat if health is low if self.lastLife < self.plant_penalty: return move, True # classify if outside cutoff and health is not low eat = [] num_images = round( abs((1.0 * self.plant_bonus) / self.plant_penalty) / self.observation_cost) for i in range(int(num_images)): data = list(view.GetImage()) eat.append( classify.get_class(data, self.mSVM, self.mDT, self.mANN, self.mNBayes)) isNutritious = ((1.0 * sum(eat)) / len(eat) > 0.5) return move, isNutritious return move, False
#!/usr/bin/env python2 from __future__ import division import os import imp from os import path import classify files = os.listdir("data/test") num_correct = 0 num_incorrect = 0 for f in files: c = classify.get_class(path.join("data/test", f)) if c == "shuttle" and f.startswith("shuttle"): num_correct+=1 elif c == "noshuttle" and f.startswith("noshuttle"): num_correct+=1 else: num_incorrect+=1 print "Correct: {}".format(num_correct) print "Incorrect: {}".format(num_incorrect) print "Percent correct: {0:.0f}%".format(num_correct/(num_incorrect+num_correct)*100)