Because somehow millions of enthousiast users aren’t pooring in since the game started functioning properly (i.e. a week ago), I decided to write a bot mechanism. So as of this afternoon, when creating a game, you can now throw in some artificial intelligence players!
Well, ‘intelligence’ is overstating it really. Bots just dabble around the map randomly, completely oblivious of any enemies or mines near them. They also cannot purchase are construct anything. But hey, they work, they make for very loyal beta testers, and I will definitely improve their behavior in the future (including an option to specify their difficulty level). The current algorithm for deciding their actions is ‘move towards the map center at random speed’.
There’s also a tiny issue that I want to correct ASAP: it looks like bots move right away, because they get the blinking ‘moved’ next to their name the very first time the round loads the player states. While this is convenient (you never have to wait a bot for round advance) it is also confusing. Because in fact, the bots’ moves are stored as taking 5 seconds, and evaluated as such. So no worries, you can kill those bot’s units. It is also quite entertaining to watch them kill each other.
I just won my first game, too, yay!
As a reminder to myself: here are some JS/PHP thingies I ran into while developing Dice Attack that may be worth writing about. Given the amount of stuff I learn through blog posts by people who encountered my same problem and solved it for me, I think it is only fair to return the favor. Some interesting tidbits I ran into that might be interesting for others are:
- Getting a page to remember a draggable’s position (so the chatbox doesn’t forget where you put it when the round advances)
- Getting a page to remember what you were typing in a form (so the chatbox remembers what you were typing)
- Giving a text field focus on page load, and putting the cursor at the end of its content rather than selecting it (chatbox, again)
- Writing a rudimentary PHP debugger that really ‘tells the story’ of how your page is made
- Writing the simplest possible PHP forum (this one’s old)
- Writing a rudimentary AJAX chat (including private chat)
- Using AJAX to detect who is still on the same page with you and who left
- Injecting an animated GIF at a precise location and then removing it again to simulate explosions (also used this for ‘attack’ and ‘range’ circles)
- Dynamically generating images with PHP (handy to generate those 16 possible tile states when inventing a new unit)
- Timing how long it took a user to do something after entering the page
- …
Boy did I run into many tidbits
Stay tuned!