/* Kidopia idea engine: reads a game idea in plain words and turns it into a game plan, on the device, with no AI service. How it works: 1. Words and short phrases are looked up in a picture dictionary (creatures, food, things, dangers, places, verbs, looks). 2. Verbs set what the nouns after them mean: "collect carrots" makes carrots the treats, "dodge sharks" makes sharks the enemies, "save puppies" makes puppies the friends to rescue. "no" or "without" skips the next thing. 3. The first two kinds of play it hears become the game type and the mixed-in extra (for example racing plus collecting). 4. Looks words change the game: night, rain, snow, bubbles, hearts, sparkles, giant or tiny hero, sky colours. 5. If an idea is outside what the engine can make (sports, cooking, fighting), it picks the closest game it can make. The result also lists which words did what, so the game can show the child how their idea became the game. */ (function(){'use strict'; /* ---- picture dictionary ---- kind: c creature (can be hero, friend or enemy), v vehicle (hero, racing), f food (treat), o thing (treat), d danger (enemy), plural forms are found by the word stemmer. "fl" marks things that fly. */ const D={}; function add(kind,list){list.split(',').forEach(it=>{const [w,e,extra]=it.split(':');const n=w.trim();D[n]={k:kind,e,w:n,fl:extra==='fl',sea:extra==='sea'};});} add('c','pig:๐Ÿท,cow:๐Ÿฎ,horse:๐Ÿด,pony:๐Ÿด,unicorn:๐Ÿฆ„:fl,dragon:๐Ÿ‰:fl,dino:๐Ÿฆ•,dinosaur:๐Ÿฆ•,trex:๐Ÿฆ–,dog:๐Ÿถ,puppy:๐Ÿถ,doggy:๐Ÿถ,bunny:๐Ÿฐ,rabbit:๐Ÿฐ,bear:๐Ÿป,teddy:๐Ÿงธ,panda:๐Ÿผ,koala:๐Ÿจ,penguin:๐Ÿง,fox:๐ŸฆŠ,monkey:๐Ÿต,elephant:๐Ÿ˜,giraffe:๐Ÿฆ’,owl:๐Ÿฆ‰:fl,frog:๐Ÿธ,duck:๐Ÿฆ†:fl,chicken:๐Ÿ”,chick:๐Ÿฅ,turtle:๐Ÿข:sea,fish:๐ŸŸ:sea,dolphin:๐Ÿฌ:sea,whale:๐Ÿณ:sea,octopus:๐Ÿ™:sea,mermaid:๐Ÿงœโ€โ™€๏ธ:sea,fairy:๐Ÿงš:fl,wizard:๐Ÿง™,princess:๐Ÿ‘ธ,prince:๐Ÿคด,king:๐Ÿคด,queen:๐Ÿ‘ธ,superhero:๐Ÿฆธ:fl,hero:๐Ÿฆธ:fl,ninja:๐Ÿฅท,pirate:๐Ÿฆœ,parrot:๐Ÿฆœ:fl,astronaut:๐Ÿง‘โ€๐Ÿš€,alien:๐Ÿ‘ฝ,robot:๐Ÿค–,butterfly:๐Ÿฆ‹:fl,ladybug:๐Ÿž:fl,snail:๐ŸŒ,mouse:๐Ÿญ,hamster:๐Ÿน,hedgehog:๐Ÿฆ”,sloth:๐Ÿฆฅ,deer:๐ŸฆŒ,sheep:๐Ÿ‘,goat:๐Ÿ,zebra:๐Ÿฆ“,hippo:๐Ÿฆ›,rhino:๐Ÿฆ,kangaroo:๐Ÿฆ˜,flamingo:๐Ÿฆฉ:fl,peacock:๐Ÿฆš,swan:๐Ÿฆข:sea,eagle:๐Ÿฆ…:fl,bird:๐Ÿฆ:fl,seal:๐Ÿฆญ:sea,otter:๐Ÿฆฆ:sea,squirrel:๐Ÿฟ๏ธ,raccoon:๐Ÿฆ,ant:๐Ÿœ,snowman:โ›„,baby:๐Ÿฃ,girl:๐Ÿ‘ง,boy:๐Ÿ‘ฆ,kid:๐Ÿง’,mom:๐Ÿ‘ฉ,dad:๐Ÿ‘จ,grandma:๐Ÿ‘ต,grandpa:๐Ÿ‘ด,friend:๐Ÿง’,ghost:๐Ÿ‘ป,elf:๐Ÿง,giant:๐ŸงŒ'); add('v','car:๐Ÿš—,racecar:๐ŸŽ๏ธ,kart:๐ŸŽ๏ธ,truck:๐Ÿšš,train:๐Ÿš‚,bus:๐ŸšŒ,bike:๐Ÿšฒ,bicycle:๐Ÿšฒ,tractor:๐Ÿšœ,motorcycle:๐Ÿ๏ธ,scooter:๐Ÿ›ด,skateboard:๐Ÿ›น,rocket:๐Ÿš€:fl,plane:โœˆ๏ธ:fl,airplane:โœˆ๏ธ:fl,jet:โœˆ๏ธ:fl,helicopter:๐Ÿš:fl,ufo:๐Ÿ›ธ:fl,spaceship:๐Ÿš€:fl,boat:โ›ต:sea,ship:๐Ÿšข:sea,submarine:๐Ÿšค:sea,balloon:๐ŸŽˆ:fl'); add('f','pizza:๐Ÿ•,pepper:๐ŸŒถ๏ธ,chilli:๐ŸŒถ๏ธ,chili:๐ŸŒถ๏ธ,cake:๐ŸŽ‚,cookie:๐Ÿช,donut:๐Ÿฉ,doughnut:๐Ÿฉ,candy:๐Ÿฌ,sweet:๐Ÿฌ,lollipop:๐Ÿญ,chocolate:๐Ÿซ,icecream:๐Ÿฆ,apple:๐ŸŽ,banana:๐ŸŒ,strawberry:๐Ÿ“,watermelon:๐Ÿ‰,carrot:๐Ÿฅ•,cheese:๐Ÿง€,burger:๐Ÿ”,hamburger:๐Ÿ”,fries:๐ŸŸ,taco:๐ŸŒฎ,sushi:๐Ÿฃ,popcorn:๐Ÿฟ,pancake:๐Ÿฅž,waffle:๐Ÿง‡,bread:๐Ÿž,egg:๐Ÿฅš,cherry:๐Ÿ’,grape:๐Ÿ‡,orange:๐ŸŠ,lemon:๐Ÿ‹,pineapple:๐Ÿ,peach:๐Ÿ‘,corn:๐ŸŒฝ,honey:๐Ÿฏ,milk:๐Ÿฅ›,juice:๐Ÿงƒ,pretzel:๐Ÿฅจ,croissant:๐Ÿฅ,broccoli:๐Ÿฅฆ,mushroom:๐Ÿ„,hotdog:๐ŸŒญ,noodle:๐Ÿœ,pasta:๐Ÿ,muffin:๐Ÿง,cupcake:๐Ÿง,pie:๐Ÿฅง,sandwich:๐Ÿฅช,fruit:๐Ÿ“,veggie:๐Ÿฅฆ,vegetable:๐Ÿฅ•,food:๐Ÿ•,snack:๐Ÿฟ,treat:๐Ÿฌ,acorn:๐ŸŒฐ,nut:๐Ÿฅœ,peanut:๐Ÿฅœ,coconut:๐Ÿฅฅ,avocado:๐Ÿฅ‘,potato:๐Ÿฅ”,tomato:๐Ÿ…'); add('o','coin:๐Ÿช™,gold:๐Ÿช™,money:๐Ÿ’ฐ,treasure:๐Ÿ’ฐ,gem:๐Ÿ’Ž,diamond:๐Ÿ’Ž,jewel:๐Ÿ’Ž,crystal:๐Ÿ’Ž,star:โญ,heart:โค๏ธ,crown:๐Ÿ‘‘,key:๐Ÿ—๏ธ,ball:โšฝ,football:๐Ÿˆ,basketball:๐Ÿ€,soccerball:โšฝ,present:๐ŸŽ,gift:๐ŸŽ,flower:๐ŸŒธ,rose:๐ŸŒน,leaf:๐Ÿƒ,shell:๐Ÿš,book:๐Ÿ“š,note:๐ŸŽต,trophy:๐Ÿ†,medal:๐Ÿ…,toy:๐Ÿงธ,kite:๐Ÿช,potion:๐Ÿงช,battery:๐Ÿ”‹,bone:๐Ÿฆด,sock:๐Ÿงฆ,shoe:๐Ÿ‘Ÿ,hat:๐ŸŽฉ,ring:๐Ÿ’,sticker:โญ,card:๐Ÿƒ,letter:๐Ÿ’Œ,cloud:โ˜๏ธ,sun:โ˜€๏ธ,moonstone:๐ŸŒ™,feather:๐Ÿชถ,block:๐Ÿงฑ,brick:๐Ÿงฑ,stone:๐Ÿชจ,pearl:๐Ÿฆช,bubble:๐Ÿซง,snowflake:โ„๏ธ,balloons:๐ŸŽˆ'); add('d','shark:๐Ÿฆˆ:sea,crab:๐Ÿฆ€:sea,bee:๐Ÿ:fl,spider:๐Ÿ•ท๏ธ,snake:๐Ÿ,bat:๐Ÿฆ‡:fl,monster:๐Ÿ‘พ,zombie:๐Ÿ‘พ,villain:๐Ÿ‘พ,meteor:โ˜„๏ธ:fl,asteroid:โ˜„๏ธ:fl,rock:๐Ÿชจ,boulder:๐Ÿชจ,fire:๐Ÿ”ฅ,lava:๐Ÿ”ฅ,storm:โ›ˆ๏ธ,lightning:โšก,tornado:๐ŸŒช๏ธ,cactus:๐ŸŒต,wave:๐ŸŒŠ:sea,iceberg:๐ŸงŠ,mosquito:๐ŸฆŸ:fl,scorpion:๐Ÿฆ‚,wolf:๐Ÿบ,squid:๐Ÿฆ‘:sea,jellyfish:๐Ÿฆ‘:sea,slime:๐ŸŸข,trap:๐Ÿชค,thunder:๐ŸŒฉ๏ธ,witch:๐Ÿง™,goblin:๐ŸงŒ,troll:๐ŸงŒ,crocodile:๐ŸŠ,alligator:๐ŸŠ,bull:๐Ÿ‚,wasp:๐Ÿ,fly:๐Ÿชฐ'); /* phrases (several words) become one word before reading */ const PHR=[['ice cream','icecream'],['hot dog','hotdog'],['race car','racecar'],['t rex','trex'],['t-rex','trex'],['north pole','northpole'],['outer space','space'],['candy land','candy'],['hide and seek','hideseek'],['super jump','superjump'],['run away','runaway'],['pick up','pickup'],['obstacle course','obstacle'],['under the sea','underwater'],['under water','underwater'],['haunted house','spookyhouse'],['spooky house','spookyhouse'],['toy shop','toyshop'],['toy store','toyshop'],['play as','playas'],['i am','iam'],["i'm",'iam'],['soccer ball','soccerball'],['high score','highscore'],['lots of','lots'],['a lot of','lots'],['tons of','lots'],['loads of','lots'],['super fast','fast'],['really fast','fast'],['space ship','spaceship'],['rain bow','rainbow'],['dodge ball','dodgeball'],['bad guys','villain'],['bad guy','villain']]; /* places: base world plus a custom look when the place is new */ const PL={ rainbow:{w:'rainbow'},sky:{w:'sky'},cloud:{w:'sky'},clouds:{w:'sky'},mountain:{w:'sky'},mountains:{w:'sky'}, candy:{w:'candy'},candyland:{w:'candy'},sweets:{w:'candy'},chocolate:{w:'candy'}, sea:{w:'ocean'},ocean:{w:'ocean'},underwater:{w:'ocean'},reef:{w:'ocean'}, lake:{w:'ocean',x:{n:'Sparkle Lake',s:'Lake',e:'๐Ÿž๏ธ',sky:['#7fd8ff','#2b8be0'],marks:['๐Ÿฆ†','๐Ÿ›ถ','๐Ÿž๏ธ','๐Ÿธ','๐Ÿฆข']}}, river:{w:'ocean',x:{n:'Rushing River',s:'River',e:'๐Ÿž๏ธ',sky:['#8fe0ff','#3a9be8'],marks:['๐Ÿฆฆ','๐Ÿ›ถ','๐ŸŸ','๐ŸŒ‰','๐Ÿฆ†']}}, space:{w:'space'},planet:{w:'space'},galaxy:{w:'space'},stars:{w:'space'}, moon:{w:'space',x:{n:'The Moon',s:'Moon',e:'๐ŸŒ™',sky:['#0b0630','#2a2a4a'],gr:'#b8b8c8',gr2:'#d8d8e4',deco:['๐ŸŒ','โœจ','๐ŸŒ™'],marks:['๐Ÿš€','๐Ÿ›ฐ๏ธ','๐ŸŒ','๐Ÿณ๏ธ','๐ŸŒ•']}}, mars:{w:'space',x:{n:'Planet Mars',s:'Mars',e:'๐Ÿ”ด',sky:['#3a0a14','#a8452a'],gr:'#c0502a',gr2:'#e07040',deco:['โœจ','๐Ÿช'],marks:['๐Ÿš€','๐Ÿ›ธ','๐Ÿชจ','๐Ÿ›ฐ๏ธ','๐ŸŒ‹']}}, icecream:{w:'icecream'},factory:{w:'robot'},lab:{w:'robot'},robotland:{w:'robot'}, kitchen:{w:'icecream',x:{n:'Giant Kitchen',s:'Kitchen',e:'๐Ÿณ',sky:['#fff3d6','#ffd6a5'],gr:'#e8c49a',gr2:'#fff',deco:['๐Ÿณ','๐Ÿฅ„'],marks:['๐Ÿณ','๐Ÿง','๐Ÿฅž','๐Ÿซ–','๐Ÿฐ']}}, castle:{w:'castle'},palace:{w:'castle'},kingdom:{w:'castle'}, city:{w:'city'},town:{w:'city'},street:{w:'city'}, school:{w:'city',x:{n:'School Day',s:'School',e:'๐Ÿซ',sky:['#8fd0ff','#e6f6ff'],gr:'#9ad48a',gr2:'#ffd23f',deco:['๐Ÿซ','โœ๏ธ'],marks:['๐Ÿซ','๐Ÿ“š','๐Ÿ–๏ธ','๐ŸšŒ','๐ŸŽ’']}}, donut:{w:'donut'},bakery:{w:'donut'}, pirate:{w:'pirate'},island:{w:'pirate'}, beach:{w:'pirate',x:{n:'Sunny Beach',s:'Beach',e:'๐Ÿ–๏ธ',sky:['#5ad1ff','#fff3c8'],gr:'#f7dc8f',gr2:'#4fc3e8',deco:['๐Ÿ–๏ธ','๐ŸŒด'],marks:['๐Ÿ–๏ธ','๐Ÿฐ','๐Ÿš','โ›ฑ๏ธ','๐Ÿฆ€']}}, jungle:{w:'jungle'},rainforest:{w:'jungle'},zoo:{w:'jungle'},safari:{w:'jungle'},park:{w:'jungle'}, forest:{w:'jungle',x:{n:'Whispering Forest',s:'Forest',e:'๐ŸŒฒ',sky:['#a8e6b0','#f0ffe0'],gr:'#4a9a4a',gr2:'#2f7a3a',deco:['๐ŸŒฒ','๐Ÿ„'],marks:['๐ŸŒฒ','๐ŸฆŒ','๐Ÿ„','๐Ÿ•๏ธ','๐Ÿฆ‰']}}, woods:{w:'jungle',x:{n:'Whispering Forest',s:'Forest',e:'๐ŸŒฒ',sky:['#a8e6b0','#f0ffe0'],gr:'#4a9a4a',gr2:'#2f7a3a',deco:['๐ŸŒฒ','๐Ÿ„'],marks:['๐ŸŒฒ','๐ŸฆŒ','๐Ÿ„','๐Ÿ•๏ธ','๐Ÿฆ‰']}}, farm:{w:'jungle',x:{n:'Happy Farm',s:'Farm',e:'๐Ÿšœ',sky:['#9be0ff','#fff6d0'],gr:'#9ad46a',gr2:'#c9a06a',deco:['๐ŸŒป','๐ŸŒพ'],marks:['๐Ÿšœ','๐Ÿก','๐ŸŒฝ','๐Ÿ„','๐Ÿ“']}}, desert:{w:'volcano',x:{n:'Sunny Desert',s:'Desert',e:'๐Ÿœ๏ธ',sky:['#ffb36b','#fff0c4'],gr:'#f0c878',gr2:'#e0a850',deco:['๐ŸŒต','๐Ÿœ๏ธ'],marks:['๐Ÿซ','๐Ÿœ๏ธ','๐ŸŒต','๐Ÿ—ฟ','โ›บ']}}, volcano:{w:'volcano'},cave:{w:'volcano',x:{n:'Crystal Cave',s:'Cave',e:'๐Ÿ’Ž',sky:['#1a1030','#4a3070'],gr:'#5a4a6a',gr2:'#7a6a9a',deco:['๐Ÿ’Ž','๐Ÿฆ‡'],marks:['๐Ÿ’Ž','๐Ÿ”ฆ','๐Ÿฆ‡','๐Ÿชจ','๐Ÿ—๏ธ']}}, snow:{w:'snow'},winter:{w:'snow'},arctic:{w:'snow'},northpole:{w:'snow'},iceland:{w:'snow'}, house:{w:'castle',x:{n:'Cozy House',s:'House',e:'๐Ÿก',sky:['#ffe4c4','#fff8ee'],gr:'#e0b080',gr2:'#ff9ad5',deco:['๐Ÿชด','๐Ÿ–ผ๏ธ'],marks:['๐Ÿ›๏ธ','๐Ÿงธ','๐Ÿ›','๐Ÿ“บ','๐Ÿช']}}, home:{w:'castle',x:{n:'Cozy House',s:'House',e:'๐Ÿก',sky:['#ffe4c4','#fff8ee'],gr:'#e0b080',gr2:'#ff9ad5',deco:['๐Ÿชด','๐Ÿ–ผ๏ธ'],marks:['๐Ÿ›๏ธ','๐Ÿงธ','๐Ÿ›','๐Ÿ“บ','๐Ÿช']}}, bedroom:{w:'castle',x:{n:'Bedroom Adventure',s:'Bedroom',e:'๐Ÿ›๏ธ',sky:['#c9d6ff','#fff0f8'],gr:'#c8a0e0',gr2:'#ffd6ec',deco:['๐Ÿงธ','๐ŸŒ™'],marks:['๐Ÿ›๏ธ','๐Ÿงธ','๐Ÿช€','๐Ÿ“š','๐Ÿš‚']}}, spookyhouse:{w:'castle',x:{n:'Silly Spooky House',s:'Spooky',e:'๐Ÿš๏ธ',sky:['#2a1460','#6a3fa0'],gr:'#4a3a6a',gr2:'#7a5aa0',deco:['๐Ÿ•ธ๏ธ','๐ŸŽƒ'],marks:['๐Ÿš๏ธ','๐ŸŽƒ','๐Ÿ•ฏ๏ธ','๐Ÿฆ‰','๐Ÿฌ']}}, toyshop:{w:'candy',x:{n:'Toy Shop',s:'Toy',e:'๐Ÿงธ',sky:['#ffd6ec','#e6f6ff'],gr:'#ffcf8a',gr2:'#ff8fd0',deco:['๐Ÿงธ','๐Ÿช€'],marks:['๐Ÿงธ','๐Ÿช','๐Ÿš‚','๐ŸŽฒ','๐Ÿช€']}}, playground:{w:'rainbow',x:{n:'Playground',s:'Playground',e:'๐Ÿ›',sky:['#8fd8ff','#fff6d0'],gr:'#8be08b',gr2:'#ffd23f',deco:['๐ŸŒณ','โšฝ'],marks:['๐Ÿ›','โšฝ','๐Ÿช','๐ŸŒณ','๐Ÿ€']}}, stadium:{w:'city',x:{n:'Big Stadium',s:'Stadium',e:'๐ŸŸ๏ธ',sky:['#3fa8ff','#d6efff'],gr:'#4cc15a',gr2:'#ffffff',deco:['๐ŸŸ๏ธ','๐ŸŽ‰'],marks:['๐ŸŸ๏ธ','๐Ÿ†','โšฝ','๐Ÿฅ…','๐Ÿ“ฃ']}} }; /* kinds of play */ const MV={race:'race',racing:'race',drive:'race',driving:'race',kart:'race',zoom:'race',speedway:'race',racetrack:'race', fly:'fly',flying:'fly',soar:'fly',glide:'fly',wing:'fly',jetpack:'fly',swim:'fly',float:'fly', jump:'platform',hop:'platform',climb:'platform',run:'platform',parkour:'platform',obstacle:'platform',bounce:'platform',platform:'platform',skip:'platform', treasure:'treasure',dig:'treasure',hunt:'treasure',map:'treasure', explore:'explore',adventure:'explore',discover:'explore',travel:'explore',journey:'explore',visit:'explore',quest:'explore',hideseek:'explore',wander:'explore', collect:'collect',catch:'collect',gather:'collect',grab:'collect',pickup:'collect',eat:'collect',munch:'collect',feed:'collect',cook:'collect',bake:'collect',shop:'collect',buy:'collect', dodge:'dodge',avoid:'dodge',escape:'dodge',runaway:'dodge',survive:'dodge',hide:'dodge',dodgeball:'dodge',chase:'dodge', puzzle:'puzzle',memory:'puzzle',match:'puzzle',think:'puzzle',brain:'puzzle',remember:'puzzle',solve:'puzzle', rescue:'rescue',save:'rescue',help:'rescue',protect:'rescue',free:'rescue',lost:'rescue'}; const CTX={collect:'item',catch:'item',gather:'item',grab:'item',pickup:'item',eat:'item',munch:'item',feed:'item',cook:'item',bake:'item',buy:'item',get:'item',find:'item',win:'item',earn:'item', dodge:'haz',avoid:'haz',escape:'haz',runaway:'haz',from:'haz',against:'haz',fight:'haz',battle:'haz',beat:'haz',chase:'haz',over:'haz',chased:'haz',enemy:'haz',enemies:'haz',villain:'haz',attack:'haz',defeat:'haz',stop:'haz',zap:'haz',dodgeball:'haz',survive:'haz',hide:'haz', rescue:'friend',save:'friend',help:'friend',protect:'friend',free:'friend',lost:'friend', playas:'hero',iam:'hero',am:'hero',be:'hero',starring:'hero'}; const POW={fast:'speed',speedy:'speed',quick:'speed',speed:'speed',zoomy:'speed',shield:'shield',safe:'shield',armor:'shield',invincible:'shield',protected:'shield', magnet:'magnet',magnetic:'magnet',superjump:'jump',jumpy:'jump',bouncy:'jump',spring:'jump',slow:'slow',slowmo:'slow',freeze:'slow',double:'double',rich:'double',highscore:'double',points:'double'}; const MUSW={party:'party',dance:'party',disco:'party',dancing:'party',calm:'calm',sleepy:'calm',quiet:'calm',relax:'calm',peaceful:'calm',cozy:'calm', epic:'adventure',brave:'adventure',adventure:'adventure',exciting:'adventure',spooky:'adventure',space:'space',cosmic:'space',happy:'happy',silly:'happy',funny:'happy',cute:'happy'}; const LVW={easy:'easy',simple:'easy',little:'easy',medium:'medium',normal:'medium',hard:'hard',difficult:'hard',crazy:'hard',impossible:'hard',tricky:'hard',extreme:'hard'}; const TINT={pink:['#ff9ad5','#ffe0f0'],purple:['#9b5cff','#e6d6ff'],blue:['#3fa8ff','#d6efff'],green:['#4cd18a','#e0ffe8'],yellow:['#ffd23f','#fff6c8'], orange:['#ff8a3d','#ffe0c4'],red:['#ff4f6d','#ffd6dc'],gold:['#ffc21a','#fff3b0'],golden:['#ffc21a','#fff3b0'],silver:['#b8c4d6','#f0f4fa']}; const WEA={rain:'rain',rainy:'rain',raining:'rain',snowy:'snow',snowing:'snow',snowflake:'snow',heart:'hearts',love:'hearts',valentine:'hearts',bubble:'bubbles',bubbly:'bubbles', sparkle:'sparkles',sparkly:'sparkles',glitter:'sparkles',magic:'sparkles',magical:'sparkles',shiny:'sparkles',leaf:'leaves',autumn:'leaves',fall:'leaves',confetti:'confetti'}; const NIGHT={night:1,dark:1,midnight:1,nighttime:1,moonlight:1,evening:1}; const BIG={giant:1.35,huge:1.35,big:1.25,enormous:1.4,mega:1.35,gigantic:1.4},SMALL={tiny:.75,little:.85,small:.8,mini:.75,teeny:.7}; const NEG={no:1,not:1,without:1,never:1,dont:1,"don't":1,nothing:1}; const NEAR=[ [/\b(soccer|football|basketball|sport|tennis|golf|baseball|hockey)(s|es|ing|ed|er|ers)?\b/,{mode:'collect',item:'โšฝ',music:'party'},'A sports game! You catch the balls.'], [/\b(cook|chef|recipe|restaurant)(s|es|ing|ed|er|ers)?\b/,{mode:'collect',world:'kitchen'},'A cooking game! Catch the food for the kitchen.'], [/\b(fight|battle|war|shoot|gun|sword|punch|kill)(s|es|ing|ed|er|ers)?\b/,{mode:'dodge',power:'shield'},'This is a friendly dodging game instead of a fight.'], [/\b(draw|paint|art|colou?r)(s|es|ing|ed|er|ers)?\b/,{mode:'puzzle',world:'rainbow'},'An art game! A colorful matching puzzle.'], [/\b(music|sing|piano|song|band|guitar|drum)(s|es|ing|ed|er|ers)?\b/,{mode:'collect',item:'๐ŸŽต',music:'party'},'A music game! Catch the notes.'], [/\b(scary|horror|creepy)(s|es|ing|ed|er|ers)?\b/,{mode:'dodge',haz:'๐Ÿ‘ป',world:'spookyhouse'},'A silly-spooky game with friendly ghosts.'], [/\b(build|block|craft)(s|es|ing|ed|er|ers)?\b/,{mode:'platform',item:'๐Ÿงฑ'},'A building game! Jump across the blocks.'], [/\b(shop|store|money|sell)(s|es|ing|ed|er|ers)?\b/,{mode:'collect',item:'๐Ÿช™'},'Collect all the coins!'], [/\b(school|learn|math|read)(s|es|ing|ed|er|ers)?\b/,{mode:'puzzle',world:'school'},'A school game! A memory puzzle.'], [/\b(sleep|bed|dream)(s|es|ing|ed|er|ers)?\b/,{mode:'explore',world:'bedroom',night:1},'A dream game! Explore the dark bedroom.'] ]; const NAME_MODE={race:'Race',fly:'Flight',platform:'Jump',treasure:'Treasure Hunt',explore:'Quest',collect:'Catch',dodge:'Dash',puzzle:'Puzzle',rescue:'Rescue'}; const MODE_LABEL={race:'Racing game',fly:'Flying game',platform:'Jumping game',treasure:'Treasure hunt',explore:'Exploring game',collect:'Collecting game',dodge:'Dodging game',puzzle:'Memory puzzle',rescue:'Rescue game'}; const MODE_E={race:'๐ŸŽ๏ธ',fly:'โœˆ๏ธ',platform:'๐Ÿฆ˜',treasure:'๐Ÿ—บ๏ธ',explore:'๐Ÿ”ญ',collect:'๐Ÿงบ',dodge:'๐Ÿ’จ',puzzle:'๐Ÿงฉ',rescue:'๐Ÿ›Ÿ'}; const MIX_OF={collect:'collect',rescue:'rescue',dodge:'dodge',treasure:'treasure',race:'clock'}; const MIX_LABEL={collect:'+ collecting',rescue:'+ rescuing friends',dodge:'+ extra dodging',treasure:'+ big treasure',clock:'+ beat the clock'}; const WEA_E={rain:'๐ŸŒง๏ธ',snow:'โ„๏ธ',hearts:'๐Ÿ’–',bubbles:'๐Ÿซง',sparkles:'โœจ',leaves:'๐Ÿ‚',confetti:'๐ŸŽ‰'}; const POW_N={speed:'Super speed',shield:'Shield bubble',magnet:'Magnet',jump:'Super jump',slow:'Slow motion',double:'Double points'}; const POW_E={speed:'โšก',shield:'๐Ÿ›ก๏ธ',magnet:'๐Ÿงฒ',jump:'๐Ÿš€',slow:'โณ',double:'โœจ'}; const cap=s=>s.charAt(0).toUpperCase()+s.slice(1); function stems(w){ const out=[w];const add=s=>{if(s&&s.length>1&&out.indexOf(s)<0)out.push(s);}; if(w.endsWith('ies'))add(w.slice(0,-3)+'y'); if(w.endsWith('es'))add(w.slice(0,-2)); if(w.endsWith('s'))add(w.slice(0,-1)); if(w.endsWith('ves'))add(w.slice(0,-3)+'f'); if(w.endsWith('ing')){const b=w.slice(0,-3);add(b);add(b+'e');if(b.length>2&&b[b.length-1]===b[b.length-2])add(b.slice(0,-1));} if(w.endsWith('ed')){const b=w.slice(0,-2);add(b);add(w.slice(0,-1));if(b.length>2&&b[b.length-1]===b[b.length-2])add(b.slice(0,-1));} if(w.endsWith('er'))add(w.slice(0,-2)); if(w==='mice')add('mouse');if(w==='geese')add('duck');if(w==='children'||w==='kids')add('kid');if(w==='people')add('friend'); return out; } function find(table,w){for(const s of stems(w))if(Object.prototype.hasOwnProperty.call(table,s))return {key:s,v:table[s]};return null;} /* Read an idea. ctx: {heroes:[{id,e,n}], worlds:[{id,...}], okWorld(id)} */ function read(text,ctx){ const raw=String(text||'').slice(0,160); let t=' '+raw.toLowerCase().replace(/[โ€™']/g,"'").replace(/[,.;:!?]+/g,' | ').replace(/\bmixed with\b|\bthen\b|\bbut\b|\bplus\b/g,' | ').replace(/[^a-z0-9'| -]/g,' ')+' '; for(const [a,b] of PHR)t=t.split(' '+a+' ').join(' '+b+' '); const words=t.split(/\s+/).filter(Boolean); const P={text:raw,heroE:null,heroN:null,heroWord:null,heroFl:false,heroSea:false,vehicle:false,place:null,placeWord:null,modes:[],items:[],haz:null,hazN:null,friends:[], power:null,music:null,level:null,night:false,weather:null,size:1,tint:null,im:1,hm:1,notes:[],marks:[],swaps:[]}; let ctxRole=null,neg=0,lots=false; const note=(w,e,what,role)=>{if(!P.notes.some(n=>(n.w===w||n.e===e)&&n.what===what))P.notes.push({w,e,what,role});P.marks.push({w,role});}; for(let i=0;i0)neg--; if(/^(in|on|at|into|inside|across|through|around)$/.test(w)&&ctxRole!=='hero'){ctxRole=null;continue;} if(w==='lots'||w==='many'||w==='hundreds'||w==='millions'||w==='loads'){lots=true;continue;} if(w==='and'||w==='the'||w==='a'||w==='an'||w==='of'||w==='to'||w==='in'||w==='on'||w==='at'||w==='with'||w==='game'||w==='games')continue; // context verbs and kinds of play const cv=find(CTX,w);if(cv&&!neg)ctxRole=cv.v; const mv=find(MV,w); if(mv&&!neg){if(P.modes.indexOf(mv.v)<0){P.modes.push(mv.v);note(w,MODE_E[mv.v],P.modes.length===1?MODE_LABEL[mv.v]:'Mixed in: '+MODE_LABEL[mv.v].toLowerCase(),'mode');} if(!(w==='fly'&&words[i-1]&&/^(a|the|some|lots)$/.test(words[i-1])))continue;} // looks if(NIGHT[w]&&!neg){P.night=true;note(w,'๐ŸŒ™','Night time','look');continue;} const we=find(WEA,w);if(we&&!neg&&!D[w]){P.weather=we.v;note(w,WEA_E[we.v],'Weather: '+we.v,'look');continue;} if(BIG[w]&&!neg){P.size=BIG[w];note(w,'โฌ†๏ธ','Giant hero','look');continue;} if(SMALL[w]&&!neg){P.size=SMALL[w];note(w,'โฌ‡๏ธ','Tiny hero','look');continue;} if(TINT[w]&&!neg){P.tint=TINT[w];note(w,'๐ŸŽจ',cap(w)+' sky','look');continue;} const pw=find(POW,w);if(pw&&!neg&&!P.power){P.power=pw.v;note(w,POW_E[pw.v],'Power: '+POW_N[pw.v],'power');continue;} const lv=find(LVW,w);if(lv&&!neg&&!(w==='little'&&words[i+1]&&D[words[i+1]])){P.level=lv.v;note(w,'๐ŸŽš๏ธ','Level: '+cap(lv.v),'look');continue;} const mu=find(MUSW,w);if(mu&&!neg&&!PL[w]&&!P.music){P.music=mu.v;note(w,'๐ŸŽต','Music: '+cap(mu.v),'look');} // places (a thing after "collect", "dodge" or "save" is a thing, not a place) const thingFirst=(ctxRole==='item'||ctxRole==='haz'||ctxRole==='friend')&&find(D,w); const pl=thingFirst?null:find(PL,w); if(pl&&P.place&&/^(in|on|at|the|into|across|through|around)$/.test(words[i-1]||'')){continue;} if(pl&&!neg&&!P.place){P.place=pl.key;P.placeWord=w;const base=pl.v.x||(ctx&&ctx.worldOf(pl.v.w));note(w,base?base.e:'๐ŸŒ','World: '+(base?base.n:cap(w)),'place');if(!D[pl.key]||pl.key==='candy'||pl.key==='chocolate')continue;} // things const th=find(D,w);if(!th)continue; const it=th.v; if(neg){P.swaps.push('No '+it.w+'s, got it!');continue;} let role; if(ctxRole==='haz')role='haz'; else if(ctxRole==='friend')role=(it.k==='c'||it.k==='v')?'friend':(it.k==='d'?'haz':'item'); else if(ctxRole==='item')role=(it.k==='d')?'haz':'item'; else if(ctxRole==='hero')role='hero'; else role=it.k==='d'?'haz':(it.k==='f'||it.k==='o')?'item':(P.heroE?'friend':'hero'); if(role==='hero'&&P.heroE)role=it.k==='d'?'haz':'friend'; if(role==='hero'&&it.k==='d'){role='haz';} if(role==='hero'){P.heroE=it.e;P.heroN=cap(it.w==='trex'?'T-Rex':it.w);P.heroWord=it.w;P.heroFl=it.fl;P.heroSea=it.sea;P.vehicle=it.k==='v';note(w,it.e,'Hero','hero');if(ctxRole==='hero')ctxRole=null;} else if(role==='item'){if(P.items.indexOf(it.e)<0&&P.items.length<3)P.items.push(it.e);if(lots)P.im=1.6;note(w,it.e,'Treats to collect','item');} else if(role==='haz'){if(!P.haz){P.haz=it.e;P.hazN=cap(it.w);}if(lots)P.hm=1.5;note(w,it.e,'Enemies to dodge','haz');} else if(role==='friend'){if(P.friends.indexOf(it.e)<0&&P.friends.length<3)P.friends.push(it.e);note(w,it.e,'Friends to rescue','friend');} lots=false; } // ideas the engine cannot make become the closest game it can make const low=raw.toLowerCase();let near=null; for(const [re,set,msg] of NEAR)if(re.test(low)){near={set,msg};break;} if(near&&(!P.modes.length||near.set.mode==='dodge')){ const s=near.set; if(s.mode&&(!P.modes.length||s.mode==='dodge')){P.modes=[s.mode].concat(P.modes.filter(m=>m!==s.mode));} if(s.item&&!P.items.length)P.items.push(s.item); if(s.haz&&!P.haz){P.haz=s.haz;P.hazN='Ghost';} if(s.world&&!P.place)P.place=s.world; if(s.power&&!P.power)P.power=s.power;if(s.music&&!P.music)P.music=s.music;if(s.night)P.night=true; P.swaps.push(near.msg); } // the kind of play, when no play word was heard if(!P.modes.length){ let m='platform',why=''; if(P.vehicle&&!P.heroFl&&!P.heroSea){m='race';why=P.heroWord;} else if(P.heroFl){m='fly';why=P.heroWord;} else if(P.heroSea&&P.place!=='ocean'){m='fly';why=P.heroWord;} else if(P.friends.length){m='rescue';why='friends';} else if(P.place==='pirate'||P.place==='island'||P.place==='beach'||P.place==='cave'){m='treasure';why=P.placeWord;} else if(P.place==='space'||P.place==='moon'||P.place==='mars'||P.place==='forest'||P.place==='woods'){m='explore';why=P.placeWord;} else if(P.items.length){m='collect';why='treats';} else if(P.haz){m='dodge';why='enemies';} else if(P.place==='ocean'||P.place==='sea'||P.place==='underwater'){m='fly';why=P.placeWord;} P.modes=[m];P.inferred=true; P.notes.push({w:why||'idea',e:MODE_E[m],what:'Best fit: '+MODE_LABEL[m].toLowerCase(),role:'mode'}); } P.mode=P.modes[0]; P.mix=null; for(const m of P.modes.slice(1))if(MIX_OF[m]&&MIX_OF[m]!==P.mode){P.mix=MIX_OF[m];break;} if(!P.mix&&P.items.length&&P.mode!=='collect'&&P.mode!=='puzzle')P.mix='collect'; if(!P.mix&&P.friends.length&&P.mode!=='rescue'&&P.mode!=='puzzle')P.mix='rescue'; if(P.mix==='collect'&&P.mode==='collect')P.mix=null; if(P.mode==='fly'&&P.modes.indexOf('platform')>0&&!P.power)P.power='jump'; P.found=P.notes.length; if(!P.found&&!P.swaps.length)P.swaps.push('That idea is brand new to me! I made my best guess.'); return P; } /* Make up a customer's request, in words, from the same dictionary */ const REQ_HEROES=['pig','unicorn','dragon','puppy','bunny','penguin','robot','astronaut','mermaid','monkey','elephant','fox','frog','owl','turtle','dino','panda','koala','duck','princess','superhero','ninja','car','rocket','hamster','dolphin','giraffe','sloth','snowman','fairy','bear','octopus','kangaroo','chicken']; const REQ_PLACES=[['on the moon','moon'],['under the sea','underwater'],['in a candy kingdom','candy'],['on a farm','farm'],['in the jungle','jungle'],['at the beach','beach'],['in the desert','desert'],['in a big city','city'],['in a snowy land','snow'],['in outer space','space'],['in a castle','castle'],['in an ice cream factory','icecream'],['on pirate island','pirate'],['in a robot factory','robot'],['in donut world','donut'],['on a rainbow','rainbow'],['in the clouds','sky'],['near a volcano','volcano'],['in a silly spooky house','spookyhouse'],['in a toy shop','toyshop'],['in a crystal cave','cave'],['at school','school'],['in a giant kitchen','kitchen'],['in the forest','forest'],['on Mars','mars']]; const REQ_ITEMS=['pizza','carrot','cookie','donut','star','gem','banana','strawberry','coin','candy','ice cream','cheese','apple','pretzel','shell','acorn','present','heart','balloon','crown','honey','watermelon','popcorn']; const REQ_HAZ=['shark','bee','crab','meteor','rock','ghost','bat','snake','storm','spider','fire','tornado','cactus','slime','wave']; const REQ_FR=['puppy','chick','bunny','hamster','duck','baby turtle','koala','penguin','panda']; const REQ_EXTRA=['at night','in the snow','in the rain','with lots of bubbles','super fast','with a giant hero','with a tiny hero','with sparkles everywhere','with a pink sky','with party music','with calm music','and it is super hard','and it is easy']; const pl=w=>{if(/(sh|ch|x|s)$/.test(w))return w+'es';if(/[^aeiou]y$/.test(w))return w.slice(0,-1)+'ies';if(w==='fish'||w==='sheep')return w;if(w==='mouse')return 'mice';if(w==='ice cream')return 'ice creams';if(w==='popcorn')return 'popcorn';return w+'s';}; function pickOne(a,r){return a[Math.floor(r()*a.length)];} function makeRequest(opts){ const r=(opts&&opts.rand)||Math.random,avoid=(opts&&opts.avoid)||[]; const modes=['race','fly','platform','treasure','explore','collect','dodge','puzzle','rescue'].filter(m=>avoid.indexOf(m)<0); const m=pickOne(modes.length?modes:['collect'],r); let h=pickOne(REQ_HEROES,r);if(m==='race'&&r()<.5)h=pickOne(['car','racecar','truck','tractor','unicorn','dino'],r); const [pp]=pickOne(REQ_PLACES,r),I=pickOne(REQ_ITEMS,r),Z=pickOne(REQ_HAZ,r),F=pickOne(REQ_FR,r); const H=an(h)+' '+h; const S={ race:`a racing game where ${H} drives ${pp}`+(r()<.6?` and grabs ${pl(I)}`:''), fly:`${H} that flies ${pp}`+(r()<.6?` and collects ${pl(I)}`:` and dodges ${pl(Z)}`), platform:`a jumping game with ${H} hopping ${pp}`+(r()<.6?` over ${pl(Z)}`:` and grabbing ${pl(I)}`), treasure:`${H} hunting for treasure ${pp}`+(r()<.5?` and avoiding ${pl(Z)}`:''), explore:`${H} exploring ${pp}`+(r()<.5?` and finding ${pl(I)}`:''), collect:`${H} catching falling ${pl(I)} ${pp}`+(r()<.5?` and dodging ${pl(Z)}`:''), dodge:`${H} dodging ${pl(Z)} ${pp}`+(r()<.5?` and collecting ${pl(I)}`:''), puzzle:`a memory puzzle with ${H} ${pp}`, rescue:`${H} saving lost baby ${pl(F)} ${pp}`+(r()<.4?` and escaping ${pl(Z)}`:'') }[m]; const extra=r()<.45?' '+pickOne(REQ_EXTRA,r):''; const start=pickOne(['I want ','Can you make ','My idea is ','Please make ','I dream of '],r); let s=start+S+extra; s=s.charAt(0).toUpperCase()+s.slice(1)+'!'; return s; } function an(w){return /^[aeiou]/i.test(w)?'an':'a';} function nameFor(P,heroN,worldS,modeId,mix){ const parts=[]; if(heroN)parts.push(heroN.replace(/^Pirate Parrot$/,'Parrot')+'โ€™s'); if(worldS&&worldS!==heroN)parts.push(worldS); parts.push(NAME_MODE[modeId]||'Game'); if(mix==='collect'&&modeId!=='collect')parts.push('& Catch'); else if(mix==='rescue')parts.push('& Rescue'); else if(mix==='treasure')parts.push('of Treasure'); return parts.join(' ').slice(0,34); } window.KidIdea={read,makeRequest,nameFor,MIX_LABEL,WEA_E,dict:D,places:PL}; })();