Example #1
0
def test_child(child, cur_piece, net):
    LAYER_1, LAYER_2, LAYER_3 = net[0], net[1], net[2]
    pieces = list(child.players['one']) + list(child.players['two'])
    pieces.sort(key=lambda x: x.num)
    index = 0
    inputs = np.zeros((17, 1))
    for piece in pieces:
        inputs[index] = piece.x
        inputs[index + 1] = piece.y
        index += 2
    inputs[16] = cur_piece
    inputs = network.normalize(inputs)
    inputs[16] = (
        inputs[16] * 6
    ) / 8  # the current piece is the only input not from 0-6 so we re-normalize it for 1-8
    out = LAYER_3.feed(LAYER_2.feed(LAYER_1.feed(inputs)))
    return out[0]
Example #2
0
def main():
    """
    Main command-line execution loop.
    """
    try:
        # Parse command line options
        parser, options, arguments = parse_options()

        # Update env with any overridden option values
        # NOTE: This needs to remain the first thing that occurs
        # post-parsing, since so many things hinge on the values in env.
        for option in env_options:
            state.env[option.dest] = getattr(options, option.dest)

        # Handle --hosts, --roles (comma separated string => list)
        for key in ['hosts', 'roles']:
            if key in state.env and isinstance(state.env[key], str):
                state.env[key] = state.env[key].split(',')

        # Handle output control level show/hide
        update_output_levels(show=options.show, hide=options.hide)

        # Handle version number option
        if options.show_version:
            print("Fabric %s" % state.env.version)
            sys.exit(0)

        # Load settings from user settings file, into shared env dict.
        state.env.update(load_settings(state.env.rcfile))

        # Find local fabfile path or abort
        fabfile = find_fabfile()
        if not fabfile:
            abort("Couldn't find any fabfiles!")

        # Store absolute path to fabfile in case anyone needs it
        state.env.real_fabfile = fabfile

        # Load fabfile (which calls its module-level code, including
        # tweaks to env values) and put its commands in the shared commands
        # dict
        commands.update(load_fabfile(fabfile))

        # Abort if no commands found
        if not commands:
            abort("Fabfile didn't contain any commands!")

        # Now that we're settled on a fabfile, inform user.
        if state.output.debug:
            print("Using fabfile '%s'" % fabfile)

        # Handle list-commands option (now that commands are loaded)
        if options.list_commands:
            list_commands()

        # Handle show (command-specific help) option
        if options.display:
            display_command(options.display)

        # If user didn't specify any commands to run, show help
        if not arguments:
            parser.print_help()
            sys.exit(0) # Or should it exit with error (1)?

        # Parse arguments into commands to run (plus args/kwargs/hosts)
        commands_to_run = parse_arguments(arguments)

        # Figure out if any specified names are invalid
        unknown_commands = []
        for tup in commands_to_run:
            if tup[0] not in commands:
                unknown_commands.append(tup[0])

        # Abort if any unknown commands were specified
        if unknown_commands:
            abort("Command(s) not found:\n%s" \
                % indent(unknown_commands))

        # At this point all commands must exist, so execute them in order.
        for name, args, kwargs, cli_hosts, cli_roles in commands_to_run:
            # Get callable by itself
            command = commands[name]
            # Set current command name (used for some error messages)
            state.env.command = name
            # Set host list (also copy to env)
            state.env.all_hosts = hosts = get_hosts(
                command, cli_hosts, cli_roles)
            # If hosts found, execute the function on each host in turn
            for host in hosts:
                username, hostname, port = normalize(host)
                state.env.host_string = host
                state.env.host = hostname
                # Preserve user
                prev_user = state.env.user
                state.env.user = username
                state.env.port = port
                # Actually run command
                commands[name](*args, **kwargs)
                # Put old user back
                state.env.user = prev_user
            # If no hosts found, assume local-only and run once
            if not hosts:
                commands[name](*args, **kwargs)
        # If we got here, no errors occurred, so print a final note.
        if state.output.status:
            print("\nDone.")
    except SystemExit:
        # a number of internal functions might raise this one.
        raise
    except KeyboardInterrupt:
        if state.output.status:
            print >>sys.stderr, "\nStopped."
        sys.exit(1)
    except:
        sys.excepthook(*sys.exc_info())
        # we might leave stale threads if we don't explicitly exit()
        sys.exit(1)
    finally:
        # Explicitly disconnect from all servers
        for key in connections.keys():
            if state.output.status:
                print "Disconnecting from %s..." % denormalize(key),
            connections[key].close()
            if state.output.status:
                print "done."
    sys.exit(0)
