驴友花雕 发表于 2025-9-23 16:41:30

【花雕动手做】基于Kitronik可编程开发板之时尚青蛙游戏



Kitronik ARCADE 是一款由英国教育科技公司 Kitronik 精心打造的可编程游戏机开发板,专为编程教学与创客实践而设计。该设备原生支持微软的 MakeCode Arcade 平台,用户可通过图形化或 JavaScript 编程方式,轻松创建、下载并运行复古风格的街机游戏。

它集成了彩色 LCD 显示屏、方向控制键、功能按键、蜂鸣器和震动马达等交互组件,提供完整的游戏输入输出体验。无论是初学者进行编程启蒙,还是创客群体开发交互式作品,Kitronik ARCADE 都能作为理想的硬件载体,助力创意实现。

凭借其开源友好、易于上手、兼容性强等特点,该开发板广泛应用于中小学编程课程、创客工作坊、游戏开发教学以及个人项目原型设计,深受教育者与技术爱好者的喜爱。



驴友花雕 发表于 2025-9-23 16:42:58

【花雕动手做】基于Kitronik可编程开发板之时尚青蛙游戏

作为学习、练习与尝试,这里创建一个时尚青蛙的小游戏。
打开网页版:https://arcade.makecode.com/,设置项目名称:时尚青蛙

MicroPython实验代码

@namespace
class SpriteKind:
    Frog = SpriteKind.create()
    Menu = SpriteKind.create()
def Think(R: number, G: number, B: number, Net: List]]):
    global OutputArray, OutputArray2
    OutputArray =
    OutputArray2 =
    for index in range(4):
      OutputArray = R * Net + G * Net + (B * Net + Net)
    for index2 in range(4):
      OutputArray2 = OutputArray * Net + OutputArray * Net + (OutputArray * Net + (OutputArray * Net + Net))
    print(OutputArray2 * Net + OutputArray2 * Net + (OutputArray2 * Net + (OutputArray2 * Net + Net)))
    if OutputArray2 * Net + OutputArray2 * Net + (OutputArray2 * Net + (OutputArray2 * Net + Net)) >= 2:
      return "...Ribbit?"
    elif OutputArray2 * Net + OutputArray2 * Net + (OutputArray2 * Net + (OutputArray2 * Net + Net)) >= 1:
      return "LOVE"
    elif OutputArray2 * Net + OutputArray2 * Net + (OutputArray2 * Net + (OutputArray2 * Net + Net)) >= 0.75:
      return "Like"
    elif OutputArray2 * Net + OutputArray2 * Net + (OutputArray2 * Net + (OutputArray2 * Net + Net)) >= 0.5:
      return "OK"
    elif OutputArray2 * Net + OutputArray2 * Net + (OutputArray2 * Net + (OutputArray2 * Net + Net)) >= 0.25:
      return "Dislike"
    elif OutputArray2 * Net + OutputArray2 * Net + (OutputArray2 * Net + (OutputArray2 * Net + Net)) >= -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, LoveArray)
                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:
                              print(value)
                              print(value)
                              print(value)
                        
                        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 / 255, RGB / 255, RGB / 255, Net_1),
      5000,
      False)
    Frog_2.say_text(Think(RGB / 255, RGB / 255, RGB / 255, Net_2),
      5000,
      False)
    Frog_3.say_text(Think(RGB / 255, RGB / 255, RGB / 255, Net_3),
      5000,
      False)
    Frog_4.say_text(Think(RGB / 255, RGB / 255, RGB / 255, Net_4),
      5000,
      False)
    Frog_5.say_text(Think(RGB / 255, RGB / 255, RGB / 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]], Two: List]]):
    global Net_1, Net_2, Net_3, Net_4, Net_5
    Net_1 = [[, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]]]
    Net_2 = [[, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]]]
    Net_3 = [[, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]]]
    Net_4 = [[, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]]]
    Net_5 = [[, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100],
            , 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100]],
      [, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 100,
                randint(100 * One, 100 * Two) / 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 =
    color.set_color(7, color.rgb(RGB, RGB, RGB))
def Mutate(Net2: List]]):
    global MutationArray
    MutationArray = []
    MutationArray.append(randint(0, 2))
    if MutationArray == 2:
      MutationArray.append(0)
    else:
      MutationArray.append(randint(0, 3))
    if MutationArray == 1:
      MutationArray.append(randint(0, 3))
    else:
      MutationArray.append(randint(0, 4))
    Net2]]] = 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 = []
