Exemplo n.º 1
0
    def save_data(self):
        """
        puts the loaded configuration parameters in the dict and save it
        """
        if not self.current_configuration:
            return

        groupboxes = [
            self.ui_cw.groupBox, self.ui_cw.groupBox_2, self.ui_cw.groupBox_3
        ]

        for igroupbox in groupboxes:  # por cada groupbox

            for ikey in self.current_configuration.keys():

                if ikey not in JSON_CONFIGURATION_KEYS:
                    continue
                item_le = igroupbox.findChild(QtWidgets.QLineEdit, ikey)
                item_cob = igroupbox.findChild(QtWidgets.QComboBox, ikey)
                item_chb = igroupbox.findChild(QtWidgets.QCheckBox, ikey)
                item_sb = igroupbox.findChild(QtWidgets.QSpinBox, ikey)
                item_dsb = igroupbox.findChild(QtWidgets.QDoubleSpinBox, ikey)
                item_tw = igroupbox.findChild(QtWidgets.QTableWidget, ikey)
                if item_le is not None:
                    text = item_le.text()
                    # intentar convertir la cadena a float (si es un numero), de otro
                    # modo es directamente un string (por ejemplo, label)
                    text = convert_string(text)
                    self.current_configuration[ikey] = text
                elif item_cob is not None:
                    if ikey in CB_GET_VALUE:
                        self.current_configuration[ikey] = convert_string(
                            item_cob.currentText())
                    else:
                        self.current_configuration[
                            ikey] = item_cob.currentIndex()
                elif item_sb is not None:
                    self.current_configuration[ikey] = item_sb.value()
                elif item_dsb is not None:
                    self.current_configuration[ikey] = item_dsb.value()
                elif item_tw is not None:
                    self.get_table(ikey, item_tw, self.current_configuration)
                elif item_chb is not None:
                    self.current_configuration[ikey] = 1 if item_chb.isChecked(
                    ) else 0
                else:
                    continue

        return self.current_configuration
Exemplo n.º 2
0
 def get_table(self, ikey, table, current_dict, factor):
     if not table.isEnabled():
         return
     ncols = table.columnCount()
     nrows = table.rowCount()
     current_dict[ikey] = []
     for irow in range(0, nrows):
         dict_row = []
         for icol in range(0, ncols):
             if not table.item(irow, icol):
                 current_dict[ikey] = []
                 show_message(
                     'Please provide all the fields for the %s table' %
                     ikey)
                 # dejo que salte el error en el try de accept
             text = table.item(irow, icol).text()
             text_parsed = convert_string(text)
             text_parsed = text_parsed * factor[icol]
             if ncols == 1:
                 current_dict[ikey].append(text_parsed)
             else:
                 dict_row.append(text_parsed)
         if dict_row != []:
             current_dict[ikey].append(dict_row)
     return
Exemplo n.º 3
0
    def generate_play(self, grid):
        # print("received grid : ", grid)
        # maxgrid, index = get_max_rotation(grid)
        maxgrid, index = grid.copy(), 0
        # print("maxgrid", maxgrid, "index", index)
        strigrid = convert_string(maxgrid)
        if strigrid in self.moves:
            move = self.moves[strigrid]
            tryhard = (move["loss"] - move["win"]) * 100
            if tryhard < random.randint(0, 100):
                # print("found move on maxgrid", move["play"])
                play = perm_x(move["play"], 4 - index)
                self.new_moves[strigrid] = perm_x(play, index)

                # print("returned move", play)
                return int(play)
            # print("tryhard --------------------------------------------------")
        picks = [i for i, x in enumerate(grid) if not x]
        play = random.choice(picks)
        self.new_moves[strigrid] = perm_x(play, index)
        if not strigrid[int(play)]:
            print("picked move :")
            from TicTac import display
            display(grid)
            print("play :", play)
            print("saved move :")
            display(strigrid)
            print("play :", perm_x(play, index))

        return play
