AI learning to play platformer
@Stage\n\n@player\n\ndefine plat. (gravity) (jump) (speed) (friction)\nchange y by (yv)\nchange [yv v] by (gravity)\nif <touching (ground v)?> then\n    repeat until <not <touching (ground v)?>>\n        change y by ((([abs v] of (yv) ) / (yv)) * (-1))\n    end\n    set [yv v] to (<<((letter (2) of (item (1) of [inputs v])) - (1)) = [1]> and <(([abs v] of (yv) ) / (yv)) = [-1]>> * (jump))\nend\nset [xv v] to (((xv) + (((letter (1) of (item (1) of [inputs v])) - (1)) * (speed))) * (friction))\nchange x by (xv)\nif <touching (ground v)?> then\n    repeat until <not <touching (ground v)?>>\n        change x by ((([abs v] of (xv) ) / (xv)) * (-1))\n    end\n    change [score v] by (-0.5)\nend\nif <((letter (1) of (item (1) of [inputs v])) - (1)) = [0]> then\n    change [score v] by (-1)\nend\nif <touching (hurt v)?> then\n    change [score v] by (-1000)\nend\nif <touching (goal v)?> then\n    change [score v] by (1000000000000000000000000000000000)\nend\ncalc distance (x position) (y position) and ([x position v] of [goal v]) ([y position v] of [goal v]) old (oldposx) (oldposy) and ([x position v] of [goal v]) ([y position v] of [goal v])\nif <(return distance) < (return old distance)> then\n    change [score v] by (1)\nend\nif <[60] < (x position)> then\n    change [score v] by (1)\nend\nset [oldposx v] to (x position)\nset [oldposy v] to (y position)\n\nwhen flag clicked\nset [id v] to [0]\ndelete all of [scores v]\ndelete all of [best decisions v]\nset [generation v] to [1]\nset [counter v] to [500]\nset [best ai v] to [-1]\nset [isclone v] to [false]\nhide\ncreate clones\nbroadcast (restart v)\nforever\n    if <(counter) < [1]> then\n        change [generation v] by (1)\n        set [counter v] to [500]\n        select\n        broadcast (restart v)\n    end\n    change [counter v] by (-1)\nend\n\ndefine calc distance (x) (y) and (x1) (y1) old (oldx) (oldy) and (oldx1) (oldy1)\nset [return distance v] to ([sqrt v] of ((((x) - (x1)) * ((x) - (x1))) + (((y) - (y1)) * ((y) - (y1)))) )\nset [return old distance v] to ([sqrt v] of ((((oldx) - (oldx1)) * ((oldx) - (oldx1))) + (((oldy) - (oldy1)) * ((oldy) - (oldy1)))) )\n\ndefine create clones\nrepeat (50)\n    change [id v] by (1)\n    create clone of (_myself_ v)\n    add [0] to [scores v]\nend\nset [id v] to [-1]\n\ndefine select\nset [score compare v] to [0]\nset [best ai v] to [-1]\nset [i v] to [1]\nrepeat (length of [scores v])\n    if <(item (i) of [scores v]) > (score compare)> then\n        set [score compare v] to (item (i) of [scores v])\n        set [best ai v] to (i)\n    end\n    change [i v] by (1)\nend\n\ndefine paste info\ndelete all of [best decisions v]\nset [i v] to [1]\nrepeat (length of [decision v])\n    add (item (i) of [decision v]) to [best decisions v]\n    change [i v] by (1)\nend\n\nwhen I start as a clone\nset [isclone v] to [true]\n\nwhen I receive [restart v]\nif <(isclone) = [true]> then\n    if <(best AI) = (id)> then\n        if <(generation) > [1]> then\n            paste info\n        end\n        show\n        set rotation style [left-right v]\n        go to x: (-230) y: (0)\n        set [xv v] to [0]\n        set [yv v] to [0]\n        set [score v] to [0]\n        delete all of [decision v]\n        delete all of [inputs v]\n        add [0] to [inputs v]\n        set [move v] to [1]\n        set [wait v] to [0]\n        forever\n            plat. [-0.8] [8] [0.8] [0.85]\n            change [wait v] by (-1)\n            if <(wait) < [0]> then\n                set [wait v] to [5]\n                if <(generation) = [1]> then\n                    set [input v] to (join (pick random (0) to (2)) (pick random (0) to (2)))\n                    replace item (1) of [inputs v] with (input)\n                    add (input) to [decision v]\n                else\n                    set [input v] to (item (move) of [best decisions v])\n                    replace item (1) of [inputs v] with (input)\n                    add (input) to [decision v]\n                end\n                if <(move) < [201]> then\n                    change [move v] by (1)\n                end\n                replace item (id) of [scores v] with (score)\n            end\n        end\n    else\n        show\n        set rotation style [left-right v]\n        go to x: (-230) y: (0)\n        set [xv v] to [0]\n        set [yv v] to [0]\n        set [score v] to [0]\n        delete all of [decision v]\n        delete all of [inputs v]\n        add [0] to [inputs v]\n        set [move v] to [1]\n        set [wait v] to [0]\n        forever\n            plat. [-0.8] [8] [0.8] [0.85]\n            change [wait v] by (-1)\n            if <(wait) < [0]> then\n                set [wait v] to [5]\n                if <(generation) = [1]> then\n                    set [input v] to (join (pick random (0) to (2)) (pick random (0) to (2)))\n                    replace item (1) of [inputs v] with (input)\n                    add (input) to [decision v]\n                else\n                    if <(pick random (1) to (5)) = [1]> then\n                        set [input v] to (join (pick random (0) to (2)) (pick random (0) to (2)))\n                    else\n                        set [input v] to (item (move) of [best decisions v])\n                    end\n                    replace item (1) of [inputs v] with (input)\n                    add (input) to [decision v]\n                end\n                if <(move) < [201]> then\n                    change [move v] by (1)\n                end\n                replace item (id) of [scores v] with (score)\n            end\n        end\n    end\nend\n\nwhen I receive [finish v]\ndelete this clone\n\nwhen I receive [finish v]\nshow\nset rotation style [left-right v]\ngo to x: (-230) y: (0)\nset [xv v] to [0]\nset [yv v] to [0]\nset [move v] to [1]\nset [wait v] to [0]\nforever\n    plat. [-0.8] [8] [0.8] [0.85]\n    change [wait v] by (-1)\n    if <(wait) < [0]> then\n        set [wait v] to [5]\n    end\n    set [input v] to (item (move) of [best decisions v])\n    replace item (1) of [inputs v] with (input)\n    add (input) to [decision v]\n    replace item (id) of [scores v] with (score)\nend\n\n@ground\n\n@hurt\n\n@goal\n\n@number\n\nwhen flag clicked\nhide\nforever\n    print(score) (generation)\nend\n\ndefine print(score) (score)\nset [digit v] to [0]\ngo to x: (((length of (score)) * (-9)) + (9)) y: (160)\nrepeat (length of (score))\n    change [digit v] by (1)\n    switch costume to (join [n] (letter (digit) of (score)))\n    create clone of (_myself_ v)\n    change x by (18)\nend\n\nwhen I start as a clone\nclear graphic effects\nset size to (100) %\nset [brightness v] effect to (100)\nshow\nwait (0) seconds\ndelete this clone\n\ndefine print(highscore) (highscore)\nset [digit v] to [0]\ngo to x: (((length of (highscore)) * (-9)) + (9)) y: (-67)\nrepeat (length of (highscore))\n    change [digit v] by (1)\n    switch costume to (join [n] (letter (digit) of (highscore)))\n    create clone of (_myself_ v)\n    change x by (18)\nend\n\n
Do you often rage at platformers games? worry no more with this robot that learns how to play them so you dont have to do it urself. *only takes away the whole fun of platformers and may take hours to learn*\n\nhi :p i wanted to take a break from my new unity game so i attempted to make an AI that could learn. if you dont know how it works, basically first it start out random. everytime when the AI does something good, u reward it and if it does bad, u punish it. at the end of every gen, u pick the smartest of the AIs and clone them. evetually one of them will make it to the finish. 