def setup():
    global _has_setup_ui

    if _has_setup_ui == True:
        logging.warn("ui setup() function called more than once")
        return

    win = getMainWindow()
    if win == None:
        raise AssertionError("Unable to get a reference to the main window")

    pcTab = win.findChild(QtWidgets.QTreeView, 'plays')

    # setup play config tab
    pcTab.setModel(main.play_registry())
    pcTab.expandAll()
    pcTab.resizeColumnToContents(0)

    logging.debug("Initialized PlayConfigTab")

    # bind the play label in the ui to the name of the current play
    play_name_label = win.findChild(QtWidgets.QLabel, 'current_play_name')
    main.root_play().play_changed.connect(play_name_label.setText)

    _has_setup_ui = True
Example #2
0
def setup():
    global _has_setup_ui
    global _defense_checkbox

    if _has_setup_ui == True:
        logging.warn("ui setup() function called more than once")
        return

    win = getMainWindow()
    if win == None:
        raise AssertionError("Unable to get a reference to the main window")

    pcTab = win.findChild(QtWidgets.QTreeView, 'plays')

    # setup play config tab
    pcTab.setModel(main.play_registry())
    pcTab.expandAll()
    pcTab.resizeColumnToContents(0)

    logging.debug("Initialized PlayConfigTab")

    # bind the play label in the ui to the name of the current play
    play_name_label = win.findChild(QtWidgets.QLabel, 'current_play_name')
    _defense_checkbox = win.findChild(QtWidgets.QCheckBox,
                                      'useDefenseCheckBox')

    main.root_play().play_changed.connect(play_name_label.setText)

    _has_setup_ui = True
Example #3
0
    def execute_running(self):
        # update double touch tracker
        evaluation.double_touch.tracker().spin()

        # cache and calculate the score() function for each play class
        main.play_registry().recalculate_scores()

        # Play Selection
        ################################################################################

        if main.game_state().is_stopped():
            evaluation.double_touch.tracker().restart()
            if main.game_state().is_placement():
                if not isinstance(self.play,
                                  plays.restarts.placement.Placement):
                    logging.info("Placing Ball")
                    self.play = plays.restarts.placement.Placement()
                    self._currently_restarting = True
            else:
                if self.play is None or not self.play.run_during_stopped():
                    logging.info(
                        "Running 'Stopped' play due to game state change")
                    self.play = plays.stopped.Stopped()
                    self._currently_restarting = True
        elif main.game_state().is_halted():
            evaluation.double_touch.tracker().restart()
            self.play = None
        else:
            # (play_class, score value) tuples
            enabled_plays_and_scores = [
                p for p in main.play_registry().get_enabled_plays_and_scores()
            ]

            # only let restart play run once
            enabled_plays_and_scores = [
                p for p in enabled_plays_and_scores
                if not p[0].is_restart() or (
                    p[0].is_restart() and self._currently_restarting)
            ]

            # handle temporary blacklisting
            # we remove the blacklisted play class from selection for this iteration, then unblacklist it
            enabled_plays_and_scores = [
                p for p in enabled_plays_and_scores
                if p[0] != self.temporarily_blacklisted_play_class
            ]
            self.temporarily_blacklisted_play_class = None

            # see if we need to kill current play or if it's done running
            if self.play is not None:
                if self.play.__class__ not in map(lambda tup: tup[0],
                                                  enabled_plays_and_scores):
                    logging.info("Current play '" +
                                 self.play.__class__.__name__ +
                                 "' no longer enabled, aborting")
                    self.play.terminate()
                    self.play = None
                elif self.play.is_done_running():
                    logging.info("Current play '" +
                                 self.play.__class__.__name__ +
                                 "' finished running")
                    if self.play.is_restart:
                        self._currently_restarting = False
                    self.play = None
                elif self.play.__class__.score() == float("inf"):
                    logging.info("Current play '" +
                                 self.play.__class__.__name__ +
                                 "' no longer applicable, ending")
                    self.play.terminate()
                    self.play = None

            if self.play is None:
                try:
                    if len(enabled_plays_and_scores) > 0:
                        # select the play with the smallest value for score()
                        play_class_and_score = min(enabled_plays_and_scores,
                                                   key=lambda tup: tup[1])

                        # run the play with the lowest score, as long as it isn't inf
                        if play_class_and_score[1] != float("inf"):
                            play_class = play_class_and_score[0]
                            self.play = play_class()  # instantiate it
                    else:
                        # there's no available plays to run
                        pass
                except Exception as e:
                    logging.error(
                        "Exception occurred during play selection: " + str(e))
                    traceback.print_exc()
                if self.play is not None:
                    logging.info("Chose new play: '" +
                                 self.play.__class__.__name__ + "'")

        # Role Assignment
        ################################################################################
        try:
            assignments = role_assignment.assign_roles(
                self.robots, self.role_requirements())
        except role_assignment.ImpossibleAssignmentError as e:
            logging.error(
                "Unable to satisfy role assignment constraints.  Dropping and temp. blacklisting current play..."
            )
            self.drop_current_play(temporarily_blacklist=True)
        else:
            self.assign_roles(assignments)
