コード例 #1
0
def main():

    simonObject = Simon()

    # constants
    QUBIT_RANGE = 7
    ITERATIONS = 2

    worked = np.zeros(shape=(QUBIT_RANGE - 1, ITERATIONS))
    timing = np.zeros(shape=(QUBIT_RANGE - 1, ITERATIONS))

    print('Testing out Simon\'s alorithm...')

    seed(3245234)
    for n in range(2, QUBIT_RANGE + 1):
        print(f'Trying {2*n}-qubit machine...')
        for j in range(ITERATIONS):
            print(f'Iteration {j+1}...')

            # randomly decide f
            # for ease of construction, the output for each x,y such that x^y=s is min(x,y)
            s = randint(0, 2**n - 1)
            print("S: " + "{0:b}".format(s))

            def f(x):
                return x if (x ^ s > x) else x ^ s

            start = time.perf_counter()
            result = simonObject.run(f, n)
            end = time.perf_counter()

            print("Result = " + str(result) +
                  (": Worked" if result == s else ": Failed"))
            print("Timing: " + str(end - start))
            timing[n - 2][j] = (end - start)

    qubit_values = []
    for n in range(2, QUBIT_RANGE + 1):
        qubit_values += [2 * n]

    average_runtimes = []
    for i in range(QUBIT_RANGE - 1):
        average_runtimes += [np.mean(timing[i])]

    plt.plot(qubit_values, average_runtimes)
    plt.ylabel('Runtime (s)')
    plt.xlabel('Number of Qubits')
    plt.xticks(qubit_values)
    plt.title('Quantum Simulation Scaling for Simon\'s Algorithm')
    plt.show()
コード例 #2
0
ファイル: level1.py プロジェクト: tirhelen/ot-harjoitustyo
    def __init__(self, filename):
        """constructor for the map

        Args:
            filename (string): name of the csv file that has information about the map tiles
        """
        self.filename = filename
        self.tile_size = 50
        self.start_x, self.start_y = 0, 0
        self.boa_group = pygame.sprite.Group()
        self.simon = Simon()
        self.door_group = pygame.sprite.Group()
コード例 #3
0
ファイル: mitterent_main.py プロジェクト: 2016180022/20022DGP
def enter():
    gfw.world.init([
        'bigground', 'background', 'enemy', 'abigail', 'simon', 'bullet',
        'enemy_bullet', 'frontground', 'ui', 'platform'
    ])
    map_loader.load()

    global simon
    simon = Simon()
    gfw.world.add(gfw.layer.simon, simon)
    global bigground
    bigground = BiggroundScroll('bigground_demo.png')
    gfw.world.add(gfw.layer.bigground, bigground)
    global background
    background = BackgroundScroll('background.png')
    gfw.world.add(gfw.layer.background, background)
    global frontground
    frontground = FrontgroundScroll('frontground.png')
    gfw.world.add(gfw.layer.frontground, frontground)
    background.target = simon
    frontground.target = simon
    bigground.target = simon

    global music_bg, wav_simon_dead, wav_enemy_dead1, wav_enemy_dead2

    music_bg = load_music('res/Midnight Wandering.mp3')
    wav_simon_dead = load_wav('res/P_EriDeath_old.wav')
    wav_enemy_dead1 = load_wav('res/P_ClarkDeath.wav')
    wav_enemy_dead2 = load_wav('res/P_MarcoDeath_old.wav')

    global enemy_die
    enemy_die = random.choice([wav_enemy_dead1, wav_enemy_dead2])

    music_bg.set_volume(30)
    wav_simon_dead.set_volume(10)
    enemy_die.set_volume(10)

    global game_over_image
    game_over_image = gfw.image.load('res/gameover.png')

    global state
    state = STATE_IN_GAME
    start_game()
    print('init')
コード例 #4
0
def enter():
    gfw.world.init(['bigground','background', 'enemy', 'abigail', 'simon', 'bullet', 'enemy_bullet', 'frontground', 'ui', 'platform'])
    map_loader.load()
    #gfw.world.init(['background', 'enemy', 'simon', 'bullet', 'enemy_bullet', 'frontground'])

    global simon
    simon = Simon()
    gfw.world.add(gfw.layer.simon, simon)
    global bigground
    bigground = BiggroundScroll('bigground_demo.png')
    gfw.world.add(gfw.layer.bigground, bigground)
    global background
    background = BackgroundScroll('background.png')
    gfw.world.add(gfw.layer.background, background)    
    global frontground
    frontground = FrontgroundScroll('frontground.png')
    gfw.world.add(gfw.layer.frontground, frontground)
    background.target = simon
    frontground.target = simon
    bigground.target = simon
    #for i in range (3):
    global enemy
    enemy = Enemy()
    gfw.world.add(gfw.layer.enemy, enemy)
コード例 #5
0
ファイル: main.py プロジェクト: ZachElkins/Simon
def main():
    root = tk.Tk()

    simon = Simon(root)

    root.mainloop()
コード例 #6
0
# Implemented by Xiang Zejun, State Key Laboratory of Information Security,
# Institute Of Information Engineering, CAS

from simon import Simon

if __name__ == "__main__":

    WORD_LENGTH = int(
        raw_input(
            "Input the word length of the target cipher (16 for SIMON32): "))
    while WORD_LENGTH not in [16, 24, 32, 48, 64]:
        print "Invalid word length!"
        WORD_LENGTH = int(raw_input("Input the word length again: "))

    ROUND = int(raw_input("Input the target round number: "))
    while not (ROUND > 0):
        print "Input a round number greater than 0."
        ROUND = int(raw_input("Input the target round number again: "))

    ACTIVEBITS = int(raw_input("Input the number of acitvebits: "))
    while not (ACTIVEBITS < 64 and ACTIVEBITS > 0):
        print "Input a number of activebits with range (0, 64):"
        ACTIVEBITS = int(raw_input("Input the number of acitvebits again: "))

    simon = Simon(ROUND, ACTIVEBITS, WORD_LENGTH)

    simon.MakeModel()

    simon.SolveModel()
コード例 #7
0
def game():
    return Simon()
コード例 #8
0
        await ctx.send("", embed=gen_embed("Current Simon", ", ".join(map(str, simon_role.members))))


@bot.command()
async def remaining(ctx):
    """
    Get the remaining Simon Says players
    """
    player_role = get(ctx.guild.roles, name=get_role("Player"))

    title = f"{len(player_role.members)} Player(s) Remaining"
    description = ', '.join(map(str, player_role.members))

    await ctx.send("", embed=gen_embed(title, description))


@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")


@bot.event
async def on_raw_reaction_remove(payload):
    channel = bot.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    await get(channel.guild.channels, name=config["Channels"]["ReactionLog"]).send(f"<@{payload.user_id}> removed the reaction {payload.emoji} on this message: <{message.jump_url}>.")

bot.add_cog(Simon(bot))
bot.run(getenv("SIMON_BOT_KEY"))