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. http://www.egeniq.com
    [email protected]
    @egeniq
    Dutch PHP Conference, 7 June 2013
    Ivo Jansch
    Cheater’s Math
    Or: how iOS app + PHP == $$$

    View full-size slide

  2. About Me
    @ijansch
    Entreprenerd
    Mobile & Web Developer
    Author & Speaker
    Talk feedback:
    http://joind.in/8446
    2

    View full-size slide

  3. 2 ways to make money
    ‣Successful games
    ‣Cheats for successful games
    3

    View full-size slide

  4. The arrival of Letterpress
    4

    View full-size slide

  5. Beating Letterpress
    ‣What do we need:
    • Analyze screen (dimensions, location of the board)
    • OCR
    • Color matching
    • Word matching
    • Word scoring
    • Game strategy
    5

    View full-size slide

  6. OCR
    ‣Complex algorithms
    ‣Look at existing libraries
    ‣Image comparison
    or.....
    ‣CHEAT!
    6

    View full-size slide

  7. Fast & Dumb Binary Tree Pixel Thingee
    7
    ABCDEFGIJOPQRSTZ HKLMNUVWXY
    BDEFPRTZ ACGIJOQS HMNXY KLUVW

    View full-size slide

  8. Workable, but crude & ugly code
    8

    View full-size slide

  9. Same for dimensional stuff
    9

    View full-size slide

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

    View full-size slide

  11. GameCoach was born
    11

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  14. GameCoach new style
    14
    Game management,
    analysis
    Signatures Generic parser,
    game strategy

    View full-size slide

  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

    View full-size slide

  16. Recursive dimension parsing
    board width = screen width
    board height = screen width (square board)
    board x = 0
    board y = screen height - board height
    16

    View full-size slide

  17. Poor Man’s OCR
    ‣Pixel method worked, but hard to do
    ‣What if we train a parser using existing
    screenshots?
    17

    View full-size slide

  18. Enter The Matrix
    18

    View full-size slide

  19. Enter The Matrix
    19

    View full-size slide

  20. How? Just some Imagick
    20

    View full-size slide

  21. Canonicalize the screenshots
    21

    View full-size slide

  22. Reduced Matrix
    22

    View full-size slide

  23. Reduced Matrix up close
    23

    View full-size slide

  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

    View full-size slide

  25. Result: generic signatures
    25

    View full-size slide

  26. Client side generic parser
    26
    +
    =

    View full-size slide

  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

    View full-size slide

  28. Stop!
    Demo Time!
    28

    View full-size slide

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

    View full-size slide

  30. CSS sprite techniques
    30

    width="300"
    height="532.5"
    style="position:absolute; top: -232.5px; left: 0px;" />

    (yes I know inline styles are evil)

    View full-size slide

  31. HTML5 Canvas (Yay!)
    ‣It’s so easy, even you can use it.
    height="568">
    31

    View full-size slide

  32. HTML5 Canvas
    32

    View full-size slide

  33. Reading canvases
    33

    View full-size slide

  34. Writing canvases
    34

    View full-size slide

  35. GameCoach engine to the test: Ruzzle
    35

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  38. The future :-)
    38

    View full-size slide

  39. The future :-)
    39

    View full-size slide

  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

    View full-size slide

  41. Thank you! Questions?
    http://www.egeniq.com
    [email protected]
    @egeniq
    http://www.egeniq.com
    [email protected]
    @ijansch

    View full-size slide