I really like CivWorld and here is my proof!
The CivWorld gameplay has one really amusing/annoying feature, the bonus resource bubbles. If you hover the mouse over one of these bubbles you will get some extra resources as a bonus. If found that those extra bonuses can be really helpful, at least during the early eras! And you can also win on of the contests by grabbing those. I believe most player find those annoying, but I really like these bonuses as a way to thank dedicated players!
I really need this extra edge that the bonus can supply! I might be the god of all CivWorld players, but my friends ain't. Thats why I ain't winning, right? So I cheat – I'm developed Grorld.
Grorld is a software that automatically finds bonus bubbles and hover the mouse over those, even while your at sleep.
This is a blog about coding (and gaming), so I'm going to tell you how I created it! Enjoy the lesson!
Warning:
This application only works on recent linux system (like Ubuntu 11.4). Windows user can preferable stop reading right now, because there will never ever be a port (or maybe a bribe could change me...)!
I realized that I needed three component to achieve my goal to automatically grind the bonus resources.
1) A screen scraper/reader/grabber to be able to 'see' the game board inside my application.
2) A 'tool' to identify bonus bubbles on the game board.
3) A mouse simulating component to automatically perform the hovering.
The mouse moving was the simplest, so let's start with that one. The Xlib library supplies a protocol to communicate with the X server. It really helped me with ALL the dirty work. For example: The Xlib API have the XWarpPointer() function to move the mouse pointer a distance relative current pointer position. However, as I need to set the mouse position to an absolute point I to retrieve the current position, via XQueryPointer() , calculated the deltas and set those with XWarpPointer().
Fully working C code:
The screen grabber component was almost as simple. But as the Xlib function XGetScreen() is way to slow I had to go and look for alternatives. Fortunately the MIT-SHM extension allows both client (my app) and the server (X) to share memory. Hence you can skip all huge image buffer copying that XGetScreen() is using. This XShmGetScreen() tutorial saved my day.
The tool to identify bonus bubble is the most interesting. I decided to use a so called template matching technique. I've used the OpenCV library before and I like it. Quickly I converted the Xlib pixmap into a OpenCV cv::Mat structure. This image was used as the so called search image. Then I loaded a home made image looking like the bonus bubbles as the so called template image. Thereafter I justed performed a cv::matchTemplate() on the search image. The result is a vector with scores. The item in the vector with the lowest score represent the pixel on the search image that has the highest probability to contain the template image, it can be retrieved with cv::minMaxLoc(). Afterwards I calculated a relative score with help of standard deviation. Fortunately the OpenCV library have helper function for that as well, cv::meanStdDev(). If the score is 3 sigma or above, we have a 99.7% probability that we have a correct hit. And in that case, I simply hover the mouse over that area...
Problem solved! And thanks for all the fish!
Please go and download it and tell me how it's working...
July 18, 2011
July 14, 2011
CivWorld rambling
I started to play the CivWorld beta on facebook the other day. I'm already enjoying it way to much! But first we have to go back to when it all begun.
Sid Meier has been a favorite of mine since long. I played Civilization for hours with my friends. We used to go home and play the game together, ain't several minds better than one? This co-operative way of playing a single player game really hooked me. Since that time I been admiring all Sid's work. I've had my ups (CivII, CivRev) and downs (CivIV) due to natural periods in life. Like spending to much time making my own games or producing small children. But I been faithful and played them all.
CivWorld is the latest installment. It's a so called facebook game. It's still in beta, but I'm already impressed! It has a few flaws, mostly due to the flashplayer that are required! The framerate sucks on my system and the game might not be the deepest in the series. But overall the game is brilliant, because the game requires you to team up with friend/other players to win. It's like a big co-operative Civilization MMO.
Did I mention that it's brilliant? It really is! This co-operation really reminds me of how I played Civilization with my friends back in the days... we now sit in our own houses by ourselfs but we're melting our brains just like we did in the good old days.
Plus:
- Gameplay
- Co-operation
- I've almost won my first game
Minus:
- Flashplayer is required! (HTML5 anyone?)
Sid Meier has been a favorite of mine since long. I played Civilization for hours with my friends. We used to go home and play the game together, ain't several minds better than one? This co-operative way of playing a single player game really hooked me. Since that time I been admiring all Sid's work. I've had my ups (CivII, CivRev) and downs (CivIV) due to natural periods in life. Like spending to much time making my own games or producing small children. But I been faithful and played them all.
CivWorld is the latest installment. It's a so called facebook game. It's still in beta, but I'm already impressed! It has a few flaws, mostly due to the flashplayer that are required! The framerate sucks on my system and the game might not be the deepest in the series. But overall the game is brilliant, because the game requires you to team up with friend/other players to win. It's like a big co-operative Civilization MMO.
Did I mention that it's brilliant? It really is! This co-operation really reminds me of how I played Civilization with my friends back in the days... we now sit in our own houses by ourselfs but we're melting our brains just like we did in the good old days.
Plus:
- Gameplay
- Co-operation
- I've almost won my first game
Minus:
- Flashplayer is required! (HTML5 anyone?)
May 29, 2011
Du får all min kärlek #9
Spenderade dagen på
fotbollscup med dottern och resterande del av familjen. Vädret var
ganska hyfsat, sol till och från. Men denna historia handlar
egentligen inte om fotboll. För tycker du som jag att damfotboll är rätt trist? Du vet, forwards som inte ens med all kraft orkar lyfta
bollen över ribban eller målvakter som inte ens når ända upp till
ribban när de hoppar. Ja, då är det en pina att se 7-8 åriga
flickor ge sig an det ädla spelet.
Men idag, I tredje
matchens halvlek, hände något intressant! Den nu snart 5-årige
lillebrodern fick sitta med i en liten ring bestående av några
'hemma'-spelare. För första gången någonsin kunde ungen sitta
tyst och stilla mer än 3 minuter! Det hade hänt något, vid den
tidpunkten förstod jag dock inte riktigt vad. Men mysteriet skulle
komma att klarna.
Andra halvlek började.
Lillebror, som är ganska hetlevrad, skriker svordomar och könsord
vid första målchansen och allt känns som vanligt igen. Vid andra
målchansen utspelar sig följande konversation;
- Gör mål då nummer nio, skriker lillgrabben.
- Skjut, skriker jag.
- Gör mål då nummer nio, skriker lillgrabben.
- Skjut, skriker jag.
- Gör mål då nummer nio, skriker lillgrabben återigen.
- Vem är nummer nio, är hon ens på plan?, frågar min sambo och modern till barnen.
Jag scannar av hela planen
efter den beryktade spelaren. Jag finner henne bland de andra
avbytarna, sittande i en ring. Platsen jämte henne var tom!
Målchansen klingar av, föräldrarna suckar och blir tysta. Då,
helt till de andra föräldrarnas stora nöje, ställer sig min son
på den medhavda gröna stolen och skriker högt;
- Gör mål då nummer nio, DU FÅR ALL MIN KÄRLEK #9!
Så gick det alltså till
när grabben gick och kärade ner sig första gången! Jag hoppas det
händer fler gånger, eftersom #9 var bortglömd redan vid
kvällsmaten.
February 13, 2011
Lost Odyssey - please think twice...
This
blog entry is dedicated one
game, a Japanese game to be specific. I've always loved JRPG's
, so when Lost
Odyssey was announced I was thrilled. As a Xbox gamer I
never had any chance to play the legendary FF games (darn
you Sony)... But here it was, a Mistwalker
developed game for the Xbox 360!