Example #4
0
    def execute_running(self):
        # update double touch tracker
        evaluation.double_touch.tracker().spin()

        # cache and calculate the score() function for each play class
        main.play_registry().recalculate_scores()

        # Play Selection
        ################################################################################

        if main.game_state().is_stopped():
            if not isinstance(self.play, plays.stopped.Stopped):
                logging.info("Running 'Stopped' play due to game state change")
                self.play = plays.stopped.Stopped()
                self._currently_restarting = True
        elif main.game_state().is_halted():
            self.play = None
        else:
            # (play_class, score value) tuples
            enabled_plays_and_scores = [p for p in main.play_registry().get_enabled_plays_and_scores()]

            # only let restart play run once
            enabled_plays_and_scores = [p for p in enabled_plays_and_scores if not p[0].is_restart() or ( p[0].is_restart() and self._currently_restarting)]

            # handle temporary blacklisting
            # we remove the blacklisted play class from selection for this iteration, then unblacklist it
            enabled_plays_and_scores = [p for p in enabled_plays_and_scores if p[0] != self.temporarily_blacklisted_play_class]
            self.temporarily_blacklisted_play_class = None

            # see if we need to kill current play or if it's done running
            if self.play != None:
                if self.play.__class__ not in map(lambda tup: tup[0], enabled_plays_and_scores):
                    logging.info("Current play '" + self.play.__class__.__name__ + "' no longer enabled, aborting")
                    self.play.terminate()
                    self.play = None
                elif self.play.is_done_running():
                    logging.info("Current play '" + self.play.__class__.__name__ + "' finished running")
                    if self.play.is_restart:
                        self._currently_restarting = False
                    self.play = None
                elif self.play.__class__.score() == float("inf"):
                    logging.info("Current play '" + self.play.__class__.__name__ + "' no longer applicable, ending")
                    self.play.terminate()
                    self.play = None

            if self.play == None:
                # reset the double-touch tracker
                evaluation.double_touch.tracker().restart()

                try:
                    if len(enabled_plays_and_scores) > 0:
                        # select the play with the smallest value for score()
                        play_class_and_score = min(enabled_plays_and_scores, key=lambda tup: tup[1])

                        # run the play with the lowest score, as long as it isn't inf
                        if play_class_and_score[1] != float("inf"):
                            play_class = play_class_and_score[0]
                            self.play = play_class() # instantiate it
                    else:
                        # there's no available plays to run
                        pass
                except Exception as e:
                    logging.error("Exception occurred during play selection: " + str(e))
                    traceback.print_exc()
                if self.play != None:
                    logging.info("Chose new play: '" + self.play.__class__.__name__ + "'")


        # Role Assignment
        ################################################################################
        try:
            assignments = role_assignment.assign_roles(self.robots, self.role_requirements())
        except role_assignment.ImpossibleAssignmentError as e:
            logging.error("Unable to satisfy role assignment constraints.  Dropping and temp. blacklisting current play...")
            self.drop_current_play(temporarily_blacklist=True)
        else:
            self.assign_roles(assignments)
 def __init__(self):
     super().__init__()
     self.setModel(main.play_registry())
     self.expandAll()
     self.resizeColumnToContents(0)
 def __init__(self):
     super().__init__()
     self.setModel(main.play_registry())
     self.expandAll()
     self.resizeColumnToContents(0)