作为学习、练习与尝试,这里创建一个时尚青蛙的小游戏。
打开网页版:https://arcade.makecode.com/ ,设置项目名称:时尚青蛙
MicroPython实验代码
@namespace
class SpriteKind:
Frog = SpriteKind.create()
Menu = SpriteKind.create()
def Think(R: number, G: number, B: number, Net: List[List[List[number]]]):
global OutputArray, OutputArray2
OutputArray = [0, 0, 0, 0]
OutputArray2 = [0, 0, 0, 0]
for index in range(4):
OutputArray[index] = R * Net[0][index][0] + G * Net[0][index][1] + (B * Net[0][index][2] + Net[0][index][3])
for index2 in range(4):
OutputArray2[index2] = OutputArray[0] * Net[1][index2][0] + OutputArray[1] * Net[1][index2][1] + (OutputArray[2] * Net[1][index2][2] + (OutputArray[3] * Net[1][index2][3] + Net[1][index2][4]))
print(OutputArray2[0] * Net[2][0][0] + OutputArray2[1] * Net[2][0][1] + (OutputArray2[2] * Net[2][0][2] + (OutputArray2[3] * Net[2][0][3] + Net[2][0][4])))
if OutputArray2[0] * Net[2][0][0] + OutputArray2[1] * Net[2][0][1] + (OutputArray2[2] * Net[2][0][2] + (OutputArray2[3] * Net[2][0][3] + Net[2][0][4])) >= 2:
return "...Ribbit?"
elif OutputArray2[0] * Net[2][0][0] + OutputArray2[1] * Net[2][0][1] + (OutputArray2[2] * Net[2][0][2] + (OutputArray2[3] * Net[2][0][3] + Net[2][0][4])) >= 1:
return "LOVE"
elif OutputArray2[0] * Net[2][0][0] + OutputArray2[1] * Net[2][0][1] + (OutputArray2[2] * Net[2][0][2] + (OutputArray2[3] * Net[2][0][3] + Net[2][0][4])) >= 0.75:
return "Like"
elif OutputArray2[0] * Net[2][0][0] + OutputArray2[1] * Net[2][0][1] + (OutputArray2[2] * Net[2][0][2] + (OutputArray2[3] * Net[2][0][3] + Net[2][0][4])) >= 0.5:
return "OK"
elif OutputArray2[0] * Net[2][0][0] + OutputArray2[1] * Net[2][0][1] + (OutputArray2[2] * Net[2][0][2] + (OutputArray2[3] * Net[2][0][3] + Net[2][0][4])) >= 0.25:
return "Dislike"
elif OutputArray2[0] * Net[2][0][0] + OutputArray2[1] * Net[2][0][1] + (OutputArray2[2] * Net[2][0][2] + (OutputArray2[3] * Net[2][0][3] + Net[2][0][4])) >= -1:
return "HATE"
else:
return "...Ribbit?"
def on_a_pressed():
global Stage, Count, Net_3
music.play(music.melody_playable(music.zapped),
music.PlaybackMode.IN_BACKGROUND)
if mySprite.tile_kind_at(TileDirection.CENTER, assets.tile("""
Seat
""")) and Stage > 0:
if Stage < 3:
if Frog_1.image.equals(assets.image("""
Frog_1
""")) and mySprite.overlaps_with(Frog_1):
Frog_1.set_image(assets.image("""
Frog_1_Love
"""))
Frog_1.start_effect(effects.hearts, 500)
LoveArray.append(Net_1)
Stage += 1
if Frog_2.image.equals(assets.image("""
Frog_2
""")) and mySprite.overlaps_with(Frog_2):
Frog_2.set_image(assets.image("""
Frog_2_Love
"""))
Frog_2.start_effect(effects.hearts, 500)
LoveArray.append(Net_2)
Stage += 1
if Frog_3.image.equals(assets.image("""
Frog_3
""")) and mySprite.overlaps_with(Frog_3):
Frog_3.set_image(assets.image("""
Frog_3_Love
"""))
Frog_3.start_effect(effects.hearts, 500)
LoveArray.append(Net_3)
Stage += 1
if Frog_4.image.equals(assets.image("""
Frog_4
""")) and mySprite.overlaps_with(Frog_4):
Frog_4.set_image(assets.image("""
Frog_4_Love
"""))
Frog_4.start_effect(effects.hearts, 500)
LoveArray.append(Net_4)
Stage += 1
if Frog_5.image.equals(assets.image("""
Frog_5
""")) and mySprite.overlaps_with(Frog_5):
Frog_5.set_image(assets.image("""
Frog_5_Love
"""))
Frog_5.start_effect(effects.hearts, 500)
LoveArray.append(Net_5)
Stage += 1
if Stage == 3:
Stage = 0
Count += -1
animation.stop_animation(animation.AnimationTypes.ALL, mySprite)
mySprite.set_image(assets.image("""
Cursor
"""))
pause(500)
Breed(LoveArray[0], LoveArray[1])
music.play(music.melody_playable(music.power_up),
music.PlaybackMode.IN_BACKGROUND)
Round()
if Count > 0:
Stage = 1
else:
game.show_long_text("It's time to pick your final AI Fashion Frog!",
DialogLayout.BOTTOM)
Stage = -1
animation.run_image_animation(mySprite,
assets.animation("""
Cursor_Select
"""),
700,
True)
elif mySprite.tile_kind_at(TileDirection.CENTER, assets.tile("""
Seat
""")) and Stage == -1:
if Frog_1.image.equals(assets.image("""
Frog_1
""")) and mySprite.overlaps_with(Frog_1):
Frog_1.set_image(assets.image("""
Frog_1_Love
"""))
Frog_1.start_effect(effects.hearts, 500)
Stage = -1.1
if Frog_2.image.equals(assets.image("""
Frog_2
""")) and mySprite.overlaps_with(Frog_2):
Frog_2.set_image(assets.image("""
Frog_2_Love
"""))
Frog_2.start_effect(effects.hearts, 500)
Stage = -1.2
if Frog_3.image.equals(assets.image("""
Frog_3
""")) and mySprite.overlaps_with(Frog_3):
Frog_3.set_image(assets.image("""
Frog_3_Love
"""))
Frog_3.start_effect(effects.hearts, 500)
Stage = -1.3
if Frog_4.image.equals(assets.image("""
Frog_4
""")) and mySprite.overlaps_with(Frog_4):
Frog_4.set_image(assets.image("""
Frog_4_Love
"""))
Frog_4.start_effect(effects.hearts, 500)
Stage = -1.4
if Frog_5.image.equals(assets.image("""
Frog_5
""")) and mySprite.overlaps_with(Frog_5):
Frog_5.set_image(assets.image("""
Frog_5_Love
"""))
Frog_5.start_effect(effects.hearts, 500)
Stage = -1.5
if Stage < -1:
if Stage == -1.1:
Net_3 = Net_1
elif Stage == -1.2:
Net_3 = Net_2
elif Stage == -1.3:
Net_3 = Net_3
elif Stage == -1.4:
Net_3 = Net_4
elif Stage == -1.5:
Net_3 = Net_5
sprites.destroy(Frog_1)
sprites.destroy(Frog_2)
sprites.destroy(Frog_4)
sprites.destroy(Frog_5)
effects.hearts.start_screen_effect(1000)
def on_after():
game.show_long_text("Congratulations finding your AI Fashion Frog!",
DialogLayout.BOTTOM)
def on_after2():
game.show_long_text("Here is what your frog thinks of your fashionable color tastes!",
DialogLayout.BOTTOM)
def on_after3():
game.show_long_text("They think you " + str(Think(1, 1, 1, Net_3)) + " White!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(0, 0, 0, Net_3)) + " Black!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(1, 0, 0, Net_3)) + " Red!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(1, 0.5, 0, Net_3)) + " Orange!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(1, 1, 0, Net_3)) + " Yellow!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(0, 1, 0, Net_3)) + " Green!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(0, 1, 0, Net_3)) + " Green!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(0, 1, 1, Net_3)) + " Cyan!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(0, 0, 1, Net_3)) + " Blue!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(0.5, 0, 1, Net_3)) + " Purple!",
DialogLayout.BOTTOM)
game.show_long_text("They think you " + str(Think(1, 0, 1, Net_3)) + " Magenta!",
DialogLayout.BOTTOM)
for index3 in range(3):
for value in Net_3[index3]:
print(value[0])
print(value[1])
print(value[2])
def on_after4():
game.show_long_text("Thanks so much for playing around with my first neural network game. If you want more games like this, search for my games in the makecode arcade forum!",
DialogLayout.BOTTOM)
game.set_game_over_message(True, "- Dragondoodle / Randomuser")
game.game_over(True)
timer.after(500, on_after4)
timer.after(500, on_after3)
timer.after(500, on_after2)
timer.after(1000, on_after)
controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)
def Round():
global Stage, LoveArray
Stage = 0
pause(2000)
music.play(music.melody_playable(music.magic_wand),
music.PlaybackMode.IN_BACKGROUND)
Frog_1.say_text(Think(RGB[0] / 255, RGB[1] / 255, RGB[2] / 255, Net_1),
5000,
False)
Frog_2.say_text(Think(RGB[0] / 255, RGB[1] / 255, RGB[2] / 255, Net_2),
5000,
False)
Frog_3.say_text(Think(RGB[0] / 255, RGB[1] / 255, RGB[2] / 255, Net_3),
5000,
False)
Frog_4.say_text(Think(RGB[0] / 255, RGB[1] / 255, RGB[2] / 255, Net_4),
5000,
False)
Frog_5.say_text(Think(RGB[0] / 255, RGB[1] / 255, RGB[2] / 255, Net_5),
5000,
False)
Frog_1.set_image(assets.image("""
Frog_1_Speak
"""))
Frog_2.set_image(assets.image("""
Frog_2_Speak
"""))
Frog_3.set_image(assets.image("""
Frog_3_Speak
"""))
Frog_4.set_image(assets.image("""
Frog_4_Speak
"""))
Frog_5.set_image(assets.image("""
Frog_5_Speak
"""))
def on_after5():
Frog_1.set_image(assets.image("""
Frog_1
"""))
Frog_2.set_image(assets.image("""
Frog_2
"""))
Frog_3.set_image(assets.image("""
Frog_3
"""))
Frog_4.set_image(assets.image("""
Frog_4
"""))
Frog_5.set_image(assets.image("""
Frog_5
"""))
timer.after(1000, on_after5)
pause(4000)
game.show_long_text("Pick the right frogs!", DialogLayout.BOTTOM)
animation.run_image_animation(mySprite,
assets.animation("""
Cursor_Select
"""),
700,
True)
LoveArray = []
def Breed(One: List[List[List[number]]], Two: List[List[List[number]]]):
global Net_1, Net_2, Net_3, Net_4, Net_5
Net_1 = [[[randint(100 * One[0][0][0], 100 * Two[0][0][0]) / 100,
randint(100 * One[0][0][1], 100 * Two[0][0][1]) / 100,
randint(100 * One[0][0][2], 100 * Two[0][0][2]) / 100,
randint(100 * One[0][0][3], 100 * Two[0][0][3]) / 100],
[randint(100 * One[0][1][0], 100 * Two[0][1][0]) / 100,
randint(100 * One[0][1][1], 100 * Two[0][1][1]) / 100,
randint(100 * One[0][1][2], 100 * Two[0][1][2]) / 100,
randint(100 * One[0][1][3], 100 * Two[0][1][3]) / 100],
[randint(100 * One[0][2][0], 100 * Two[0][2][0]) / 100,
randint(100 * One[0][2][1], 100 * Two[0][2][1]) / 100,
randint(100 * One[0][2][2], 100 * Two[0][2][2]) / 100,
randint(100 * One[0][2][3], 100 * Two[0][2][3]) / 100],
[randint(100 * One[0][3][0], 100 * Two[0][3][0]) / 100,
randint(100 * One[0][3][1], 100 * Two[0][3][1]) / 100,
randint(100 * One[0][3][2], 100 * Two[0][3][2]) / 100,
randint(100 * One[0][3][3], 100 * Two[0][3][3]) / 100]],
[[randint(100 * One[1][0][0], 100 * Two[1][0][0]) / 100,
randint(100 * One[1][0][1], 100 * Two[1][0][1]) / 100,
randint(100 * One[1][0][2], 100 * Two[1][0][2]) / 100,
randint(100 * One[1][0][3], 100 * Two[1][0][3]) / 100,
randint(100 * One[1][0][4], 100 * Two[1][0][4]) / 100],
[randint(100 * One[1][1][0], 100 * Two[1][1][0]) / 100,
randint(100 * One[1][1][1], 100 * Two[1][1][1]) / 100,
randint(100 * One[1][1][2], 100 * Two[1][1][2]) / 100,
randint(100 * One[1][1][3], 100 * Two[1][1][3]) / 100,
randint(100 * One[1][1][4], 100 * Two[1][1][4]) / 100],
[randint(100 * One[1][2][0], 100 * Two[1][2][0]) / 100,
randint(100 * One[1][2][1], 100 * Two[1][2][1]) / 100,
randint(100 * One[1][2][2], 100 * Two[1][2][2]) / 100,
randint(100 * One[1][2][3], 100 * Two[1][2][3]) / 100,
randint(100 * One[1][2][4], 100 * Two[1][2][4]) / 100],
[randint(100 * One[1][3][0], 100 * Two[1][3][0]) / 100,
randint(100 * One[1][3][1], 100 * Two[1][3][1]) / 100,
randint(100 * One[1][3][2], 100 * Two[1][3][2]) / 100,
randint(100 * One[1][3][3], 100 * Two[1][3][3]) / 100,
randint(100 * One[1][3][4], 100 * Two[1][3][4]) / 100]],
[[randint(100 * One[2][0][0], 100 * Two[2][0][0]) / 100,
randint(100 * One[2][0][1], 100 * Two[2][0][1]) / 100,
randint(100 * One[2][0][2], 100 * Two[2][0][2]) / 100,
randint(100 * One[2][0][3], 100 * Two[2][0][3]) / 100,
randint(100 * One[2][0][4], 100 * Two[2][0][4]) / 100]]]
Net_2 = [[[randint(100 * One[0][0][0], 100 * Two[0][0][0]) / 100,
randint(100 * One[0][0][1], 100 * Two[0][0][1]) / 100,
randint(100 * One[0][0][2], 100 * Two[0][0][2]) / 100,
randint(100 * One[0][0][3], 100 * Two[0][0][3]) / 100],
[randint(100 * One[0][1][0], 100 * Two[0][1][0]) / 100,
randint(100 * One[0][1][1], 100 * Two[0][1][1]) / 100,
randint(100 * One[0][1][2], 100 * Two[0][1][2]) / 100,
randint(100 * One[0][1][3], 100 * Two[0][1][3]) / 100],
[randint(100 * One[0][2][0], 100 * Two[0][2][0]) / 100,
randint(100 * One[0][2][1], 100 * Two[0][2][1]) / 100,
randint(100 * One[0][2][2], 100 * Two[0][2][2]) / 100,
randint(100 * One[0][2][3], 100 * Two[0][2][3]) / 100],
[randint(100 * One[0][3][0], 100 * Two[0][3][0]) / 100,
randint(100 * One[0][3][1], 100 * Two[0][3][1]) / 100,
randint(100 * One[0][3][2], 100 * Two[0][3][2]) / 100,
randint(100 * One[0][3][3], 100 * Two[0][3][3]) / 100]],
[[randint(100 * One[1][0][0], 100 * Two[1][0][0]) / 100,
randint(100 * One[1][0][1], 100 * Two[1][0][1]) / 100,
randint(100 * One[1][0][2], 100 * Two[1][0][2]) / 100,
randint(100 * One[1][0][3], 100 * Two[1][0][3]) / 100,
randint(100 * One[1][0][4], 100 * Two[1][0][4]) / 100],
[randint(100 * One[1][1][0], 100 * Two[1][1][0]) / 100,
randint(100 * One[1][1][1], 100 * Two[1][1][1]) / 100,
randint(100 * One[1][1][2], 100 * Two[1][1][2]) / 100,
randint(100 * One[1][1][3], 100 * Two[1][1][3]) / 100,
randint(100 * One[1][1][4], 100 * Two[1][1][4]) / 100],
[randint(100 * One[1][2][0], 100 * Two[1][2][0]) / 100,
randint(100 * One[1][2][1], 100 * Two[1][2][1]) / 100,
randint(100 * One[1][2][2], 100 * Two[1][2][2]) / 100,
randint(100 * One[1][2][3], 100 * Two[1][2][3]) / 100,
randint(100 * One[1][2][4], 100 * Two[1][2][4]) / 100],
[randint(100 * One[1][3][0], 100 * Two[1][3][0]) / 100,
randint(100 * One[1][3][1], 100 * Two[1][3][1]) / 100,
randint(100 * One[1][3][2], 100 * Two[1][3][2]) / 100,
randint(100 * One[1][3][3], 100 * Two[1][3][3]) / 100,
randint(100 * One[1][3][4], 100 * Two[1][3][4]) / 100]],
[[randint(100 * One[2][0][0], 100 * Two[2][0][0]) / 100,
randint(100 * One[2][0][1], 100 * Two[2][0][1]) / 100,
randint(100 * One[2][0][2], 100 * Two[2][0][2]) / 100,
randint(100 * One[2][0][3], 100 * Two[2][0][3]) / 100,
randint(100 * One[2][0][4], 100 * Two[2][0][4]) / 100]]]
Net_3 = [[[randint(100 * One[0][0][0], 100 * Two[0][0][0]) / 100,
randint(100 * One[0][0][1], 100 * Two[0][0][1]) / 100,
randint(100 * One[0][0][2], 100 * Two[0][0][2]) / 100,
randint(100 * One[0][0][3], 100 * Two[0][0][3]) / 100],
[randint(100 * One[0][1][0], 100 * Two[0][1][0]) / 100,
randint(100 * One[0][1][1], 100 * Two[0][1][1]) / 100,
randint(100 * One[0][1][2], 100 * Two[0][1][2]) / 100,
randint(100 * One[0][1][3], 100 * Two[0][1][3]) / 100],
[randint(100 * One[0][2][0], 100 * Two[0][2][0]) / 100,
randint(100 * One[0][2][1], 100 * Two[0][2][1]) / 100,
randint(100 * One[0][2][2], 100 * Two[0][2][2]) / 100,
randint(100 * One[0][2][3], 100 * Two[0][2][3]) / 100],
[randint(100 * One[0][3][0], 100 * Two[0][3][0]) / 100,
randint(100 * One[0][3][1], 100 * Two[0][3][1]) / 100,
randint(100 * One[0][3][2], 100 * Two[0][3][2]) / 100,
randint(100 * One[0][3][3], 100 * Two[0][3][3]) / 100]],
[[randint(100 * One[1][0][0], 100 * Two[1][0][0]) / 100,
randint(100 * One[1][0][1], 100 * Two[1][0][1]) / 100,
randint(100 * One[1][0][2], 100 * Two[1][0][2]) / 100,
randint(100 * One[1][0][3], 100 * Two[1][0][3]) / 100,
randint(100 * One[1][0][4], 100 * Two[1][0][4]) / 100],
[randint(100 * One[1][1][0], 100 * Two[1][1][0]) / 100,
randint(100 * One[1][1][1], 100 * Two[1][1][1]) / 100,
randint(100 * One[1][1][2], 100 * Two[1][1][2]) / 100,
randint(100 * One[1][1][3], 100 * Two[1][1][3]) / 100,
randint(100 * One[1][1][4], 100 * Two[1][1][4]) / 100],
[randint(100 * One[1][2][0], 100 * Two[1][2][0]) / 100,
randint(100 * One[1][2][1], 100 * Two[1][2][1]) / 100,
randint(100 * One[1][2][2], 100 * Two[1][2][2]) / 100,
randint(100 * One[1][2][3], 100 * Two[1][2][3]) / 100,
randint(100 * One[1][2][4], 100 * Two[1][2][4]) / 100],
[randint(100 * One[1][3][0], 100 * Two[1][3][0]) / 100,
randint(100 * One[1][3][1], 100 * Two[1][3][1]) / 100,
randint(100 * One[1][3][2], 100 * Two[1][3][2]) / 100,
randint(100 * One[1][3][3], 100 * Two[1][3][3]) / 100,
randint(100 * One[1][3][4], 100 * Two[1][3][4]) / 100]],
[[randint(100 * One[2][0][0], 100 * Two[2][0][0]) / 100,
randint(100 * One[2][0][1], 100 * Two[2][0][1]) / 100,
randint(100 * One[2][0][2], 100 * Two[2][0][2]) / 100,
randint(100 * One[2][0][3], 100 * Two[2][0][3]) / 100,
randint(100 * One[2][0][4], 100 * Two[2][0][4]) / 100]]]
Net_4 = [[[randint(100 * One[0][0][0], 100 * Two[0][0][0]) / 100,
randint(100 * One[0][0][1], 100 * Two[0][0][1]) / 100,
randint(100 * One[0][0][2], 100 * Two[0][0][2]) / 100,
randint(100 * One[0][0][3], 100 * Two[0][0][3]) / 100],
[randint(100 * One[0][1][0], 100 * Two[0][1][0]) / 100,
randint(100 * One[0][1][1], 100 * Two[0][1][1]) / 100,
randint(100 * One[0][1][2], 100 * Two[0][1][2]) / 100,
randint(100 * One[0][1][3], 100 * Two[0][1][3]) / 100],
[randint(100 * One[0][2][0], 100 * Two[0][2][0]) / 100,
randint(100 * One[0][2][1], 100 * Two[0][2][1]) / 100,
randint(100 * One[0][2][2], 100 * Two[0][2][2]) / 100,
randint(100 * One[0][2][3], 100 * Two[0][2][3]) / 100],
[randint(100 * One[0][3][0], 100 * Two[0][3][0]) / 100,
randint(100 * One[0][3][1], 100 * Two[0][3][1]) / 100,
randint(100 * One[0][3][2], 100 * Two[0][3][2]) / 100,
randint(100 * One[0][3][3], 100 * Two[0][3][3]) / 100]],
[[randint(100 * One[1][0][0], 100 * Two[1][0][0]) / 100,
randint(100 * One[1][0][1], 100 * Two[1][0][1]) / 100,
randint(100 * One[1][0][2], 100 * Two[1][0][2]) / 100,
randint(100 * One[1][0][3], 100 * Two[1][0][3]) / 100,
randint(100 * One[1][0][4], 100 * Two[1][0][4]) / 100],
[randint(100 * One[1][1][0], 100 * Two[1][1][0]) / 100,
randint(100 * One[1][1][1], 100 * Two[1][1][1]) / 100,
randint(100 * One[1][1][2], 100 * Two[1][1][2]) / 100,
randint(100 * One[1][1][3], 100 * Two[1][1][3]) / 100,
randint(100 * One[1][1][4], 100 * Two[1][1][4]) / 100],
[randint(100 * One[1][2][0], 100 * Two[1][2][0]) / 100,
randint(100 * One[1][2][1], 100 * Two[1][2][1]) / 100,
randint(100 * One[1][2][2], 100 * Two[1][2][2]) / 100,
randint(100 * One[1][2][3], 100 * Two[1][2][3]) / 100,
randint(100 * One[1][2][4], 100 * Two[1][2][4]) / 100],
[randint(100 * One[1][3][0], 100 * Two[1][3][0]) / 100,
randint(100 * One[1][3][1], 100 * Two[1][3][1]) / 100,
randint(100 * One[1][3][2], 100 * Two[1][3][2]) / 100,
randint(100 * One[1][3][3], 100 * Two[1][3][3]) / 100,
randint(100 * One[1][3][4], 100 * Two[1][3][4]) / 100]],
[[randint(100 * One[2][0][0], 100 * Two[2][0][0]) / 100,
randint(100 * One[2][0][1], 100 * Two[2][0][1]) / 100,
randint(100 * One[2][0][2], 100 * Two[2][0][2]) / 100,
randint(100 * One[2][0][3], 100 * Two[2][0][3]) / 100,
randint(100 * One[2][0][4], 100 * Two[2][0][4]) / 100]]]
Net_5 = [[[randint(100 * One[0][0][0], 100 * Two[0][0][0]) / 100,
randint(100 * One[0][0][1], 100 * Two[0][0][1]) / 100,
randint(100 * One[0][0][2], 100 * Two[0][0][2]) / 100,
randint(100 * One[0][0][3], 100 * Two[0][0][3]) / 100],
[randint(100 * One[0][1][0], 100 * Two[0][1][0]) / 100,
randint(100 * One[0][1][1], 100 * Two[0][1][1]) / 100,
randint(100 * One[0][1][2], 100 * Two[0][1][2]) / 100,
randint(100 * One[0][1][3], 100 * Two[0][1][3]) / 100],
[randint(100 * One[0][2][0], 100 * Two[0][2][0]) / 100,
randint(100 * One[0][2][1], 100 * Two[0][2][1]) / 100,
randint(100 * One[0][2][2], 100 * Two[0][2][2]) / 100,
randint(100 * One[0][2][3], 100 * Two[0][2][3]) / 100],
[randint(100 * One[0][3][0], 100 * Two[0][3][0]) / 100,
randint(100 * One[0][3][1], 100 * Two[0][3][1]) / 100,
randint(100 * One[0][3][2], 100 * Two[0][3][2]) / 100,
randint(100 * One[0][3][3], 100 * Two[0][3][3]) / 100]],
[[randint(100 * One[1][0][0], 100 * Two[1][0][0]) / 100,
randint(100 * One[1][0][1], 100 * Two[1][0][1]) / 100,
randint(100 * One[1][0][2], 100 * Two[1][0][2]) / 100,
randint(100 * One[1][0][3], 100 * Two[1][0][3]) / 100,
randint(100 * One[1][0][4], 100 * Two[1][0][4]) / 100],
[randint(100 * One[1][1][0], 100 * Two[1][1][0]) / 100,
randint(100 * One[1][1][1], 100 * Two[1][1][1]) / 100,
randint(100 * One[1][1][2], 100 * Two[1][1][2]) / 100,
randint(100 * One[1][1][3], 100 * Two[1][1][3]) / 100,
randint(100 * One[1][1][4], 100 * Two[1][1][4]) / 100],
[randint(100 * One[1][2][0], 100 * Two[1][2][0]) / 100,
randint(100 * One[1][2][1], 100 * Two[1][2][1]) / 100,
randint(100 * One[1][2][2], 100 * Two[1][2][2]) / 100,
randint(100 * One[1][2][3], 100 * Two[1][2][3]) / 100,
randint(100 * One[1][2][4], 100 * Two[1][2][4]) / 100],
[randint(100 * One[1][3][0], 100 * Two[1][3][0]) / 100,
randint(100 * One[1][3][1], 100 * Two[1][3][1]) / 100,
randint(100 * One[1][3][2], 100 * Two[1][3][2]) / 100,
randint(100 * One[1][3][3], 100 * Two[1][3][3]) / 100,
randint(100 * One[1][3][4], 100 * Two[1][3][4]) / 100]],
[[randint(100 * One[2][0][0], 100 * Two[2][0][0]) / 100,
randint(100 * One[2][0][1], 100 * Two[2][0][1]) / 100,
randint(100 * One[2][0][2], 100 * Two[2][0][2]) / 100,
randint(100 * One[2][0][3], 100 * Two[2][0][3]) / 100,
randint(100 * One[2][0][4], 100 * Two[2][0][4]) / 100]]]
for index4 in range(2):
Mutate(Net_1)
Mutate(Net_2)
Mutate(Net_3)
Mutate(Net_4)
Mutate(Net_5)
ColorRandom()
def ColorRandom():
global RGB
for index5 in range(5):
color.set_color(index5 + 2,
color.rgb(randint(50, 200), randint(50, 200), randint(50, 200)))
RGB = [randint(0, 255), randint(0, 255), randint(0, 255)]
color.set_color(7, color.rgb(RGB[0], RGB[1], RGB[2]))
def Mutate(Net2: List[List[List[number]]]):
global MutationArray
MutationArray = []
MutationArray.append(randint(0, 2))
if MutationArray[0] == 2:
MutationArray.append(0)
else:
MutationArray.append(randint(0, 3))
if MutationArray[0] == 1:
MutationArray.append(randint(0, 3))
else:
MutationArray.append(randint(0, 4))
Net2[MutationArray[0]][MutationArray[1]][MutationArray[2]] = randint(-100, 100) / 100
def Randomize(_2: number):
global Net_1, Net_2, Net_3, Net_4, Net_5
if _2 == 1:
Net_1 = [[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]]]
elif _2 == 2:
Net_2 = [[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]]]
elif _2 == 3:
Net_3 = [[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]]]
elif _2 == 4:
Net_4 = [[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]]]
elif _2 == 5:
Net_5 = [[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100],
[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]],
[[randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100,
randint(-100, 100) / 100]]]
MutationArray: List[number] = []
RGB: List[number] = []
LoveArray: List[List[List[List[number]]]] = []
OutputArray2: List[number] = []
OutputArray: List[number] = []
Stage = 0
mySprite: Sprite = None
Count = 0
Net_5: List[List[List[number]]] = []
Net_4: List[List[List[number]]] = []
Net_3: List[List[List[number]]] = []
Net_2: List[List[List[number]]] = []
Net_1: List[List[List[number]]] = []
Frog_5: Sprite = None
Frog_4: Sprite = None
Frog_3: Sprite = None
Frog_2: Sprite = None
Frog_1: Sprite = None
ColorRandom()
scene.center_camera_at(88, 60)
tiles.set_current_tilemap(tilemap("""
Level
"""))
ColorShow = sprites.create(assets.image("""
Show
"""), SpriteKind.Menu)
Frog_1 = sprites.create(assets.image("""
Frog_1
"""), SpriteKind.Frog)
Frog_2 = sprites.create(assets.image("""
Frog_2
"""), SpriteKind.Frog)
Frog_3 = sprites.create(assets.image("""
Frog_3
"""), SpriteKind.Frog)
Frog_4 = sprites.create(assets.image("""
Frog_4
"""), SpriteKind.Frog)
Frog_5 = sprites.create(assets.image("""
Frog_5
"""), SpriteKind.Frog)
tiles.place_on_tile(Frog_1, tiles.get_tile_location(2, 4))
tiles.place_on_tile(Frog_2, tiles.get_tile_location(3, 2))
tiles.place_on_tile(Frog_3, tiles.get_tile_location(5, 3))
tiles.place_on_tile(Frog_4, tiles.get_tile_location(7, 1))
tiles.place_on_tile(Frog_5, tiles.get_tile_location(8, 5))
ColorShow.set_position(88, 25)
Net_1 = [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0]]]
Net_2 = [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0]]]
Net_3 = [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0]]]
Net_4 = [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0]]]
Net_5 = [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0]]]
def on_after6():
global Count, mySprite, Stage
game.show_long_text("Welcome to AI Fashion Frogs #1, Color Guessing!",
DialogLayout.BOTTOM)
game.show_long_text("This AI relies on supervised deep learning to mimic how the human brain learns.",
DialogLayout.BOTTOM)
game.show_long_text("With your help, you can train these AI frogs to know your individual color tastes.",
DialogLayout.BOTTOM)
game.show_long_text("Simply pick the two frogs that have the most correct answers and the code will do the rest!",
DialogLayout.BOTTOM)
Count = game.ask_for_number("How many practice guesses do you want?", 2)
mySprite = sprites.create(assets.image("""
Cursor
"""), SpriteKind.player)
grid.snap(mySprite)
grid.move_with_buttons(mySprite)
Randomize(1)
Randomize(2)
Randomize(3)
Randomize(4)
Randomize(5)
ColorRandom()
Round()
Stage = 1
timer.after(500, on_after6)
复制代码