コード例 #1
0
 def __init__(self, tower_len, dna_len, initialize=False):
     self._dna = []
     self._tower = Hanoi(tower_len)
     if dna_len < 2**tower_len - 1:
         raise Exception("dna_len must be greater or equal than " +
                         str(2**tower_len - 1))
     self._dna_len = dna_len
     if initialize:
         self._initialize()
コード例 #2
0
ファイル: main.py プロジェクト: nbaak/Towers-of-Hanoi
def main():
    """
    function based
    disks = 3
    solve (disks, "A", "B", "C")
    """

    # class based
    h = Hanoi(3)
    h.solve("a", "b", "c")
コード例 #3
0
    def _init_hanoi(self):
        # Variables for the animation
        self._next_move = True
        self._move = 0
        self._starting_left = 0
        self._starting_top = 0
        self._target_left = 0
        self._target_top = 0
        self._acceleration = 0
        self._time_spent = 0

        # Flags indicating the state of the program
        self._running_flag = False
        self._step_by_step_flag = False
        self._over_flag = False

        # Reset the trigger_button to 'Start'
        self._trigger_button.text = 'Start'

        # Hanoi algorithm object
        self._hanoi = Hanoi(input('Please enter the number of plates\n'))

        # Initialization of the plate images
        for each_plate in self._hanoi.get_plates(0):
            plate_image = TextButton(self)
            plate_image.rect = (70 + self._hanoi.get_total() * PLATE_BASE_WIDTH / 2) - each_plate.number * PLATE_BASE_WIDTH / 2, \
                               (WINDOW_HEIGHT - self._hanoi.get_total() * PLATE_HEIGHT) + each_plate.number * PLATE_HEIGHT, \
                               PLATE_BASE_WIDTH * (each_plate.number + 1), \
                               PLATE_HEIGHT

            plate_image.background = r'Images\Root_button.png'
            self._plate_images.insert(0, plate_image)

        # Start running the hanoi algorithm and animation
        self._steps = self._hanoi.move(self._hanoi.get_total(), 0, 2)
        self._animation = koan.anim.IntervalExecute(TIME_INTERVAL,
                                                    self._onTimer)
コード例 #4
0
from RobotVision import SearchTool
from Hanoi import Hanoi
import time

rospy.init_node("vision")

print("Getting robot state... ")
rs = baxter_interface.RobotEnable(CHECK_VERSION)
init_state = rs.state().enabled
rightArm = baxter_interface.Limb("right")
leftArm = baxter_interface.Limb("left")
leftGripper = baxter_interface.Gripper('left', CHECK_VERSION)
rightGripper = baxter_interface.Gripper('right', CHECK_VERSION)
camera = CameraSubscriber()

hanoi = Hanoi(3)

searchTool = SearchTool("camera_img.png")


def goToOrigin():
    rightJoints = {
        'right_s0': 0.0,
        'right_s1': .3,
        'right_e0': 0,
        'right_e1': 1,
        'right_w0': 0,
        'right_w1': 0.2,
        'right_w2': 0
    }
    leftJoints = {
コード例 #5
0
from Hanoi import Hanoi, Stack, turtle


def moveTower(height, fromPole, toPole, auxPole):
    """Solve Tower of Hanoi problem depending on height."""
    if height == 1:
        moveDisk(fromPole, toPole)
        h.moveDisks(fromPole, toPole)

    else:
        moveTower(height - 1, fromPole, auxPole, toPole)
        moveDisk(fromPole, toPole)
        h.moveDisks(fromPole, toPole)
        moveTower(height - 1, auxPole, toPole, fromPole)


def moveDisk(fromPole, toPole):
    """Print the moves made."""
    print(f"Move from {fromPole} to {toPole}")


h = Hanoi(4)
moveTower(4, "A", "C", "B")
h.wn.exitonclick()