Example #1
0
 def setUp(self):
     # Create two boards, both of which form a nand loop
     self.boards = [
         # Directly output to simnode
         Board.deserialize("--D\n"
                           "u.d\n"
                           "---\n"),
         # Output via wire
         Board.deserialize("--D\n"
                           "u.-\n"
                           "--l\n")
     ]
     # Keep track of the leftmost nand on both grids.
     # They should both always have the same value.
     self.nands = [b.get((0, 1)) for b in self.boards]
Example #2
0
    def setUp(self):
        board_str = ("-r--\n")
        self.board = Board.deserialize(board_str)

        self.input_wire = self.board.get((0, 0))
        self.nand = self.board.get((1, 0))
        self.output_wires = [self.board.get((2, 0)), self.board.get((3, 0))]
Example #3
0
 def setUp(self):
     board_str = ("...o..\n"
                  "-R-|--\n"
                  "...-..\n")
     self.board = Board.deserialize(board_str)
     self.bridge_coords = (3, 1)
     self.bridge = self.board.get(self.bridge_coords)
Example #4
0
 def setUp(self):
     board_str = (".--l..\n"
                  "......\n"
                  "-r.|.-\n"
                  "......\n")
     self.board = Board.deserialize(board_str)
     self.bridge_coords = (3, 2)
     self.bridge = self.board.get(self.bridge_coords)
Example #5
0
    def setUp(self):
        board_str = ("-R---")
        self.board = Board.deserialize(board_str)

        self.nand = self.board.get((1, 0))

        # Split the wire
        self.board.set((3, 0), None)
Example #6
0
    def setUp(self):
        self.board = Board.deserialize("R--\n"
                                       "-..\n")
        self.nand = self.board.get((0, 0))
        self.bottom_wire = self.board.get((0, 1))
        self.right_wire = self.board.get((2, 0))

        self.nand.rotate_facing(1, (0, 0), self.board)
Example #7
0
    def setUp(self):
        board_str = ("-r-..-\n" "-.-..x\n" "---..-\n")
        self.board = Board.deserialize(board_str)

        self.nand = self.board.get((1, 0))
        self.nand_wire = self.board.get((1, 2))

        self.switch = self.board.get((5, 1))
        self.switch_wires = [self.board.get((5, 0)), self.board.get((5, 2))]
Example #8
0
    def setUp(self):
        board_str = ("-rR-.\n" ".....\n" "-r-R-\n")
        self.board = Board.deserialize(board_str)

        self.input_wires = [self.board.get((0, 0)), self.board.get((0, 2))]
        self.left_nands = [self.board.get((1, 0)), self.board.get((1, 2))]
        self.right_nands = [self.board.get((2, 0)), self.board.get((3, 2))]
        self.output_wires = [self.board.get((3, 0)), self.board.get((4, 2))]
        self.middle_wire = self.board.get((2, 2))
Example #9
0
    def setUp(self):
        board_str = ("---\n"
                     "d..\n"
                     "---\n")
        self.board = Board.deserialize(board_str)
        self.nand = self.board.get((0, 1))

        # Dynamically finish the loop
        self.board.set((2, 1), Wire())
Example #10
0
    def setUp(self):
        board_str = (".--l..\n" "...-..\n" "-r-|--\n" "...-..\n")
        self.board = Board.deserialize(board_str)
        self.top_nand = self.board.get((3, 0))
        self.right_wire = self.board.get((5, 2))
        self.bridge = self.board.get((3, 2))

        self.board.tick()
        self.board.tick()
        self.board.tick()
Example #11
0
    def setUp(self):
        board_str = ("-R-.-")
        self.board = Board.deserialize(board_str)

        self.nand = self.board.get((1, 0))

        # Join the two wires
        self.new_wire = Wire()
        self.board.set((3, 0), self.new_wire)
        self.placed_wire = self.board.get((3, 0))
Example #12
0
def main():

    parser = argparse.ArgumentParser(description='Tile-based digital logic '
                                     'sandbox')
    parser.add_argument('--file', help='Load state from file')
    parser.add_argument('-x',
                        '--width',
                        dest='width',
                        metavar='N',
                        type=int,
                        default=10,
                        help='Width of the board')
    parser.add_argument('-y',
                        '--height',
                        dest='height',
                        metavar='N',
                        type=int,
                        default=10,
                        help='Height of the board')

    box_parser = parser.add_mutually_exclusive_group(required=False)
    box_parser.add_argument('--box-draw',
                            dest='box_draw',
                            action='store_true',
                            help='Enable UTF-8 box drawing characters')
    box_parser.add_argument('--no-box-draw',
                            dest='box_draw',
                            action='store_false',
                            help='Disable UTF-8 box drawing characters')
    box_parser.set_defaults(box_draw=True)

    args = parser.parse_args()

    logger.debug(args)

    if args.file:
        # Read board from file
        with open(args.file, 'r') as f:
            board_str = f.read()
            board = Board.deserialize(board_str)
    else:
        # Create a new board
        board = Board()
        board.initialize_grid((args.width, args.height))

    # # Start up the UI
    world = World([board])
    t = TermUI(args, world)
    # Block until we quit the UI
    t.start()
Example #13
0
    def setUp(self):
        board_str = ("r-...-l\n"
                     "r-----l\n"
                     "l-...-r\n")
        self.board = Board.deserialize(board_str)
        self.center_coords = (3, 1)

        self.left_input_nands = {self.board.get((0, 0)),
                                 self.board.get((0, 1))}
        self.left_output_nand = self.board.get((0, 2))

        self.right_input_nands = {self.board.get((6, 0)),
                                  self.board.get((6, 1))}
        self.right_output_nand = self.board.get((6, 2))
Example #14
0
    def setUp(self):
        board_str = ("--...-\n" "d....-\n" "--...-\n")
        self.board = Board.deserialize(board_str)

        self.board.copy((0, 0), (2, 3), (3, 0))
Example #15
0
 def setUp(self):
     self.board = Board.deserialize("dd\n")
     self.nand = self.board.get((0, 0))
Example #16
0
 def setUp(self):
     self.board_str = ("--udlr\n" "--UDLR\n" "U-xo--\n")
     self.board = Board.deserialize(self.board_str)
Example #17
0
 def setUp(self):
     board_str = ("r----r-.-\n"
                  ".-.......\n"
                  "-l-d.....\n"
                  "-..--....\n")
     self.board = Board.deserialize(board_str)
Example #18
0
    def setUp(self):
        board_str = ("-R-r-")
        self.board = Board.deserialize(board_str)
        self.board.set((3, 0), Wire())

        self.nand = self.board.get((1, 0))
Example #19
0
 def setUp(self):
     board_str = (".--\n"
                  "d.-\n"
                  ".--\n")
     self.board = Board.deserialize(board_str)
     self.nand = self.board.get((0, 1))