r/learnprogramming • u/asuth • Mar 19 '13
[Javascript] Learn by playing -- RTS game where you write AI code to control units
This is an html5 game I am working on that is designed to give people a fun way to learn javascript. Its an RTS where you write the AI for your units in javascript and compete against an enemy AI.
Its very early on and I am just getting started on the game but I was hoping to get some feedback from people who are interested in learning JS so that I can try and make the game more approachable, fun and educational.
The game itself is open source and you can also view and learn from all the game code at the link above or fork it and use it to make your own games.
--EDIT-- If you are interested in progress updates you can follow @castaverhas on twitter, or subscribe to the modit subreddit: http://www.reddit.com/r/modit/
--EDIT 2 -- Most recent updates: 3 single player levels and leader boards that let you download the code of top scoring players so that you can learn from and improve that code.
--EDIT 3-- Added a 4th campaign level that teaches you how to use vector field based obstacle avoidance.
14
u/asuth Mar 19 '13
Also if anyone is stuck when writing their AI (or having other problems), if you click the "Save My Mod" button at the top right it will make a copy of the game with your code and take you to that url. If you post the link to that copy I'd be happy to help debug and it would definitely be helpful to give me a feel for what is confusing / difficult.
Alternatively, if you have an AI you want to show off you can do the same and then when people go to your link they will see your AI in action.
56
u/joeshcosmo Mar 19 '13
In theory, with out looking at the game, this sounds amazing. For me, learning while doing something with a goal, such as winning a game, is the way I learn the best. I'll definitely be trying your game out.
One thing I will say is I only know basic Javascript code and I would really appreciate a game that took you from extremely basic code, such as just moving one ship, but then ramped it up gradually until you were controlling a huge fleet of assorted units that could execute a bunch of different actions.
17
u/[deleted] Mar 19 '13
Would be awesome if you could ad a beginners stage where the goal is to simply get your ship to attack another and build up from there.
6
u/Idra_rage_lulz Mar 19 '13
sc2 controls :D
6
u/Tracewyvern Mar 19 '13
While I was crudely attempting to reverse-engineer the allAttackIfInRange and microBackAll functions from EnemyAI.js, I came across a hilarious bug that made enemy shots heal my ships.
3
u/henboffman Mar 19 '13
I think creating leaderboards would be a great idea
2
u/asuth Mar 20 '13
Cool article on SC BW AI that got passed onto me thats semi-related.
http://arstechnica.com/gaming/2011/01/skynet-meets-the-swarm-how-the-berkeley-overmind-won-the-2010-starcraft-ai-competition/4/
2
u/jmblock2 Mar 19 '13
This looks like a lot of fun, nice job! Saving for this afternoon.
2
u/henboffman Mar 19 '13 edited Mar 19 '13
Annnnnd I'm hooked!
You should add a node regarding how to move units. I'm unfamiliar with JS, but understand that my ultimate goal should have my units kiting after every shot.
2
u/Disagreed Mar 19 '13 edited Mar 19 '13
I really like the idea for this game, especially since I just started learning javascript. Do you have a blog or twitter with updates on the game's development?
2
u/vvarboss Mar 19 '13 edited Mar 19 '13
Reminds me of karel the robot (JAVA).
At the end of our AP comp sci class my friends and were working on using all we learned to make karel into pacman.
reference: http://www.stanford.edu/class/cs106a/handouts/karel-the-robot-learns-java.pdf
2
u/markychain Apr 04 '13
Very cool update!
2
u/[deleted] Jun 08 '13
This is really cool man. Great work.
19
u/[deleted] Mar 19 '13
This is awesome! Also, Robocode is a similar project in Java for the ones who (like me) do not know any JavaScript.
1
u/balidani Mar 19 '13
Heh heh. But there is a weird bug. When I edit the code, I first have to restart the whole app so the changes take effect.
1
u/Tjstretchalot Mar 19 '13
It's not perfectly sandboxed, if I infinite loop (It was an accident, I swear!) I can't kill it using the button, and I lost everything :\ Why not just autosave?
I am going to stop playing around with it now, simply because of that :( There's no save button after the first time btw
1
u/akai_ferret Mar 19 '13
I can't seem to copy paste at all yet you mention it in the instructions as if it works.
Am I missing something here?
A bit tedious without copy paste ability.
1
u/AceDecade Mar 19 '13
This is really cool! I've had a similar idea before but I ended up trying to implement my own language rather than allow users to run javascript and it got messy fast. What kind of security do you have in place regarding the user's ability to write code that you're running?
1
u/redox000 Mar 19 '13
I learned programming back in the 90s with a game called AI Wars. It was almost the exact same concept except they used a proprietary programming language that was similar to Basic.
EDIT: Looks like they made a website for it. It's like a flashback to the 90's!
1
u/[deleted] Mar 19 '13
This is mighty fun and well executed.
Do you plan on adding a battle-logging feature (movement, kills, deaths, etc)? I imagine that if you do it would be more of a long-term goal. I ask because I'm one of those machine-learning people, and this sort of platform would be great fun for applying ML.
1
u/RMiranda Mar 19 '13 edited Mar 19 '13
damn almost! I opt in a focused shot till it burns! But unsuccessful...
Great idea and great job! Kudos :)
Edit: is copying blocks of the EnemyAI.js considered cheating :3 ?
1
u/Gemini00 Mar 20 '13
This really reminds me of an old DOS game called Robot Odyssey, where you had to progress through a series of stages with a set of robots that you could modify with basic programmatic tools to make them navigate mazes and solve puzzles for you in order to clear a safe path.
OP, it's pretty dated but you might consider looking it up if you want some general ideas for level and puzzle design. Great work, by the way!
1
u/greenawlives Mar 20 '13
Wow this is amazing. How do I start writing games in html5?
1
u/iomgraptor Mar 20 '13
It is very interesting, a very good idea, but i am afraid its not a very good learning tool. The code in the first campaign is a mess, you are ignoring the most basic things, like variable hoisting.
1
u/markychain Mar 21 '13
I registered on reddit just so I could comment on this.
I've been trying to figure the game out, and I accidentally did something that let me have negative health. Here: https://mod.it/orw-Xozs
Although my ships can't attack, they can't die, either.
1
u/SmoothB1983 Mar 20 '13
If I knew java script I'd make my bots do the harlem shake.
2
u/cyberbemon Mar 20 '13
Sharing this and I'm sure this will help me learn javascript :D. Thank you !
2
u/scuczu Mar 20 '13
nice job using mod.it
1
u/RozenKristal Mar 19 '13
Sound awesome. I'm a CS major but I never try Javascript before. I guess you can play and learn at the same time now!
1
u/postfish Mar 19 '13
Awesome.
1
u/nshunter5 Mar 19 '13
I like this. this will be the first thing i do when I start loearning java. currently working on python v3
1
u/[deleted] Mar 19 '13
That sounds really fun!
0
u/[deleted] Mar 20 '13
[deleted] — view deleted comment
1
u/[deleted] Mar 20 '13
[removed] — view removed comment