
Hacking Calculords part 2: Who needs fingers? - RKoutnik
https://rkoutnik.com/2016/06/14/hacking-calculords-2-who-needs-fingers.html
======
jerf
RKoutnik, regarding the neural net, if you're not specifically looking to play
with neural nets but you just want to identify numbers, you don't need neural
nets. Especially if you have a digitally-accurate dump of the screen, you just
need one pixel that uniquely identifies the given number. Looking at the
screen shots, while the numbers are different colors, they all have black
outlines. It should be fairly easy to find simple combinations of pixels that
uniquely identify numbers.

If you _want_ to play with neural nets, by all means be my guest. But if
you're just looking to do the job, this is probably a much easier way.

~~~
RKoutnik
Thanks for the advice - and if this weren't a completely bananas project, I'd
be doing that instead. However, part 3 is a thinly veiled excuse to play with
neural nets and I learned a ton (code is done, post is about 1/3 written). The
opener to part 3 is an elaborate excuse as to why I didn't do the simple thing
(as you've mentioned).

One quirk of using NN for that task is that since I've already got all of the
possible outcomes, I need to deliberately overfit to my data (and it's a rare
case where 100% accuracy is to be expected). Of course that's a good sign I
shouldn't be using NN anyways, but we've beaten that drum...

~~~
jerf
Righty-o. More power to you and I look forward to your post. :)

------
fhood
"This drove the running time of the solver algorithm from an upper bound of 90
seconds to an average time of Out of Memory."

This, I almost peed I laughed so hard. And I had to pretend that my python
code was hilarious to convince my coworkers I was actually working (not hard,
it is hilarious).

~~~
RKoutnik
Fantastic! Glad you liked it.

(and nice cover-up with the Python, smart to use a language named after the
greatest comedy group of all time).

------
qwertyuiop924
This is fascinating. Although your AI algorithm might be faster if you could
somehow sort inputs, starting with the most promising, and discarding the
least promising, once an effectiveness threshold has been reached. Not knowing
Calculords that well, I don't know if this is possible or not.

Also the line

>At this point, it was clear I had two options:

>Armed with a trivial example and an inept grasp of the tools available to me,
I could write a snarky Medium post about how terrible JavaScript is

>WebWorkers

Having been on both the receiving, and a few times sending, end of such posts
(although not on medium, and not about js, for sending) I understand,
empathise, and cannot help but laugh. Steve Yegge at his best couldn't have
phrased that better.

------
pavel_lishin
I already tweeted this at you, and you already responded, but this is probably
a better venue: does your code deal with cards like Mutate Stargod that spawn
another number card to your hand?

Your tweet answer was: "Not intentionally, but since we're deploying
everything in the same row, it should be able to take advantage of that."

But that doesn't make sense to me - if you optimize for your 9 cards to spawn
all 6 available units/cards, but the best solution is still only 5, at the end
you might be left with that remaining soldier and a [5] card in your deck -
whereas the best solution for the _ten_ cards, including the newly-spawned
five, might let you deploy all six units.

(There are other weird edge cases as well, such as the $2 card that lets you
discard all of your units and draw 4 new ones.)

~~~
RKoutnik
Yeah, most of my work in this series is ever-better interactions with the game
itself via code. If Calculords had a comprehensive API, I'd be able to build a
smarter AI than what I currently have instead of working through things like
`adb` and image detection (coming in part 3!). I'd love to dig further into
strategy and ML but this side project has already occupied WAY too much of my
time. I may revisit it in the future after completing part 3 but I've already
got too many other ideas to make.

Unfortunately I don't recall exactly how Mutate Stargod works, from your
response it seems like I've misremembered how it works, mind posting the card
text here? (I thought it absorbed already-deployed mutates).

~~~
pavel_lishin
Ah, no - you're thinking of "Form Mutatro", which is a $15 utility card: "Your
mutates in the target lane merge into Mutatro, the Goliath Mutate God!"

Mutate Stargod is an $85 "Tactician 5" card: Generates a 5 in your calculator
when deployed, and gives all allied mutates in lane +1HP.

I think that even without machine learning, you could build a pretty decent AI
just with the "spam maximum units" tactic; that's why my favorite deck is all
mutates, preferring things that deploy multiple units.

I think hardcoding exceptions and edge-cases like Tactician cards would vastly
increase the number of calculations you'd have to make - because now the order
in which you deploy units matters, and calculations have to be re-considered
from every possible deploy-point on - although it may be enough to get to a
solution in which you empty out your calculator, and hope that the second
calculator deal lets you empty the rest of your units.

(This naive approach may not work for the harder bosses, though - spamming a
single row against Hate Bit is a good way to roll out the red carpet for him
to your base, since it's likely he'll get there before you do unless you get
an incredibly lucky deal.)

~~~
RKoutnik
> I think hardcoding exceptions and edge-cases like Tactician cards would
> vastly increase the number of calculations you'd have to make

The current algorithm is exhaustive, so one run will generate all of the
possible solutions to the given deal. Once all the solutions have been
computed, the AI could run through the top n solutions and pick the best. This
way the number of calculations is additive, not multiplicative. That's still
thinking per-round though (not at the game level). It should be possible to
determine if there are enemy units within striking distance of the base and
deploy counterunits (so your eggs aren't all in the same basket of the top
lane).

I haven't encountered any tactician cards yet (confession: I haven't even
reached Hate Bit, I've been so focused on the coding/blogging and it's easier
to debug against Fancybot).

~~~
pavel_lishin
> _I haven 't encountered any tactician cards yet (confession: I haven't even
> reached Hate Bit, I've been so focused on the coding/blogging and it's
> easier to debug against Fancybot)._

Ooh, you're in for... uh... well, not a treat. But a challenge!

------
Agustus
The title of this article should be Hacking Calculors, part 2: Who needs
fingers?

The emotional roller coaster I just went on of:

"Did I miss the release of Calculords 2?"

"No... I am not that out of it."

<click>

"Awww... Punctuation got me again."

~~~
RKoutnik
Title of HN post and actual blog post fixed. Thanks! Good catch, didn't think
of that as I was writing it. I'm awaiting the release of Calculords 2 as much
as you.

------
pavel_lishin
Hah! I was just playing that game on my break. If I had a genie lamp, I would
absolutely spend one wish asking for a multiplayer version; at this point, the
only challenging AI opponent is the very last one, Hate Bit, and I win against
it about 50% - and that number is slowly increasing as I improve my deck.

I actually thought about trying to make a web-based multi-player version, but
I don't want to rip off Seanbaby's hard work. (I also don't want to make a
'skinned' version that I could argue isn't a complete copy, because I don't
want to have to come up with the hundreds of units that would require.)

~~~
RKoutnik
You're in luck, Calculords 2 will have PvP:
[https://twitter.com/Calculords/status/692528566794330112](https://twitter.com/Calculords/status/692528566794330112)

~~~
pavel_lishin
Oh thank god, I don't have to do any of the hard work myself :p

