Short video of the AI in-game. They just run around throwing down walls. After a few bugs pertaining to walking through walls are fixed, and after the wondrous lag compensated combat is restored (+zombies), this might actually be a bit of a game.
A few workers gather more wood for their houses while glitchily hovering over trees.
These little AIs I’ve been tinkering with are finally living on the actual “mmo server” from previous blog posts. They spend their days collecting resources and starting [construction] projects that they can’t finish — so naturally, I find them quite relate-able.
It was certainly nice to be able to connect a few more of these prototypes together, and it has caused me to reflect on the various projects that have been combined to produce the glitchy screen shot above.
The worker AI has gotten subtly more sophisticated. Ultimately they still cut down trees and build houses, but now they are a lot less robotic and a lot more resilient to things going wrong.
Some of their new behaviors:
When a worker is standing in the way of construction project, she becomes the subject of a quick little evaluation. If she is progressing on a project herself then she may remain there blocking someone else’s work. This relies on the assumption that she has valid work and will probably wander off after it is done. There’s also the capacity for workers to shoo each other away briefly so they can install a floor or whatever needs done.
Per the above, no one gets built into the wall anymore, which solves a whole series of bugs that came from reserving work and not being able to get to it.
Whenever anyone gets interrupted while working, whatever they were doing (cutting a tree, building something, etc) becomes available again, and the next idle worker can finish their project.
There’s a concept of idleness now. Idleness occurs after any project has been finished, and is followed by a simple set of decisions about what to do next. So far this is relegated to staying idle, building, or cutting down a tree… but in the future this will be the root of other behaviors.
Pathing has been reworked so that the workers always approach things in a natural (aka lazy) way and never run around to the far side of an object unless that really was the only way to get there.
Houses are no longer built in stages of floors, walls, roofs, etc. each which has to be finished before the next stage can be built. Walls are now considered more important than anything else, but workers are allowed to start on the floors if all the wall jobs have already been assigned.
This is as far as I plan to go with the building AI for now. After the zombie AI (mindless wandering, fighting, and fleeing for the workers) the next focus is going to be getting everything back in-engine.
There’s a vague village planner AI which periodically decides to build more houses. This ai knows where the village center is, and enforces a certain minimum space around any house plans that get started. In the next evolution this AI will assign house ownership, which will provide a new type of idle behavior: going home.
There are now zombies, and they do nothing but wander mindlessly. The workers run from the zombies (that’s what the picture is, zombies in black and workers in red) but they can’t get hurt yet.
I’ve also started to merge this little ai proof of concept w/ the mmo server prototype, so hopefully the character generator and ai will soon make use of one another… which reminds me I have four zombie skins but no actual zombie generator yet!
Note: this is for framerates (server ticks) in node.js. If you want nice framerates in a browser use requestAnimationFrame as the looping mechanism that calls draw or update.
Short video showing the current state of the lumberjack/carpenter AI. You’ll just have to picture the house from a few blog posts ago superimposed on these squares.
While not too different from previous demos, this time the workers exist on the same map/engine-ish-thingy that was used in the mmo prototype. So while I call it a prototype in the video, really that’s not what I mean.. it is part of the actual game now. The workers have also gotten quite a bit more clever about finding trees and not building walls on each other.
After the housing artwork (and recently streamed tile code stuff) get added to the game client and server, I should be able to produce an in-game video of the AI at work. I’m missing axes and a lumberjacking animation, but having the procedurally generated characters walk up to trees and assemble a house will probably still capture a good amount of the overall vibe.
Before I consider the game playable (as even an alpha) the workers will have to be able to run from a zombie and still get back to their lives after danger has passed. Basic player vs npc combat (melee only) is already working. There is still quite a bit to work on before the slimly-featured “one night prototype” will be done.
Working demo and code: Twitch.tv online stream source code and demo . I highly suggest copying and pasting code from this demo rather than directly from this blog post. You can edit the twitchName and hit the ‘run’ button to confirm that it all works for your stream before attempting to put a little widget on your site.
How to add the widget to a site
All of the code is in the following link: twitch widget gist. You’ll want to paste all of the code from “head code”into the <head> tag of your page.
Next post the single line from “body code” where you’d like the widget to appear.
How to add the widget specifically to a Tumblr blog
There have been a few extra challenges on Tumblr. One issue is that copying and pasting the code out of a blog post can corrupt it. I’ve put all of the code in a gist to circumvent this issue. Another issue is that some blog themes allow HTML in their description, while others don’t. To solve this, all code will be added directly via the Tumblr HTML Editor.
I tried out a few themes, and here is the most consistent way I found to display the widget.
Copy and paste code from here as you go: twitch.tv stream widget
- Goto Customize > Edit HTML to use Tumblr’s built in HTML editor
- Find the <head> tag, it should be near the top of the HTML
- Scroll down to the end of all the <meta …stuff…./> tags
- Paste all of the code from the “head code” gist
Place widget on the page somewhere in <body>
Scroll super far down until you find the <body> tag. Somewhere after the <body>, paste the one line from “body code.” There is a lot of variety in the HTML of any given theme at this point, I recommend looking for the code that displays your blog’s description and pasting our line within or after that. On most themes you can also add a <center></center> tag and put the widget inside of that.
When you’re all done don’t forget to change your twitchName near the top of the code itself.
A quick test
- While not streaming, refresh your page and confirm that it says OFFLINE
- Begin streaming on Twitch.tv
- Wait a moment (it is not instantaneous)
- Refresh your page and confirm it says ONLINE
Misc technical notes:
Many (all?) tumblr themes already include jquery, pasting the above code will include jquery twice. If you’re savvy, remove one of the jquery links.
Does not consume an API key. Might be a hack, I honestly don’t know. The technical documentation was of such a quality that I could sooner make something up (and did) than discern the approved method.
Not blocked by same origin policy / cross-site request security because of JSONP
If your site has a lot of traffic (mine doesn’t) it would be polite to cache your online status rather than run this script every request.
Problems/bugs? Comment or contact me
Here’s an example of one of the houses that the AI from this demo will build.
I still have a fair bit of art changes to make, especially on the roof, but this is the general way that the tiles will fit together. From here it will be easy to add a variety of different building materials and aesthetic themes for buildings.
A house like this (possibly a log cabin variant) will be built in tandem by the player(s) and one NPC at the start of the game.
Today’s stream itinerary:
- find the conditions that cause npcs to get stuck
- redo pathing if a wall is built in the middle of a path
- stop carpenters from building on top of each other
- if time allows, introduce a hostile npc to chase away the workers
I’ll try and uhm… save the stream this time! But if it ends up as 4 hours of I-Can’t-Find-The-Bug (likely) I may delete it ;)
Fixed: there is a widget now at the top of this blog which says if I have a stream currently going or not.
I’m going to try streaming some AI game dev stuff on twitch.tv. I haven’t tried developing like this, it might be REALLY BORING.
The link is: http://www.twitch.tv/timetocode
I’m a newbie to twitch, so if someone feels like stopping by and explaining how to customize a channel a bit, that’d be nice.
I’ll delete or edit this post when done streaming.
And there was broken pathfinding, lots of it. Goodtimes.