예제 #1
0
파일: gui.py 프로젝트: arelroche/Draughts
 def calibrate_image(self):
     logger.log("calibrating image")
     global image_update_flag
     image_update_flag = False
     try:
         img = Shooter.get_img()
         ImageProcess.calibrate_board(img)
     except Exception as ex:
         logger.log("cannot calibrate image" + str(ex),error=True)
     image_update_flag = True
예제 #2
0
파일: gui.py 프로젝트: ema2541/Draughts
 def calibrate_image(self):
     logger.log("calibrating image")
     global image_update_flag
     image_update_flag = False
     try:
         img = Shooter.get_img()
         ImageProcess.calibrate_board(img)
     except Exception as ex:
         logger.log("cannot calibrate image" + str(ex), error=True)
     image_update_flag = True
예제 #3
0
파일: gui.py 프로젝트: arelroche/Draughts
 def calc_image(self):
     try:
         self.ui.imgNormal = self.img
         self.ui.imgEdges = self.img
         self.table = ImageProcess.frame_table(self.img, False)
         self.ui.imgNormal = ImageProcess.trimmed
         self.ui.imgEdges = ImageProcess.edgesImage
         self.ui.updateImage()
     #print "New image"
     except Exception as ex:
         logger.log("cannot calculate image" + str(ex), error=True)
예제 #4
0
파일: gui.py 프로젝트: ema2541/Draughts
 def calc_image(self):
     try:
         self.ui.imgNormal = self.img
         self.ui.imgEdges = self.img
         self.table = ImageProcess.frame_table(self.img, False)
         self.ui.imgNormal = ImageProcess.trimmed
         self.ui.imgEdges = ImageProcess.edgesImage
         self.ui.updateImage()
     #print "New image"
     except Exception as ex:
         logger.log("cannot calculate image" + str(ex), error=True)
예제 #5
0
    def configButton_click(self):
        import MainApp.conf as Conf

        log("opening configuration window")
        ui = configWindow.configWindow(self)
        ui.WorkingThread = self.thread
        ui.lineEdit.setText(config.get("IP"))
        ui.colorThresholdVal.setValue(int(config.get("threshold")))
        ui.p1.setValue(int(Conf.get("param1")))
        ui.p2.setValue(int(Conf.get("param2")))
        if ui.exec_():
            config.set("IP", ui.lineEdit.text())
            config.set("threshold", ui.colorThresholdVal.value())
예제 #6
0
파일: mainApp.py 프로젝트: ema2541/Draughts
def check_game_end(table, ui):
    res = table.gameWon()
    if res != 0:
        if res == 1:
            log("AI won!")
            print "AI won!"
        else:
            log("Human won!")
            print "Human won!"
        log("game ended in %d turns" % turns)
        print "In", turns, "turns."
        return True
    return False
예제 #7
0
def check_game_end(table, ui):
    res = table.gameWon()
    if res != 0:
        if res == 1:
            log("AI won!")
            print "AI won!"
        else:
            log("Human won!")
            print "Human won!"
        log("game ended in %d turns" % turns)
        print "In", turns, "turns."
        return True
    return False
예제 #8
0
파일: mainApp.py 프로젝트: ema2541/Draughts
def move(table, ui):
    global a, turns
    #img = Image.take_photo()
    #b = proc.frame_table(img, False)
    (After, move) = a.boardFromCamera(table)

    #print "points: ",boardPoints(table)

    if move is not None:
        s = movesListToString(move)
        ui.add_move(s)
        print "OK"
        log("move OK")
        bads = 0
        a = After
        ok = 1

        sys.stdout.write("Turn " + str(turns))
        turns += 1

        if check_game_end(a, ui): return True

        log("calculating move... ", line=False, time=False)
        res = minimaks(copy.deepcopy(a), 6)  #was 6
        log("done")
        print "White:", res, res[1]

        s = movesListToString(res[1], True)
        send(res[1])
        ui.add_move(s)
        a.executeMove(res[1])
        print "After Move:\n", a
    else:
        log("bad move", error=True)
        #print "Bad Move! Try again!\nPrevious board:"
        #print a
        #print "Actual board:"
        #print table

    if check_game_end(a, ui): return True
    return False
