A fun online game that I’ve been playing, lately, is llor.nu (unroll, backwards). It’s written using Ruby on Rails, has lots of nice Javscript/AJAXy things, and is Open Source.
The game, in and of itself, is rather simple – you roll the dice, collect money, pay rent, build buildings, and get more money. Which can be rather tedious – however, being a programmer, I saw an opprotunity to automate a bunch of the tedium and maximize my profits – and according to the discussion boards, I’m not alone. Recently, the game had an overhaul changing much of the dynamics, and much of my code. One of the things on the developer’s ‘to-do’ list is to implement a public API, but until then, I’ve pulled together a number of commands (e.g. REST-like URL and parameter combos) that can get the job done. So, if you’re interested in writing your own bot, it’s definitely a good place to start.
Logging In
POST /login
user[login]=USERNAME&user[password]=PASSWORD
This is the essential first step of any bot – logging in to your account. The username and password are the ones that you signed up with originally.
Rolling The Dice
GET /js/take_turn/
The most simple of bots can do nothing but login and then roll the dice to kingdom come – under the current version of the game, it is very likely that you will become quite rich.
Buying A Building
GET /deeds/buy/NUM?levels=LEVELS
The next step, is to generate some form of perpetual income (from other hapless players, rolling their dice) – this can be done by buying an available plot and hoping that it’ll be landed on. However, you must first know if you’ve landed on a plot that can be purchased – the easiest way to do this is to take the output from ‘Rolling The Dice’ and to check and see if it contains the text “buy and build”. Some psuedo code:
login(); while( 1 ) { data = GET('http://llor.nu/js/take_turn/'); if ( data.contains( 'buy and build' ) ) { GET('http://llor.nu/deeds/buy/2?levels=1'); } }
The next important step is to determine what type of building and how many levels to buy – There are four types of buildings numbered 2 (lowest worth), 3, 4, 5 (highest) – and multiple levels (1 to 30ish). You’ll probably want to focus on buying on particular type of building, exclusively – it’ll make your code, and management, much simpler.
That should be sufficient to get you started hacking around – just make sure that you don’t call their poor server too frequently – leave a couple second delay it, to be nice. (Otherwise there may not be any more game to mess with.) If there’s interest, I’ll be happy to delve into the following:
- Using ducks, Figuring out when to use a duck
- Using hard hats, Figuring out when to use a hard hat
- Figuring out how much money you have
- Renaming Buildings
- Upgrading Buildings
- and Selling Buildings
At the very least, be sure to check out the game, it’s very slick, to say the least (and look for me up on the high score board!).
Update: The ‘can I buy’ text has been changed to ‘buy and build’ (to work with today’s update).
chip (December 16, 2005 at 12:58 am)
Here’s the output fom my bot:
Rolling 45/100…
Next rents : [40, 80, 0, 0, 10, 0]
You paid in rent.
Cash: 0.
Bank: 1752988.
Ducks: 27.
Hats: 88.
Roll took 0:07 seconds
chip (December 16, 2005 at 1:46 am)
And here’s how I typicaly use it:
> a.roll until (a.bank > 5000 or a.bank 200)
John Resig (December 16, 2005 at 2:09 am)
chip: huh, that’s really cool – much more refined then mine. I usually just tweak the numbers straight in my code, rather then using a proper console.
Do you use strategy when looking at the upcoming rents? Before the 280 build I would look to see if there was a rent greater then 100 in the next 6 spaces, then apply a duck. Although, I don’t even bother using ducks anymore, not even worth the bandwidth.
chip (December 16, 2005 at 3:54 am)
I run it in irb.
And you site stripped some less than signs out of my posts, which is why they look wrong.
sean graham (December 16, 2005 at 3:22 pm)
World:
Please stop using the terms “AJAXy” and “* Goodness”.
Thanks,
sean
John Resig (December 16, 2005 at 4:38 pm)
sean Yeah, I don’t like it either… but, unfortunately, doing DHTML these days and not using the word ‘AJAX’ will only lead to the confusion of the poor ‘Web 2.0’ simpletons.
borat_keeper (December 18, 2005 at 8:18 am)
I would like you to delve into those other areas! I already have a bot, but I havn’t worked out how to check balance, and since the Trac for llor is down again I can’t look at that.
sean graham (December 20, 2005 at 10:43 am)
Actually, I am fine with the term AJAX, even if people don’t know what the hell it means… It’s things like AJAX-y and “AJAX-y goodness” that drive me crazy… ;)
Michael Buffington (December 23, 2005 at 11:53 pm)
Hi.
The official Trac server is down right now, but http://dev.llor.nu:3000/trac/llor works.
Also, while I hate to see a good project like yours become obsolete, running bots in llor.nu will soon be pretty unproductive. I’m not going to block bots by any means – the game will simply require input that only humans can give. A sort of pseudo captchka that is relevant to the game is in the works.
What I am totally into is the idea of players ditching my Ajaxy (ahem) interface for their own, text based, Excel based, fruit based interfaces. I think your work on the bot can eventually transition into your own command line interface to the game. Not that I don’t like my interface, but I like openness more.
Michael Buffington (December 23, 2005 at 11:54 pm)
Sorry, make that http://dev.llor.nu:3000/trac/
Jim (January 3, 2006 at 12:56 pm)
Hello,
2 questions:
1. Do you still bother to roll?
2. What are you using to fetch url’s?
I tried ruby’s net/http and http-access2 but neither work well. I resorted to an external perl script. I know I could have used curl or wget, but I experimented and the perl one was the quickest.
Amos (June 20, 2006 at 11:07 pm)
I cannot download the source code by the svn link posted in rails wiki, do you have the valid link or tar.gz/zip file?
Amos (June 20, 2006 at 11:12 pm)
To Michael Buffington
Those two you provide above also don’t work.
:-(
Any ideas?
Thanks a lot!