Example #1
0
 def new_zoids(self):
     """Sets current zoid to next zoid and chooses a new random zoid for the
     next zoid.
     :modifies: self.curr_z, self.next_z
     """
     self.curr_z = self.next_z
     self.next_z = self.sequence.choice(all_zoids.values())
Example #2
0
 def new_zoids(self):
     """Sets current zoid to next zoid and chooses a new random zoid for the
     next zoid.
     :modifies: self.curr_z, self.next_z
     """
     self.curr_z = self.next_z
     self.next_z = self.sequence.choice(all_zoids.values())
    def __init__(self,
                 board=None,
                 curr=None,
                 next=None,
                 controller=None,
                 show_scores=False,
                 show_options=False,
                 show_result=True,
                 show_choice=False,
                 option_step=0,
                 choice_step=0,
                 name="Controller",
                 seed=time.time(),
                 overhangs=False,
                 force_legal=True):
        """Initializes the simulator object.
        :param board: A board representation [20 rows, 10 columns].
        :param curr: The current zoid.
        :param next: The next zoid.
        :param controller: A dictionary of feature names and their relative weights.
        :param show_scores: Whether to display the scores of the current moves.
        :param show_options: Whether to print **POTENTIAL** move as it is considered.
        :param show_result: Whether to print the results of each game.
        :param show_choice: Whether to show the **CHOSEN** move.
        :param option_step: The delay time (in seconds) for displaying each option (**COSTLY**).
        :param choice_step: The delay time (in seconds) for displaying each choice (**COSTLY**).
        :param name: The name given for logging and tracking purposes (printed during long runs).
        :param overhangs: If enabled, uses a more robust system for determining possible moves.
        :param force_legal: Enables an A* search to determine if overhang moves are actually legal (COSTLY).
        :type board: tetris_cow2
        :type curr: tetris_zoid
        :type next: tetris_zoid
        :type controller: dictionary {string : float}
        :type show_scores: bool
        :type show_options: bool
        :type show_result: bool
        :type show_choice: bool
        :type option_step: float
        :type choice_step: float
        :type name: string
        :type overhangs: bool
        :type force_legal: bool
        """

        self.sequence = random.Random(seed)

        if board:
            self.space = board
        else:
            self.space = tetris_cow2(rows=20)

        if curr:
            self.curr_z = curr
        else:
            self.curr_z = self.sequence.choice(all_zoids.values())

        if next:
            self.next_z = next
        else:
            self.next_z = self.sequence.choice(all_zoids.values())

        self.name = name

        self.overhangs = overhangs
        self.force_legal = force_legal

        if controller:
            self.controller = controller
        else:  # default Dellacherie model
            self.controller = {
                "landing_height": -1,
                "eroded_cells": 1,
                "row_trans": -1,
                "col_trans": -1,
                "pits": -4,
                "cuml_wells": -1
            }

        # display options saved
        self.show_result = show_result
        self.show_scores = show_scores
        self.show_options = show_options
        self.show_choice = show_choice

        self.option_step = option_step
        self.choice_step = choice_step

        # output scores initialized
        #self.heights = get_heights(self.space)
        #self.pits = get_all_pits(self.space)
        #self.col_roughs = self.get_roughs(self.space, columns = True)
        #self.row_roughs = self.get_roughs(self.space, columns = False)
        #self.ridge = self.get_ridge(self.space)
        #self.matches = []

        self.lines = 0
        self.l = {1: 0, 2: 0, 3: 0, 4: 0}
        self.score = 0
        self.level = 0
Example #4
0
    def __init__(self, board=None, curr=None, next=None, controller=None,
                 show_scores=False, show_options=False, show_result=True,
                 show_choice=False, option_step=0, choice_step=0,
                 name="Controller", seed=time.time(), overhangs=False,
                 force_legal=True):
        """Initializes the simulator object.
        :param board: A board representation [20 rows, 10 columns].
        :param curr: The current zoid.
        :param next: The next zoid.
        :param controller: A dictionary of feature names and their relative weights.
        :param show_scores: Whether to display the scores of the current moves.
        :param show_options: Whether to print **POTENTIAL** move as it is considered.
        :param show_result: Whether to print the results of each game.
        :param show_choice: Whether to show the **CHOSEN** move.
        :param option_step: The delay time (in seconds) for displaying each option (**COSTLY**).
        :param choice_step: The delay time (in seconds) for displaying each choice (**COSTLY**).
        :param name: The name given for logging and tracking purposes (printed during long runs).
        :param overhangs: If enabled, uses a more robust system for determining possible moves.
        :param force_legal: Enables an A* search to determine if overhang moves are actually legal (COSTLY).
        :type board: tetris_cow2
        :type curr: tetris_zoid
        :type next: tetris_zoid
        :type controller: dictionary {string : float}
        :type show_scores: bool
        :type show_options: bool
        :type show_result: bool
        :type show_choice: bool
        :type option_step: float
        :type choice_step: float
        :type name: string
        :type overhangs: bool
        :type force_legal: bool
        """

        self.sequence = random.Random(seed)

        if board:
            self.space = board
        else:
            self.space = tetris_cow2(rows=20)

        if curr:
            self.curr_z = curr
        else:
            self.curr_z = self.sequence.choice(all_zoids.values())

        if next:
            self.next_z = next
        else:
            self.next_z = self.sequence.choice(all_zoids.values())

        self.name = name

        self.overhangs = overhangs
        self.force_legal = force_legal

        if controller:
            self.controller = controller
        else:  # default Dellacherie model
            self.controller = {"landing_height": -1,
                               "eroded_cells": 1,
                               "row_trans": -1,
                               "col_trans": -1,
                               "pits": -4,
                               "cuml_wells": -1}

        # display options saved
        self.show_result = show_result
        self.show_scores = show_scores
        self.show_options = show_options
        self.show_choice = show_choice

        self.option_step = option_step
        self.choice_step = choice_step

        # output scores initialized
        self.lines = 0
        self.l = {1: 0, 2: 0, 3: 0, 4: 0}
        self.score = 0
        self.level = 0