togfoxy / Mars-Lander-reboot

A re-creation of the 1979 Atari classic Lunar Lander with new game play.
MIT License
1 stars 0 forks source link

Build a bot for single players to race against #9

Closed togfoxy closed 2 years ago

DocMcSnappen commented 2 years ago

That's an interesting problem to solve. :)

What's the goal of the race? Money? Distance? Something else? Some guidelines would be helpful in designing a bot/AI for this.

Also, does the cash bonus only work for the first player to arrive at the station, or does apply once per player? Does a bot count as a player? Can bots buy upgrades?

togfoxy commented 2 years ago

I'm thinking multiple game modes can be supported through the options menu but the default mode is 'I got further than you'. I only say this because I don't have a better idea! A race mode might be better - reach a certain distance first. That would require far more strategic flying.

Was thinking the cash is not for the first person. Everyone has their own instance of cash and fuel.

Bots would need to buy upgrades to remain competitive.

Thoughts?

DocMcSnappen commented 2 years ago

Sounds good! It's not a bad idea to have different modes, difficulties, AI types, etc. I see from your repos you've even done some AI stuff before! The most advanced AI stuff I've done is an A* pathfinding implementation, so you may have a leg up on me there. We'll see who gets to this first, lol.

And here's a though I had while typing this - what about the possibility of multiple AI competitors? I like the idea, but how do you position them at the start? This is a game where distance matters and you don't want to crash into each other. Is that idea even feasible?

I haven't tried the multiplayer aspect yet. Is that working? How did you (plan to?) overcome the starting issue?

togfoxy commented 2 years ago

Bare with me while I use a lot of words.

You'll find a branch called Artificial Intelligence. This is actual machine learning with 'agents' that learn by themselves. I believe that branch actually works and if you run it long enough (a week) then you'll find the agent will get better and fly by itself. It's not very good - but it works. You can even let it run while you have dinner and find moderate learning. I intend to return to that branch one day and rewrite it.

I've been using LOVE and LOVE games to learn and experiment with true machine learning. I've done Q-Tables, genetic learning algorithms and neural networks. Some were more successful than others but it's pretty cool to say I've done machine-learning in LOVE. :) A* is a path-finding routine (I've done that too) and really fun when you get it right.

So, being a little pedantic, this ticket was not about machine learning but rather a 'programmed' bot that runs on a script. Also a challenge in it's own right and frankly, possibly a pre-cursor to an effective machine learning algorithm. This ticket is about understanding the math and motions a bot would need to execute to get from one base to the next in a believable (but scripted) way without plotting every single action. It would be a tangle of if/then statements. FUN! :)

Let me know if one or both of those subjects are of interest to you and I can point you to some material to ease you into it. I'm fascinated by both subjects and a fledgling on that journey of knowledge. Q-learning is the easiest to understand. Don't let the math put you off. I don't understand any math and it I still achieve machine learning by ignoring the formula's: https://en.wikipedia.org/wiki/Q-learning

Back to the question: multiple bots. Yes. I think it would be fun to have like 8 bots zipping about the place doing their thing. Some will be good and some will be bad and some might do hilarious things just because they are bots and bots do dumb things. There would be no collision at the start. Bots would pass through each other. That is easy and the logical place to start. Collision detection is not impossible but next level stuff and can come after.

If the game is a 'distance' thing then they don't need to all start at the same time. Everyone (including bots) plays their session and when they run out of fuel they restart and try again. There is no interaction with bots and players but you will see each other buzz around and names can appear on the high-score board as a gauge of your success.

The game already supports this in co-op mode. You can play on a LAN or open two sessions on the same computer. One is host and one is client. You can switch windows and see them fly past each other. When a lander runs out of fuel you can press ENTER and try to beat your score. The host can reset everyone by pressing R. Hopefully this is in the players wiki (maybe not).

I've been desperately trying to get this to work on internet. I don't know if there is a porting problem or firewall problem or bugging code and I'm close to out of options to make this work on the internet.

Now, if we race, which is more interesting, we would need to 'sync' the host/clients. Perhaps that R feature is already need and already in place.

Lots of words. Let me know if any of that has intrigued you.

DocMcSnappen commented 2 years ago

Oh, lots of things interest me here. I may have some time next week to dig into sound effects, bots, and/or internet play.

I expect sound effects will be easy enough to learn - it's just a matter of looking at the wiki and the current code.

I agree with you that bots should be relatively simple algorithms that dictate commands to their respective landers. And going to maximum distance would be the logical starting place. Side thought: It may also be fun to incorporate collision detection, and then add purchasable armor, magnetic shields, etc and maybe even create a "kamikaze" bot. Perhaps players & bots can respawn after crashing, but with a penalty applied to the current goal (ie. subtract x distance per crash, or something like that).

The internet play issue is curious to me. You can operate correctly over a LAN, but not the WAN? Very possibly a router or port issue. Also possibly related to IP translation, unless you've got a static IP (unlikely). I'm willing to try to help here, but I don't have regular development time, so trying to schedule anything with me will be difficult.

togfoxy commented 2 years ago

I think collision detection would be fun and a great way to move this game to a "party" type game where a bunch of mates goof around smashing into each other on Mars whilst chugging a beer or two. :) Well - that's my vision of a good time anyway!! I'll add an issue so those ideas don't get lost.

