Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cheater's Math

Cheater's Math

A talk about how I used PHP and various techniques to build a coaching app to beat various word games. Presented at the Dutch PHP Conference 2013.

Ivo Jansch

June 07, 2013
Tweet

More Decks by Ivo Jansch

Other Decks in Technology

Transcript

  1. About Me @ijansch Entreprenerd Mobile & Web Developer Author &

    Speaker Talk feedback: http://joind.in/8446 2
  2. Beating Letterpress ‣What do we need: • Analyze screen (dimensions,

    location of the board) • OCR • Color matching • Word matching • Word scoring • Game strategy 5
  3. The Problem ‣T=0: Letterpress came out ‣T=5: Idea for coaching

    app • No cheat apps available ‣T=10: GameCoach for Letterpress ready • 1 other cheat app available ‣T=17: Apple approved GameCoach • 23 other cheat apps available :-( • By now there are over 40 12
  4. GameCoach for Letterpress retrospective ‣ Few downloads per day, even

    fewer buys • Letterpress themes weren’t supported • Buggy OCR • Average: $ 0.18 / day • Did we care? No, we had fun! ‣ To make $$$ with apps like this, we need to: • Reduce the amount of code we need to write • Support more & other games • Release quickly • So abstract and generalize the hell out of the time consuming parts! 13
  5. Generalizing a data model 15 Game Variant Theme Theme Tags

    TileTell #dd0000=theirs #ff0000=theirs,locked #0000dd=mine #000000=char Theme Tell name=letterpress board=5x5 ipad iphone 10,10=theirs,mine,locked tolerance=3 240,50 400,50 Classic Disco
  6. Recursive dimension parsing board width = screen width board height

    = screen width (square board) board x = 0 board y = screen height - board height 16
  7. Poor Man’s OCR ‣Pixel method worked, but hard to do

    ‣What if we train a parser using existing screenshots? 17
  8. Finally, combine matrixes into OCR tree Creating the tree is

    remarkably simple: findTellPixel: find the ‘most binary’ pixel; dividing the set of letters in 2 halves. 24
  9. We need a CMS! ‣ZF? Symfony? ‣Nah, let’s go for

    good old ATK • http://www.atk-framework.com • 13 years old, but gets the job done 27
  10. CSS sprite techniques 30 <div style = "width:60px; height:60px; overflow:hidden;

    position:relative;"> <img src="./data/screenshots/shot_51b19365d14c0_IMG_2156.PNG" width="300" height="532.5" style="position:absolute; top: -232.5px; left: 0px;" /> </div> (yes I know inline styles are evil)
  11. HTML5 Canvas (Yay!) ‣It’s so easy, even you can use

    it. <canvas id="canvas" width="320" height="568"></canvas> 31
  12. Ruzzle Retrospective ‣GameCoach for Letterpress: 5 days ‣GameCoach for Ruzzle:

    5 hours • Required support for more tile properties (e.g. inter-tile margin) • Different word search (using ‘Trie’ algorithm: http:// en.wikipedia.org/wiki/Trie) • Multiple dictionary support • Some rendering changes 36
  13. Next step: WordOn! ‣WordOn was piece of cake • Playing

    /collecting screenshots was the time consuming part ‣GameCoach was first (and still only) cheat ‣Reached Nr. 6 top grossing in word games :-) 37
  14. Summary ‣Development reduction by PHP backend: zillion percent ‣Managed to

    incorporate everything I ever learned: • Database design, Design patterns, Image manipulation, CSS sprites, CMS systems, Math, File uploads, JSON, APIs, Imagick, command line PHP, memory management, internationalization, caching 40