Example #3
0
def main():
    """
    Main command-line execution loop.
    """
    try:
        try:
            # Parse command line options
            parser, options, arguments = parse_options()

            # Update env with any overridden option values
            # NOTE: This needs to remain the first thing that occurs
            # post-parsing, since so many things hinge on the values in env.
            for option in env_options:
                state.env[option.dest] = getattr(options, option.dest)

            # Handle version number option
            if options.show_version:
                print "Fabric " + state.env.version
                sys.exit(0)

            # Load settings from user settings file, into shared env dict.
            state.env.update(load_settings(rc_path()))

            # Find local fabfile path or abort
            fabfile = find_fabfile()
            if not fabfile:
                abort("Couldn't find any fabfiles!")

            # Store absolute path to fabfile in case anyone needs it
            state.env.real_fabfile = fabfile

            # Load fabfile (which calls its module-level code, including
            # tweaks to env values) and put its commands in the shared commands
            # dict
            commands.update(load_fabfile(fabfile))

            # Abort if no commands found
            # TODO: continue searching for fabfiles if one we selected doesn't
            # contain any callables? Bit of an edge case, but still...
            if not commands:
                abort("Fabfile didn't contain any commands!")

            # Handle list-commands option (now that commands are loaded)
            if options.list_commands:
                list_commands()

            # Handle show (command-specific help) option
            if options.display:
                show_command(options.display)

            # If user didn't specify any commands to run, show help
            if not arguments:
                parser.print_help()
                sys.exit(0) # Or should it exit with error (1)?

            # Parse arguments into commands to run (plus args/kwargs/hosts)
            commands_to_run = parse_arguments(arguments)
            
            # Figure out if any specified names are invalid
            unknown_commands = []
            for tup in commands_to_run:
                if tup[0] not in commands:
                    unknown_commands.append(tup[0])

            # Abort if any unknown commands were specified
            if unknown_commands:
                abort("Command(s) not found:\n%s" \
                    % indent(unknown_commands))

            # At this point all commands must exist, so execute them in order.
            for name, args, kwargs, cli_hosts in commands_to_run:
                # Get callable by itself
                command = commands[name]
                # Set current command name (used for some error messages)
                state.env.command = name
                # Set host list
                hosts = get_hosts(cli_hosts, command)
                # If hosts found, execute the function on each host in turn
                for host in hosts:
                    username, hostname, port = normalize(host)
                    state.env.host_string = host
                    state.env.host = hostname
                    # Preserve user
                    prev_user = state.env.user
                    state.env.user = username
                    state.env.port = port
                    # Actually run command
                    commands[name](*args, **kwargs)
                    # Put old user back
                    state.env.user = prev_user
                # If no hosts found, assume local-only and run once
                if not hosts:
                    commands[name](*args, **kwargs)
            # If we got here, no errors occurred, so print a final note.
            print("\nDone.")
        finally:
            # TODO: explicit disconnect?
            pass
    except SystemExit:
        # a number of internal functions might raise this one.
        raise
    except KeyboardInterrupt:
        print >>sys.stderr, "\nStopped."
        sys.exit(1)
    except:
        sys.excepthook(*sys.exc_info())
        # we might leave stale threads if we don't explicitly exit()
        sys.exit(1)
    sys.exit(0)