Exemplo n.º 4
0
 def get_table(self, ikey, table, current_dict, factor=1.0):
     if not table.isEnabled():
         return True
     ncols = table.columnCount()
     nrows = table.rowCount()
     current_dict[ikey] = [] if ikey!='state_ini' else current_dict[ikey]
     for irow in range(0, nrows):
         dict_row = []
         for icol in range(0, ncols):
             if not table.item(irow,icol):
                 current_dict[ikey] = []
                 show_message('Please provide all the fields for the %s table'%ikey)
                 return False
             if not check_if_float(table.item(irow,icol).text(), ikey):
                 show_message('Please provide valid values for the %s table'%ikey)
                 current_dict[ikey] = []
                 return False
             text = table.item(irow,icol).text()
             text_parsed = convert_string(text)
             text_parsed = text_parsed*factor
             if ncols==1:
                 current_dict[ikey].append(text_parsed)
             else:
                 dict_row.append(text_parsed)
         if dict_row!=[]:
             current_dict[ikey].append(dict_row)
     return True
Exemplo n.º 5
0
 def get_table(self, ikey, table, current_dict):
     ncols = table.columnCount()
     nrows = table.rowCount()
     current_dict[ikey] = []
     for irow in range(0, nrows):
         for icol in range(0, ncols):
             text = table.item(irow, icol).text()
             text = convert_string(text)
             current_dict[ikey].append(text)
     return
Exemplo n.º 6
0
    def accept(self):
        """
        puts the loaded configuration parameters in the dict and save it
        """
        if not self.current_dict:
            return

        if not self.verify_fields():
            return

        self.current_dict['histo'] = []
        tabs = (0,4,5)
        
        self.current_dict['state_ini'] = []
        ret = self.get_table('state_ini_0', self.ui_cd.state_ini_0, self.current_dict)
        self.current_dict['state_ini'].append(self.current_dict['state_ini_0'][0])
        del self.current_dict['state_ini_0']

        for itab in range(6): # por cada tab del widget

            current_dict = self.current_dict if itab in tabs else \
                                            self.current_dict[DICT_KEYS[itab-1]]

            for ikey in current_dict.keys():

                if ikey not in JSON_CYLINDER_KEYS:
                    continue
                item_le  = self.ui_cd.tabWidget.widget(itab).findChild(QtWidgets.QLineEdit,ikey)
                item_cob = self.ui_cd.tabWidget.widget(itab).findChild(QtWidgets.QComboBox,ikey)
                item_chb = self.ui_cd.tabWidget.widget(itab).findChild(QtWidgets.QCheckBox,ikey)
                item_sb  = self.ui_cd.tabWidget.widget(itab).findChild(QtWidgets.QSpinBox,ikey)
                item_dsb = self.ui_cd.tabWidget.widget(itab).findChild(QtWidgets.QDoubleSpinBox,ikey)
                item_tw  = self.ui_cd.tabWidget.widget(itab).findChild(QtWidgets.QTableWidget,ikey)
                if item_le is not None:
                    text = item_le.text()
                    text = convert_string(text)
                    current_dict[ikey] = text
                    current_dict[ikey] = self.parse_data(current_dict,ikey,DEPARSED,DEEXTRAS)
                elif item_cob is not None:
                    if ikey in CB_GET_VALUE:
                        current_dict[ikey] = convert_string(item_cob.currentText())
                    else:
                        current_dict[ikey] = item_cob.currentIndex()
                    current_dict[ikey] = self.parse_data(current_dict,ikey,DEPARSED,DEEXTRAS)
                elif item_sb is not None:
                    current_dict[ikey] = item_sb.value()
                    current_dict[ikey] = self.parse_data(current_dict,ikey,DEPARSED,DEEXTRAS)
                elif item_dsb is not None:
                    current_dict[ikey] = item_dsb.value()
                    current_dict[ikey] = self.parse_data(current_dict,ikey,DEPARSED,DEEXTRAS)
                elif item_tw is not None:
                    ret = self.get_table(ikey, item_tw, current_dict)
                    if not ret:
                        return
                elif item_chb is not None:
                    if type(current_dict[ikey])==list:
                        current_dict[ikey] = [0] if item_chb.isChecked() else []
                    else:
                        current_dict[ikey] = 1 if item_chb.isChecked() else 0
                        current_dict[ikey] = self.parse_data(current_dict,ikey,DEPARSED,DEEXTRAS)
                else:
                    continue

        self.set_histogram()
        self.close()
        return