I suspect the code is fine and there is something dumb with my router/ports/firewall but these things can be notorious to debug and fault find. When I get someone in my time zone to help I'll start with a simple ping via OS (MS Windows) and work up.

Glad some of that is of interest to you. I'm thinking eventually - long time away - I'll build in multiple AI algorithms that can be toggled in the settings menu. You'll be able to fly against a machine learning algorithm and watch it learn to beat you. :)

togfoxy commented 2 years ago

@DocMcSnappen

Check the AI branch in this repo - it has code that literally flies the lander. You don't do anything except watch it fly itself and marvel at the wonder. :)

I'll make it production-worthy by making it a bot you can fly with/against and then merge it into the main branch. Pinging you as you showed an interest. This is a little math heavy but not beyond you. I'm happy to break it down if you're keen. I'll also add I've tried to do something like this about 100 times and failed. Persistence pays off!

In the future, I'll do a variant that is true AI, meaning it will be machine learning and not scripted. Obviously next level hardness. Merry XMAS!

DocMcSnappen commented 2 years ago

Thanks for letting me know! IRL has been very full lately, and I won't be doing any fun coding before next week, but I'll check it out soon. And I'm not intimidated by math in general - I've got an undergrad degree in it and generally know how things work. ;)

On Thu, Dec 23, 2021, 8:31 AM Fox @.***> wrote:

@DocMcSnappen https://github.com/DocMcSnappen

Check the AI branch in this repo - it has code that literally flies the lander. You don't do anything except watch it fly itself and marvel at the wonder. :)

I'll make it production-worthy by making it a bot you can fly with/against and then merge it into the main branch. Pinging you as you showed an interest. This is a little math heavy but not beyond you. I'm happy to break it down if you're keen. I'll also add I've tried to do something like this about 100 times and failed. Persistence pays off!

In the future, I'll do a variant that is true AI, meaning it will be machine learning and not scripted. Obviously next level hardness. Merry XMAS!

— Reply to this email directly, view it on GitHub https://github.com/togfoxy/Mars-Lander-reboot/issues/9#issuecomment-1000307540, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASCIS7CMFFSMJMJHUZMYSQDUSMQD5ANCNFSM5IO2IBVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

togfoxy commented 2 years ago

The branch is progressing and in doing so, I've broken the AI and the game!!

This is the commit that works. Use this for academic purposes: https://github.com/togfoxy/Mars-Lander-reboot/tree/ab01292b1af40d5139846278102e0d4f1d3198ff

Preserving this link for future use.

togfoxy commented 2 years ago

Now working so merged into main branch. The bot is not very optimised but will close this ticket and add a new one.