def switchEvent(self): message = 'switch policy' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('switch policy') self.dialog = QDialog() # tab item name list_str = [ strings.ALGORITHM_COMA, strings.ALGORITHM_COMMNET_COMA, strings.ALGORITHM_QMIX, strings.ALGORITHM_QTRAN_ALT, strings.ALGORITHM_QTRAN_BASE, strings.ALGORITHM_VDN ] # item content list_item = [ strings.CLASS_ALGORITHM_COMA, strings.CLASS_ALGORITHM_COMMNET_COMA, strings.CLASS_ALGORITHM_QMIX, strings.CLASS_ALGORITHM_QTRAN_ALT, strings.CLASS_ALGORITHM_QTRAN_BASE, strings.CLASS_ALGORITHM_VDN ] # title name self.listDialog = ListDialog(list_str, list_item, strings.OPERATIONAL_PLANNING_TITLE, strings.TYPE_POLICY) self.listDialog.setupUi(self.dialog, self.window) self.window.setWidget(self.dialog) self.initFrameLessWindow( QSize(700, 600), 'Operational Planning', QIcon('../resource/drawable/logo.png') ) self.window.show()
def outputEvent(self): message = 'situation information: output' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('output') self.dialog = QDialog() description = "a description of output" situation = SituationDescriptionDialog(description) situation.setupUi(self.dialog) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Situation Information', QIcon('../resource/drawable/logo.png')) self.window.show()
def modelTrainEvent(self): message = 'the setting of model train' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('model train') self.dialog = QDialog() description = "a description of model train" model = ModelTrainDescriptionDialog(description) model.setupUi(self.dialog) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Model Train', QIcon('../resource/drawable/logo.png')) self.window.show()
def mapEvent(self): message = 'open the map description' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('map description') self.dialog = QDialog() mapDialog = MapDescriptionDialog() mapDialog.setupUi(self.dialog) self.dialog.setModal(True) self.window.setWidget(self.dialog) self.initFrameLessWindow( QSize(700, 600), 'Operational Planning', QIcon('../resource/drawable/logo.png') ) self.window.show()
def chooseMapEvent(self): message = 'choose new map' log = logging.getLogger('StarCraftII') log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('choose map') self.dialog = QDialog() # tab item name list_map = self.list_str if globalInformation.get_value(strings.TYPE_POLICY) is None \ else globalInformation.get_value(strings.ALGORITHM_MAP)[globalInformation.get_value(strings.TYPE_POLICY)] # title name self.listDialog = ListDialog(list_map, None, strings.MAPS_TITLE, strings.TYPE_MAP) self.listDialog.setupUi(self.dialog, self.window) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Maps', QIcon('../resource/drawable/logo.png')) self.dialog.setModal(True) self.window.show()
class SituationInformation(QWidget): def __init__(self): super(SituationInformation, self).__init__() self.setObjectName('SituationInformation') self.setStyleSheet( GetQssFile.readQss('../resource/qss/situationInformation.qss')) self.log = logging.getLogger('StarCraftII') # font font = QFont() font.setWeight(50) font.setPixelSize(15) # set widget of layout self.frame = QFrame(self) self.frame.setGeometry(QDesktopWidget().screenGeometry()) self.main_layout = QHBoxLayout(self) self.main_layout.setSpacing(20) self.setLayout(self.main_layout) # consumption action self.consumption = QPushButton() self.consumption.setObjectName('consumption') self.consumptionLabel = QLabel('consumption') self.consumptionLabel.setFont(font) self.consumption_layout = QVBoxLayout() self.consumption_layout.addWidget(self.consumption, alignment=Qt.AlignCenter) self.consumption_layout.addWidget(self.consumptionLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.consumption_layout) # resource action self.resource = QPushButton() self.resource.setObjectName('resource') self.resourceLabel = QLabel('resource') self.resourceLabel.setFont(font) self.resource_layout = QVBoxLayout() self.resource_layout.addWidget(self.resource, alignment=Qt.AlignCenter) self.resource_layout.addWidget(self.resourceLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.resource_layout) # score action self.score = QPushButton() self.score.setObjectName('score') self.scoreLabel = QLabel('score') self.scoreLabel.setFont(font) self.score_layout = QVBoxLayout() self.score_layout.addWidget(self.score, alignment=Qt.AlignCenter) self.score_layout.addWidget(self.scoreLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.score_layout) # output action self.output = QPushButton() self.output.setObjectName('output') self.outputLabel = QLabel('output') self.outputLabel.setFont(font) self.output_layout = QVBoxLayout() self.output_layout.addWidget(self.output, alignment=Qt.AlignCenter) self.output_layout.addWidget(self.outputLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.output_layout) # a description dialog self.dialog = None # add stretch self.main_layout.addStretch(1) # initialization self.initUI() def initUI(self): self.consumption.clicked.connect(self.buttonEvent) self.score.clicked.connect(self.buttonEvent) self.resource.clicked.connect(self.buttonEvent) self.output.clicked.connect(self.buttonEvent) def buttonEvent(self): sender = self.sender() if sender == self.consumption: self.consumptionEvent() elif sender == self.score: self.scoreEvent() elif sender == self.resource: self.resourceEvent() elif sender == self.output: self.outputEvent() def consumptionEvent(self): message = 'situation information: consumption' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('consumption') self.dialog = QDialog() description = "a description of consumption" situation = SituationDescriptionDialog(description) situation.setupUi(self.dialog) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Situation Information', QIcon('../resource/drawable/logo.png')) self.window.show() # self.dialog.setModal(True) # self.dialog.show() def scoreEvent(self): message = 'situation information: score' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('consumption') self.dialog = QDialog() description = "a description of score" situation = SituationDescriptionDialog(description) situation.setupUi(self.dialog) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Situation Information', QIcon('../resource/drawable/logo.png')) self.window.show() # self.dialog.setModal(True) # self.dialog.show() def resourceEvent(self): message = 'situation information: resource' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('resource') self.dialog = QDialog() description = "a description of resource" situation = SituationDescriptionDialog(description) situation.setupUi(self.dialog) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Situation Information', QIcon('../resource/drawable/logo.png')) self.window.show() # self.dialog.setModal(True) # self.dialog.show() def outputEvent(self): message = 'situation information: output' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('output') self.dialog = QDialog() description = "a description of output" situation = SituationDescriptionDialog(description) situation.setupUi(self.dialog) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Situation Information', QIcon('../resource/drawable/logo.png')) self.window.show() # self.dialog.setModal(True) # self.dialog.show() def initFrameLessWindow(self, size, title, icon): self.window.resize(size) self.window.setWindowTitle(title) self.window.setWindowIcon(icon)
def main(): app = QApplication(sys.argv) splash = SplashScreen() splash.effect() app.processEvents() main_window = FramelessWindow('title') main_window.setWindowTitle(strings.NAME) main_window.setWindowIcon(QIcon('../resource/drawable/logo.png')) main_window.resize(QSize(1200, 700)) main_window.setWidget(MainWindow()) main_window.showMaximized() splash.finish(main_window) sys.exit(app.exec_())
class Maps(QWidget): def __init__(self): super(Maps, self).__init__() self.setObjectName('Maps') self.setStyleSheet(GetQssFile.readQss('../resource/qss/maps.qss')) # font font = QFont("Roman times", 36, QFont.Bold) # font.setWeight(50) # font.setFamily('Helvetica') font.setPixelSize(15) # set widget of layout self.frame = QFrame(self) self.frame.setGeometry(QDesktopWidget().screenGeometry()) self.main_layout = QHBoxLayout(self) self.main_layout.setSpacing(20) self.setLayout(self.main_layout) # choose map self.chooseMap = QPushButton() self.chooseMap.setObjectName('chooseMap') self.chooseMapLabel = QLabel('choose map') self.chooseMapLabel.setFont(font) self.chooseMap_layout = QVBoxLayout() self.chooseMap_layout.addWidget(self.chooseMap, alignment=Qt.AlignCenter) self.chooseMap_layout.addWidget(self.chooseMapLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.chooseMap_layout) # map design self.mapDesign = QPushButton() self.mapDesign.setObjectName('mapDesign') self.mapDesignLabel = QLabel('map design') self.mapDesignLabel.setFont(font) self.mapDesign_layout = QVBoxLayout() self.mapDesign_layout.addWidget(self.mapDesign, alignment=Qt.AlignCenter) self.mapDesign_layout.addWidget(self.mapDesignLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.mapDesign_layout) # dialog self.dialog = None # add stretch self.main_layout.addStretch(1) # initialization self.initUI() self.list_str = [ strings.MAP_MOVE_TO_BEACON, strings.MAP_COLLECT_MINERAL_SHARDS, strings.MAP_FIND_AND_DEFEAT_ZERGLINGS, strings.MAP_DEFEAT_ROACHES, strings.MAP_DEFEAT_ZERGLINGS_AND_BANELINGS, strings.MAP_COLLECT_MINERALS_AND_GAS, strings.MAP_BUILD_MARINES, strings.MAP_2C_VS_64ZG, strings.MAP_2M_VS_1Z, strings.MAP_2S3Z, strings.MAP_2S_VS_1SC, strings.MAP_3M, strings.MAP_3S5Z, strings.MAP_3S5Z_VS_3S6Z, strings.MAP_3S_VS_3Z, strings.MAP_3S_VS_4Z, strings.MAP_3S_VS_5Z, strings.MAP_5M_VS_6M, strings.MAP_6H_VS_8Z, strings.MAP_8M, strings.MAP_8M_VS_9M, strings.MAP_10M_VS_11M, strings.MAP_25M, strings.MAP_27M_VS_30M, strings.MAP_BANE_VS_BANE, strings.MAP_CORRIDOR, strings.MAP_MMM, strings.MAP_MMM2, strings.MAP_SO_MANY_BANELINGS ] def initUI(self): self.chooseMap.clicked.connect(self.buttonEvent) self.mapDesign.clicked.connect(self.buttonEvent) def buttonEvent(self): sender = self.sender() if sender == self.chooseMap: self.chooseMapEvent() elif sender == self.mapDesign: Maps.mapDesignEvent() def chooseMapEvent(self): message = 'choose new map' log = logging.getLogger('StarCraftII') log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('choose map') self.dialog = QDialog() # tab item name list_map = self.list_str if globalInformation.get_value(strings.TYPE_POLICY) is None \ else globalInformation.get_value(strings.ALGORITHM_MAP)[globalInformation.get_value(strings.TYPE_POLICY)] # title name self.listDialog = ListDialog(list_map, None, strings.MAPS_TITLE, strings.TYPE_MAP) self.listDialog.setupUi(self.dialog, self.window) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Maps', QIcon('../resource/drawable/logo.png')) self.dialog.setModal(True) self.window.show() # self.dialog.setModal(True) # self.dialog.show() @staticmethod def mapDesignEvent(): message = 'open the map designer to customize the map' log = logging.getLogger('StarCraftII') log.info(message) Signal.get_signal().emit_signal_str(message) # os.system(strings.SCMDRAFT) subprocess.Popen(strings.SCMDRAFT) def initFrameLessWindow(self, size, title, icon): self.window.resize(size) self.window.setWindowTitle(title) self.window.setWindowIcon(icon)
class OperationalPlanning(QWidget): signal_gameover = Signal.get_signal().signal_gameover def __init__(self): super(OperationalPlanning, self).__init__() self.setObjectName('OperationalPlanning') self.setStyleSheet(GetQssFile.readQss('../resource/qss/operationalPlanning.qss')) self.log = logging.getLogger('StarCraftII') # test fix algorithm self.algorithm = None self.algorithmThread = None # font font = QFont() font.setWeight(50) font.setPixelSize(15) # set widget of layout self.frame = QFrame(self) self.frame.setGeometry(QDesktopWidget().screenGeometry()) self.main_layout = QHBoxLayout(self) self.main_layout.setSpacing(20) self.setLayout(self.main_layout) # start action self.start = QPushButton() self.start.setObjectName('start') self.startLabel = QLabel('start') self.startLabel.setFont(font) self.start_layout = QVBoxLayout() self.start_layout.addWidget(self.start, alignment=Qt.AlignCenter) self.start_layout.addWidget(self.startLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.start_layout) # pause action # self.pause = QPushButton() # self.pause.setObjectName('pause') # self.pauseLabel = QLabel('pause') # self.pauseLabel.setFont(font) # self.pause_layout = QVBoxLayout() # self.pause_layout.addWidget(self.pause, alignment=Qt.AlignCenter) # self.pause_layout.addWidget(self.pauseLabel, alignment=Qt.AlignCenter) # self.main_layout.addLayout(self.pause_layout) # stop action self.stop = QPushButton() self.stop.setObjectName('stop') self.stopLabel = QLabel('stop') self.stopLabel.setFont(font) self.stop_layout = QVBoxLayout() self.stop_layout.addWidget(self.stop, alignment=Qt.AlignCenter) self.stop_layout.addWidget(self.stopLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.stop_layout) # switch policy action self.switch = QPushButton() self.switch.setObjectName('switch') self.switchLabel = QLabel('switch policy') self.switchLabel.setFont(font) self.switch_layout = QVBoxLayout() self.switch_layout.addWidget(self.switch, alignment=Qt.AlignCenter) self.switch_layout.addWidget(self.switchLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.switch_layout) # simulation time self.lcd = QLCDNumber() self.lcd.setObjectName('lcd') self.lcd.setDigitCount(10) self.lcd.setMode(QLCDNumber.Dec) self.lcd.setSegmentStyle(QLCDNumber.Flat) self.lcd.setFrameStyle(QFrame.Panel | QFrame.Raised) self.lcd.display(time.strftime("%X", time.localtime())) self.lcdLabel = QLabel('simulation time') self.lcdLabel.setFont(font) self.lcd_layout = QVBoxLayout() self.lcd_layout.addWidget(self.lcd, alignment=Qt.AlignBottom) self.lcd_layout.addWidget(self.lcdLabel, alignment=Qt.AlignBottom) self.main_layout.addLayout(self.lcd_layout) # define time self.qtime = QTimer() self.qtime.timeout.connect(self.refresh) # define global variable global interval interval = 0 global start_or_pause start_or_pause = False global stop stop = True # map description self.map = QPushButton() self.map.setObjectName('map') self.mapLabel = QLabel('map description') self.mapLabel.setFont(font) self.map_layout = QVBoxLayout() self.map_layout.addWidget(self.map, alignment=Qt.AlignCenter) self.map_layout.addWidget(self.mapLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.map_layout) # add stretch self.main_layout.addStretch(1) # popup window self.dialog = None # initialization self.initUI() def refresh(self): timeworker = TimeWorker(self.lcd, OperationalPlanning.interval) OperationalPlanning.interval += 1 timeworker.run() def initUI(self): # connect the slot function self.start.clicked.connect(self.buttonEvent) # self.pause.clicked.connect(self.buttonEvent) self.stop.clicked.connect(self.buttonEvent) self.switch.clicked.connect(self.buttonEvent) self.map.clicked.connect(self.buttonEvent) self.signal_gameover.connect(self.stopEvent) def buttonEvent(self): sender = self.sender() if sender == self.start: self.startEvent() # elif sender == self.pause: # self.pauseEvent() elif sender == self.stop: self.stopEvent() elif sender == self.switch: self.switchEvent() elif sender == self.map: self.mapEvent() # start simulation def startEvent(self): message = 'start the simulation' self.log.info(message) Signal.get_signal().emit_signal_str(message) # fix rl algorithm globalInformation.set_value(strings.IS_STOP, False) OperationalPlanning.interval = 0 OperationalPlanning.start_or_pause = True OperationalPlanning.stop = False self.qtime.start(1000) def playWithHuman(): subprocess.Popen(strings.PLAY_WITH_HUMAN) def playWithMachine(): """ map_name = '3m' difficulty = '3' param_set = {} param_set['gamma'] = 0.99 param_set['td_lambda'] = 0.8 param_set['learning_rate'] = 0.0005 param_set['alpha'] = 0.99 param_set['eps'] = 1e-05 param_set['epsilon_start'] = 1 param_set['epsilon_end'] = 0.01 param_set['time_length'] = 100000 param_set['grad_norm_clip'] = 10 param_set['before_learn'] = 50 param_set['batch_size'] = 16 param_set['target_update_interval'] = 400 # # # iql set # param_set['algorithm'] = 'iql_CT' # path = '../model/' + map_name + '_iql_CT_3/' # COMA set param_set['algorithm'] = 'COMA' path = '../model/' + map_name + '_COMA_3/' param_set['map_name'] = map_name param_set['difficulty'] = difficulty param_set['path'] = path param_set['load_model'] = True param_set['test'] = True # self.algorithm = MARL() # self.algorithmThread = threading.Thread( # target=self.algorithm.algorithm(param_set), # name='StarCraft2Thread') """ # self.algorithm = AlgorithmAgent() # self.algorithm.start() self.algorithm = MasterAgent() self.algorithm.start() if globalInformation.get_value('pattern') == strings.HUMAN_VS_MACHINE: playWithHuman() elif globalInformation.get_value('pattern') == strings.MACHINE_VS_MACHINE: playWithMachine() # Signal.get_signal().emit_signal_none() # pause simulation def pauseEvent(self): message = 'pause the simulation' self.log.info(message) Signal.get_signal().emit_signal_str(message) if OperationalPlanning.stop: return if OperationalPlanning.start_or_pause: self.qtime.stop() OperationalPlanning.start_or_pause = False else: self.qtime.start(1000) OperationalPlanning.start_or_pause = True # stop simulation def stopEvent(self): message = 'stop the simulation' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.qtime.stop() OperationalPlanning.start_or_pause = False OperationalPlanning.stop = True globalInformation.set_value(strings.IS_STOP, True) # a description of current map def mapEvent(self): message = 'open the map description' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('map description') self.dialog = QDialog() mapDialog = MapDescriptionDialog() mapDialog.setupUi(self.dialog) self.dialog.setModal(True) self.window.setWidget(self.dialog) self.initFrameLessWindow( QSize(700, 600), 'Operational Planning', QIcon('../resource/drawable/logo.png') ) self.window.show() # self.dialog.show() # switch policy of a dialog # there is a description of each algorithm def switchEvent(self): message = 'switch policy' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('switch policy') self.dialog = QDialog() # tab item name list_str = [ strings.ALGORITHM_COMA, strings.ALGORITHM_COMMNET_COMA, strings.ALGORITHM_QMIX, strings.ALGORITHM_QTRAN_ALT, strings.ALGORITHM_QTRAN_BASE, strings.ALGORITHM_VDN ] # item content list_item = [ strings.CLASS_ALGORITHM_COMA, strings.CLASS_ALGORITHM_COMMNET_COMA, strings.CLASS_ALGORITHM_QMIX, strings.CLASS_ALGORITHM_QTRAN_ALT, strings.CLASS_ALGORITHM_QTRAN_BASE, strings.CLASS_ALGORITHM_VDN ] # title name self.listDialog = ListDialog(list_str, list_item, strings.OPERATIONAL_PLANNING_TITLE, strings.TYPE_POLICY) self.listDialog.setupUi(self.dialog, self.window) self.window.setWidget(self.dialog) self.initFrameLessWindow( QSize(700, 600), 'Operational Planning', QIcon('../resource/drawable/logo.png') ) self.window.show() # self.dialog.setModal(True) # self.dialog.show() def initFrameLessWindow(self, size, title, icon): self.window.resize(size) self.window.setWindowTitle(title) self.window.setWindowIcon(icon)
class ModelTrain(QWidget): def __init__(self): super(ModelTrain, self).__init__() self.setObjectName('ModelTrain') self.setStyleSheet( GetQssFile.readQss('../resource/qss/modelTrain.qss')) self.log = logging.getLogger('StarCraftII') # font font = QFont() font.setWeight(50) font.setPixelSize(15) # set widget of layout self.frame = QFrame(self) self.frame.setGeometry(QDesktopWidget().screenGeometry()) self.main_layout = QHBoxLayout(self) self.main_layout.setSpacing(20) self.setLayout(self.main_layout) # model tarin self.modelTrain = QPushButton() self.modelTrain.setObjectName('modelTrain') self.modelTrainLabel = QLabel('model train') self.modelTrainLabel.setFont(font) self.modelTrain_layout = QVBoxLayout() self.modelTrain_layout.addWidget(self.modelTrain, alignment=Qt.AlignCenter) self.modelTrain_layout.addWidget(self.modelTrainLabel, alignment=Qt.AlignCenter) self.main_layout.addLayout(self.modelTrain_layout) # a description dialog self.dialog = None # add stretch self.main_layout.addStretch(1) # initialization self.initUI() def initUI(self): self.modelTrain.clicked.connect(self.buttonEvent) def buttonEvent(self): sender = self.sender() if sender == self.modelTrain: self.modelTrainEvent() def modelTrainEvent(self): message = 'the setting of model train' self.log.info(message) Signal.get_signal().emit_signal_str(message) self.window = FramelessWindow('model train') self.dialog = QDialog() description = "a description of model train" model = ModelTrainDescriptionDialog(description) model.setupUi(self.dialog) self.window.setWidget(self.dialog) self.initFrameLessWindow(QSize(700, 600), 'Model Train', QIcon('../resource/drawable/logo.png')) self.window.show() # self.dialog.setModal(True) # self.dialog.show() def initFrameLessWindow(self, size, title, icon): self.window.resize(size) self.window.setWindowTitle(title) self.window.setWindowIcon(icon)