Is it good?
Yaah, it's OK. It's not like it's over
9000 or anything, but its quite entertaining.
Now I probably got you to think twice.
Why the hell do I write a complete blog entry about a descent game?
It's because NO ONE at Mistwalker did what you just did: THINK!

Me mad!
You play as the immortal
hero Kaim who have forgot his past. The main objective game is to
defeat the magical industrial revolution.
While playing the game you experience
visions/dreams from the past. And I really mean from the past. Your
an immortal, you have lived thousand (1.000) years. I promise you, if
you live a thousand years, you have experienced things really worth
dreaming about!
I played this game for a week... until
I suddenly dropped the game. I didn't touch the game for 9 months to
come. Even minesweeper
felt fresh in comparison to the feeling I got from this game.
Here's what happened:

I'm supposed to be IMMORTAL. WTF am
I doing dead on the floor?!?!
Okay, I finally swallowed my pride and
finished the game. But I have never forgiven Mistwalker for the not
so enjoyable experience of becoming a dead immortal!!!
February 9, 2011
XOR(42) cipher
I'm currently reading the book Cryptanalytic Attacks on RSA by Song Y. Yan for a project I'm currently working on. However, I have to admit, I'm having a hard time with some of the math in that book. For me, this isn't trivial... but at least I'm having a really good time potter with prime conjecture's, Mersenne primes etc.
While reading this book my mind wandered off and I started to think about how we did it back in the days. I shared my first computer with my older brother. Hence I had to protect my private data. My private data mostly contained gif pictures of women in bathing suits. Illegally downloaded from bulletin boards in countries far far away, but that is another story...
After reading the Peter Norton's Assembly Language Book for the IBM PC I was ready. I started to encrypt my files with the famous XOR42 algorithm.
The basic idea behind the algorithm:
Like trivial letter ciphers, the ROT13 for example, the idea is that you encrypt & decrypt with the same algorithm. In ROT13 you replace the letter 'A' with the letter 13 places later, the 'N'. And now to the magic! If you once again replace the letter 'N' with a letter 13 places later (using wrap-around) you will 'magically' get the 'A' letter. You successfully decrypted the data, by encrypting it again.
On binary blobs, like my images, you instead use the exclusive disjunction (XOR). It actually has the same effect on each bit, that ROT13 has on each letter.
Encryption;
A B --- A XOR B0 0 ----- 00 1 ----- 11 0 ----- 11 1 ----- 0
A is my data and B is my key. If I once again use the key B on the now encrypted data, ta-da, each bit will have it's original value again.
Decryption;
AB --- A XOR B0 0 ----- 011 -----01 0 -----101 -----1
This is best performed on complete bytes (8bits). And the most commonly used key is of-course 00101010b (42).
The letter 'A' is represented as the number 01000001b (65) in the ASCII table.
Encryption;
01000001b XOR 00101010b = 01101011b (encrypted to ASCII character 'j')Decryption;
01101011b XOR 00101010b = 01000001b (decrypted back to ASCII character 'A')Code examples:
It is trivial to implement such algorithm in C-code, this is one example how this task can be achieved:
It may originally be consider as a joke but the GNU C library authors gave us memfrob. The library function XOR bytes in a very efficient manner (they actually call it frobnicates). Simple usage would look like;
XOR42 should not be consider to be a real encryption. There exists reasons why everyone, including me, is using openssl for encoding. However, I believe the following modern encryption example is way to simple and boring;
And NO, my brother never succeeded to decipher any of my private data...
Subscribe to:
Posts (Atom)