def run(): andlib.Init() while True: print("#" * 70) sc = andlib.GetScreen() sc = ScreenReader.normalizeImage(sc) # io.imsave("data/history/hist_" + friendspop.getTimeStr() + ".png", sc) mat = ScreenReader.createMatrixFromScreen(sc) pprint(mat) friendspop.print_board(mat) solver = friendspop.SimpleSolver() score, [start, end] = solver.solve_board(mat) print(score) print(start, end) score, _, endboard = solver.check_direction(start, ((end[0] - start[0]), (end[1] - start[1]))) x1, y1 = ScreenReader.GetCellMidPoint(sc, start[0], start[1]) x2, y2 = ScreenReader.GetCellMidPoint(sc, end[0], end[1]) print((x1, y1), (x2, y2)) plt.imshow(sc) plt.plot([x1, x2], [y1, y2], 'k-', lw=2) plt.show()
def testUsingPhone(): return andlib.Init() while True: print "##################################################################################################" try: filelist = glob.glob("data/PredictionLog/*.png") for f in filelist: os.remove(f) except: pass sc = andlib.GetScreen() sc = ScreenReader.normalizeImage(sc) # io.imsave("data/history/hist_" + friendspop.getTimeStr() + ".png", sc) mat = ScreenReader.createMatrixFromScreen(sc) pprint(mat) friendspop.print_board(mat) solver = friendspop.SimpleSolver() score, [start, end] = solver.solve_board(mat) print score print(start, end) friendspop.DEBUG_EXPLOSIONS = True score, _, endboard = solver.check_direction(start, ((end[0] - start[0]), (end[1] - start[1]))) friendspop.DEBUG_EXPLOSIONS = False x1, y1 = ScreenReader.GetCellMidPoint(sc, start[0], start[1]) x2, y2 = ScreenReader.GetCellMidPoint(sc, end[0], end[1]) print((x1,y1), (x2,y2)) plt.imshow(sc) plt.plot([x1,x2], [y1,y2], 'k-', lw=2) plt.show()
def test2(): sc = ScreenReader.readNormalizedScreen("data/asdf.png") mat = ScreenReader.createMatrixFromScreen(sc) solver = friendspop.SimpleSolver() score, [start, end] = solver.solve_board(mat) print score print(start, end) x1, y1 = ScreenReader.GetCellMidPoint(sc, start[0], start[1]) x2, y2 = ScreenReader.GetCellMidPoint(sc, end[0], end[1]) print((x1,y1), (x2,y2)) return plt.imshow(sc) plt.plot([x1,x2], [y1,y2], 'k-', lw=2) plt.show()
def run(): andlib.Init() while True: print("#" * 70) sc = andlib.GetScreen() sc = ScreenReader.normalizeImage(sc) # io.imsave("data/history/hist_" + friendspop.getTimeStr() + ".png", sc) mat = ScreenReader.createMatrixFromScreen(sc) pprint(mat) friendspop.print_board(mat) solver = friendspop.SimpleSolver() score, [start, end] = solver.solve_board(mat) print(score) print(start, end) score, _, endboard = solver.check_direction(start, ((end[0] - start[0]), (end[1] - start[1]))) x1, y1 = ScreenReader.GetCellMidPoint(sc, start[0], start[1]) x2, y2 = ScreenReader.GetCellMidPoint(sc, end[0], end[1]) print((x1,y1), (x2,y2)) plt.imshow(sc) plt.plot([x1,x2], [y1,y2], 'k-', lw=2) plt.show()
def test_predict(self): image = Image(filename=ImageReader('BLACK_BASE').filenames()[0]).image ScreenReader.predict(image) ScreenReader.predict(image) ScreenReader.predict(image)
def test_value_of(self): self.assertEqual(0, ScreenReader.value_of('BLACK_BASE')) self.assertEqual(-1, ScreenReader.value_of('NA_BASE')) self.assertEqual(4, ScreenReader.value_of('PINK_BASE'))