예제 #9
0
def move(table, ui):
    global a, turns
    #img = Image.take_photo()
    #b = proc.frame_table(img, False)
    (After, move) = a.boardFromCamera(table)

    #print "points: ",boardPoints(table)

    if move is not None:
        s = movesListToString(move)
        ui.add_move(s)
        print "OK"
        log("move OK")
        bads = 0
        a = After
        ok = 1

        sys.stdout.write("Turn " + str(turns))
        turns += 1

        if check_game_end(a, ui): return True

        log("calculating move... ", line=False,time=False)
        res = minimaks(copy.deepcopy(a), 6)  #was 6
        log("done")
        print "White:", res, res[1]

        s = movesListToString(res[1], True)
        send(res[1])
        ui.add_move(s)
        a.executeMove(res[1])
        print "After Move:\n", a
    else:
        log("bad move",error=True)
        #print "Bad Move! Try again!\nPrevious board:"
        #print a
        #print "Actual board:"
        #print table

    if check_game_end(a, ui): return True
    return False
예제 #10
0
def take_photo():
    import MainApp.conf as Conf
    import urllib

    global success

    log("Connecting... ",line=False)

    try:
        urllib.urlretrieve("http://" + str(Conf.get('IP')) + ":8080/shot.jpg", "shot.jpg")
    except Exception as ex:
        success = False
        log("Cannot connect!" + str(ex), error=True,time=False)
        return False
    else:
        log("OK",False)
        success = True
        return True
예제 #11
0
def take_photo():
    import MainApp.conf as Conf
    import urllib

    global success

    log("Connecting... ", line=False)

    try:
        urllib.urlretrieve("http://" + str(Conf.get('IP')) + ":8080/shot.jpg",
                           "shot.jpg")
    except Exception as ex:
        success = False
        log("Cannot connect!" + str(ex), error=True, time=False)
        return False
    else:
        log("OK", False)
        success = True
        return True
예제 #12
0
파일: mainApp.py 프로젝트: ema2541/Draughts
def set_position(table):
    global a
    log("Board set")
    a = table
예제 #13
0
 def nxtControlButton_click(self):
     log("opening NXT window")
     ui = nxtWindow.nxtWindow(self)
     ui.exec_()
예제 #14
0
 def new_move(self):
     log("making move")
     self.thread.new_move()
예제 #15
0
def set_position(table):
    global a
    log("Board set")
    a = table
예제 #16
0
파일: gui.py 프로젝트: ema2541/Draughts
        global image_update_flag
        image_update_flag = False
        try:
            img = Shooter.get_img()
            ImageProcess.calibrate_board(img)
        except Exception as ex:
            logger.log("cannot calibrate image" + str(ex), error=True)
        image_update_flag = True


if __name__ == "__main__":
    app = QApplication(sys.argv)

    global ui
    ui = mainWindow.mainWindow()
    ui.show()

    logger.register_ui(ui)

    th = Worker(ui)

    ui.use_thread(th)

    th.start()

    logger.log("Starting app")
    x = app.exec_()
    #th.terminate()
    Shooter.timer_stop()
    logger.log("app end")
    sys.exit(x)
예제 #17
0
파일: gui.py 프로젝트: arelroche/Draughts
        global image_update_flag
        image_update_flag = False
        try:
            img = Shooter.get_img()
            ImageProcess.calibrate_board(img)
        except Exception as ex:
            logger.log("cannot calibrate image" + str(ex),error=True)
        image_update_flag = True


if __name__ == "__main__":
    app = QApplication(sys.argv)

    global ui
    ui = mainWindow.mainWindow()
    ui.show()

    logger.register_ui(ui)

    th = Worker(ui)

    ui.use_thread(th)

    th.start()

    logger.log("Starting app")
    x = app.exec_()
    #th.terminate()
    Shooter.timer_stop()
    logger.log("app end")
    sys.exit(x)