RGB: List = []
LoveArray: List]]] = []
OutputArray2: List = []
OutputArray: List = []
Stage = 0
mySprite: Sprite = None
Count = 0
Net_5: List]] = []
Net_4: List]] = []
Net_3: List]] = []
Net_2: List]] = []
Net_1: List]] = []
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 = [[, , , ],
    [,
      ,
      ,
      ],
    []]
Net_2 = [[, , , ],
    [,
      ,
      ,
      ],
    []]
Net_3 = [[, , , ],
    [,
      ,
      ,
      ],
    []]
Net_4 = [[, , , ],
    [,
      ,
      ,
      ],
    []]
Net_5 = [[, , , ],
    [,
      ,
      ,
      ],
    []]

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)


驴友花雕 发表于 2025-9-23 16:45:57

【花雕动手做】基于Kitronik可编程开发板之时尚青蛙游戏

这是一个基于MakeCode Arcade平台的"AI Fashion Frogs"(AI时尚青蛙)游戏代码。

游戏概述
这是一个通过神经网络模拟AI学习的游戏,玩家需要训练青蛙AI来识别自己对颜色的喜好偏好。

核心组件

1. 神经网络结构
python
def Think(R: number, G: number, B: number, Net: List]]):
这是一个3层神经网络:
输入层:RGB颜色值(3个输入)
隐藏层1:4个神经元
隐藏层2:4个神经元
输出层:1个神经元

2. 神经网络工作原理
前向传播计算:输入 → 隐藏层1 → 隐藏层2 → 输出
使用权重矩阵进行线性变换
输出值映射到情感标签:LOVE, Like, OK, Dislike, HATE

3. 游戏流程
初始化阶段:
创建5只青蛙,每只都有随机的初始神经网络权重
显示随机颜色供青蛙"评价"

训练阶段:
青蛙对颜色给出评价(通过神经网络计算)
玩家选择两只评价最准确的青蛙
系统通过Breed()函数进行"繁殖"(神经网络交叉和变异)
生成新一代的5只青蛙
重复直到训练次数用完

最终选择:
玩家选择最终的AI青蛙
测试该青蛙对各种颜色的偏好

关键技术点
遗传算法实现
python
def Breed(One, Two):
交叉繁殖:从两只父代青蛙的权重中随机选择值
变异:通过Mutate()函数随机改变某些权重
模拟自然选择过程

权重管理
权重值范围:-1.0 到 1.0
使用小数精度(除以100)
通过随机化和选择优化网络性能

游戏特色
教育性:直观展示神经网络和遗传算法的工作原理
交互性:玩家参与训练过程,影响AI进化方向
可视化:通过青蛙图像和特效增强用户体验
个性化:最终AI会反映玩家的颜色偏好

技术架构
前端:MakeCode Arcade游戏引擎
AI核心:自定义实现的简单神经网络
算法:遗传算法优化神经网络权重
交互:网格移动和选择机制
这个项目巧妙地将机器学习概念游戏化,让玩家在娱乐中理解AI训练的基本原理。

驴友花雕 发表于 2025-9-23 16:50:01

【花雕动手做】基于Kitronik可编程开发板之时尚青蛙游戏

通过模拟器,调试与模拟运行



实验场景记录












页: [1]
查看完整版本: 【花雕动手做】基于Kitronik可编程开发板之时尚青蛙游戏