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.

B272216b76be8aacbfd11fad48196558?s=128

Ivo Jansch

June 07, 2013
Tweet

Transcript

  1. http://www.egeniq.com info@egeniq.com @egeniq Dutch PHP Conference, 7 June 2013 Ivo

    Jansch Cheater’s Math Or: how iOS app + PHP == $$$
  2. About Me @ijansch Entreprenerd Mobile & Web Developer Author &

    Speaker Talk feedback: http://joind.in/8446 2
  3. 2 ways to make money ‣Successful games ‣Cheats for successful

    games 3
  4. The arrival of Letterpress 4

  5. Beating Letterpress ‣What do we need: • Analyze screen (dimensions,

    location of the board) • OCR • Color matching • Word matching • Word scoring • Game strategy 5
  6. OCR ‣Complex algorithms ‣Look at existing libraries ‣Image comparison or.....

    ‣CHEAT! 6
  7. Fast & Dumb Binary Tree Pixel Thingee 7 ABCDEFGIJOPQRSTZ HKLMNUVWXY

    BDEFPRTZ ACGIJOQS HMNXY KLUVW
  8. Workable, but crude & ugly code 8

  9. Same for dimensional stuff 9

  10. Heuristic scoring ‣Simple rules ‣Strategy design pattern 10

  11. GameCoach was born 11

  12. 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
  13. 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
  14. GameCoach new style 14 Game management, analysis Signatures Generic parser,

    game strategy
  15. 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
  16. Recursive dimension parsing board width = screen width board height

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

    ‣What if we train a parser using existing screenshots? 17
  18. Enter The Matrix 18

  19. Enter The Matrix 19

  20. How? Just some Imagick 20

  21. Canonicalize the screenshots 21

  22. Reduced Matrix 22

  23. Reduced Matrix up close 23

  24. 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
  25. Result: generic signatures 25

  26. Client side generic parser 26 + =

  27. 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
  28. Stop! Demo Time! 28

  29. CSS Sprite techniques 29 Issue: css sprites & image scaling

    != friends
  30. 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)
  31. HTML5 Canvas (Yay!) ‣It’s so easy, even you can use

    it. <canvas id="canvas" width="320" height="568"></canvas> 31
  32. HTML5 Canvas 32

  33. Reading canvases 33

  34. Writing canvases 34

  35. GameCoach engine to the test: Ruzzle 35

  36. 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
  37. 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
  38. The future :-) 38

  39. The future :-) 39

  40. 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
  41. Thank you! Questions? http://www.egeniq.com info@egeniq.com @egeniq http://www.egeniq.com ivo@egeniq.com @ijansch