Category Archives: Experiences

On learning by tinkering, part 2.

There is always a profound sadness associated with the end of anything, be it a book, a tv show, a year, or an era. Projects are no different. And now that I’m done with my game (I can proudly christen it v1.0) I am incredibly sad. Bordering on depressed, even. I cleaned my room (I keep it dirty just to have things to clean when I’m like this). I rearranged everything. I brushed my teeth. I made an OS X build of my game, and then a Windows one. I don’t have Linux. I got a guy to mop my room down. I paid him with the surprisingly plentiful change hidden in books and crannies in my room. I sat down. I looked at the screen, with Sublime Text (my newfound favourite text editor) staring back at me blankly. I closed the laptop, and asked my mother how to clean a mug. I didn’t have detergent, is liquid hand wash okay? I cleaned my mug. I had five or six mugs of tea yesterday. I spent 14 or 15 hours at the computer yesterday. Coding, looking things up, making mistakes, fixing mistakes. Learning.

Having fun.

I just spent the last fifteen minutes looking at the pictures my code generates. My code. (Knot atlas’s knots, but still!). There’s something mesmerising about losing yourself in your work. Music helps too, and I have Broke for Free playing right now. They’re on Bandcamp. Have I mentioned Bandcamp is awesome? It is.

I am nowhere near done yet. Oh no. This is just v1.0. This shall be a very ongoing project. I have oodles of ideas for game modes. Arpit had a brilliant idea, too, but I need to math it out to see if I can implement it or not.

What now? A log. Of retroactively named versions of my game. Thank you for reading.

v0.0
Idea is nebulous. Kawauchi shows us his game and I think about it for the next few days. I don’t quite know when exactly I wanted to make it. But I began doodling in class once. I drew the tiles I would go on to use in the actual code. I figured out how to convert arc representations into matrices. I stopped doodling.

v0.1
I find cocos2d and make the bare bones display window appear. I muck about till I get a hardcoded arc representation to become a diagram.

v0.2
I’m home now, and I’m back to doodling. This time it’s to toggle the crossings. I spend a full day thinking about it. I code it in one go the next day. Now the hardcoded knot toggles. I have one level of my game. It’s boring.

v0.3
The episode with Knot Atlas. I yanked 250 representations from their website. I wrote some code to go back and forth between knots. I changed from the “over/under” images for the crossings to “on/off”. And these are assigned randomly, to improve replayability.

v0.4
Squashed a bug I didn’t realise was there that had to do with duplicate regions being spat out by my code. Now is neat. Also the outside is now a region.

v0.5
Now I’m in Roorkee. There’s no internet. I can’t update/jailbreak my phone to put my game in it. Impatient. I begin coding it from scratch in Python. Find Tkinter, which I subsequently fall in love with. Rapidly get it up to speed, to v0.4 in one day. Or maybe two.

v0.6
I learn more Tkinter stuff. I make more windows. And buttons. And victory screens. I send the code to people. They either can’t or don’t want to play it. No matter, I try making it better.

v0.7
Changed a function that was updating every 0.1 sec into a static thing that checked only when something happened. Huge speed increase. Cool. Put in a help screen. Helpful help screen. Polish code a little bit.

v0.8
Added a counter that told you how many moves you’ve made so far vs. what the minimum is. Took a while to code. This was what I was doing yesterday. Made the counter slightly fancy with colours and stuff. Gave you the option to retry the same random seed, or to try a different seed.

v0.9
Got bored and added a Cheat button that shows you exactly which regions you need to tap in order to win. This is for when you’re too frustrated with a level or when you simply don’t believe the minimum number. Also, this is a wonderful gauge of difficulty. A 1, 2, or 3 turn level is incredibly easy and a 7, 8, or 9 turn level is deliciously hard. I love playing them. Can lose myself for hours.

v1.0
Used py2app to make an OS X app. Used py2exe to make a very messy Windows executable with a bunch of junky windows dlls and what not.

Roadmap?
Shall use py2objc to make an iOS app. When I eventually jailbreak my phone I shall get it on there.
Should probably care about Linux. But eh, they can build from source.
Write some code that goes through ALL the combinations for all the knots and sorts them by minimum turn required. Each knot has an average of say 12 crossings, and there are 249 knots, so that’s at least 1,000,000 levels. Yes, a million.

Jesus, a million.

Game modes. Like a time limited one. Or to get to a particular configuration. Or loads more. More info when I get down to coding them.

If you’ve read this far, you’re hopefully interested in the game. So here: https://www.dropbox.com/s/buzllp03yxp6a03/Source.zip

That contains the image tiles used to generate knots, the plist containing the codes I took from Knot Atlas, and the Python script itself. You’ll need Python 2.7 installed on your computer for the script to run. Leave all the various files inside the same folder. And you’re good to go!

Do let me know what you think. If you read the source, don’t hesitate to tell me all the ways I code horribly. Must get better.

Advertisements

On my adventures in the key of DIY

I am not a DIY person. (That’s Do-It-Yourself, if you didn’t already know). I have never actually done any work with any tools for anything ever. The only time I used screwdrivers and/or wrenches was putting one of those remote controlled Lego things together.

I can tell you precisely why I’m not a DIY person. Because I lack the confidence that I wouldn’t make a bigger mess than already present. Case in point: putting a screen protector on my phone. Horrible task. I put it on and everything was fine. Except for one teensy air bubble near the top. I tried ignoring it for four minutes. Then I went mad and let’s just say two hours later the screen protector was in no shape to be doing any screen protecting.

Which is why I surprised myself when I upgraded the RAM of an old laptop we had lying around. I ordered the memory (2 x 2 gb) from flipkart. When it arrived, I opened the bottom of the laptop (unscrewing three screws!), ejected the old RAM, vacuumed the dust out, pushed the new ones in, re-screwed everything back together, and did not brick the laptop in any way whatsoever.

I also have never installed a new operating system before. Because I always procrastinate too much about organising and then backing up all the shit I have. This was different. Old laptop. Nobody cares. I’ll do a fresh install. I downloaded the latest OS the thing could run (OS X Lion), made a bootable pen drive of it, and installed it in the newly erased old drive.

I have plans of eventually getting a tiny (60 gb) SSD to round up the speed boost. Why so little? Because of the reason why I went though all this. Xcode.

Xcode requires Lion. Lion requires 4 gb. (Well, 2, but 4 is better). That’s honestly the only reason I did any of this.

It’s a relatively banal moral. If I want something badly enough, I will do the shit it takes to get it. Now. I’m surprised that this is a surprise to me. I am also surprised that what I just described seems to be being referred to as some sort of Herculean task here. Lots of surprises.

Not Herculean in the sense of effort, of course. Herculean in the sense of it testing my confidence.

I don’t really have a point.

Good night.


On learning by tinkering

Aka “diving in and doing stuff”.

I realise I am no authority on the subject, but the last few days have had me engulfed in a project where I started out knowing almost nothing, and now it’s in a half-decent on-it’s-way-to-completion state. And I got to this point completely by googling the hell out of every roadblock I came up against and using as many readily available open source thingies as possible.

Yes, I’ve been coding. A game, to be particular. A game some nice Japanese people made (play store link). Why? I have no idea. It just seemed like a cool thing to do. I’ve always wanted to make a game. I’ve tinkered with another one before (I’ll talk about this later) but I’ve never built one before. And now I have a game idea to build upon!

The last time I did something like this, in the summer, I recorded progress on my app on my Facebook. In an album full of screenshots and annotations. Now I have a blog so a blog post it shall be. Ever-updating, of course.

First. Some preliminaries. I used XCode for this project partly because I was familiar with it and mostly because when I started it, I had nothing else with me. The mac stays at home though, so I’ll need to transfer the code to something like HTML5 if I want to be able to work on it in college. Or use one of the XCode windows ports for the computer in my hostel room. Whatever. Now that that’s out of the way, what I did:

One aspect of “game programming” that’s always daunting for me is the simple act of getting a window up that then displays an image. This is like Everest for me. It is such a steep mental block that I have given up countless roguelike game ideas because I could never get a window up in Python. I know PyGame and stuff exist but I was too “purist” a few years ago. I wanted to write everything myself. Now I know better.

Now I know, for instance, that being a purist is simply not feasible, at least for me. There are people out there who have done all the work for me. I just need to find those people and use their work. This is not exactly trivial. For instance, I use Cocos2D to do all the graphicy stuff. (I say “do” rather loosely). It is ridiculously simple to set up and use. But it took me the better part of a couple of hours to find it, or indeed that it was what I was looking for. I know this might not seem like much time, but it is when you take into consideration that I want to do this for fun. Not much fun if I can’t get started.

So. I was lucky to find Cocos2D. I had a thing that could put stuff on the screen. Yay.

What will I put up, exactly? Well.

Oh dammit. I haven’t explained the game to you yet.

Sigh. Hold on.

20131226-095708.jpg

Okay. This is a screenshot from the game so far. (Thank you!)

See those little white or black squares here and there? And see those shapes that the lines form, boxy little things? I call those shapes regions and those squares crossings. A white crossing is off, a black one is on. If you tap a region, all the crossings along its boundary are toggled. Your goal is to turn every crossing on.

Got it?

Good.

Now, if you notice, that picture might seem complicated to make. If you think about it for a second, though, you’ll see that it’s actually composed of little tiles, of which you only need 9. These 9, to be precise:

20131226-100613.jpg

Cool, right? So all I have to do is figure out a way to put those tiles together in order to make whatever knot I want. How do I put them together? Well. There’s a thing called the arc presentation of a knot, which is an array of coordinates from which you can generate these images. I won’t bore you with the details but I will point you to the website that will: Knot Atlas.

Next problem. How do I get these arrays? That same website (a sort of Wikipedia for knots) also has these arrays for the first 250 prime knots. Aaand they have a database you can download of all the info they have. Perfect? Not quite. That database doesn’t include these arrays (because they’re not unique.) So I need some other way to get what I need.

Every mac comes with a brilliant little program called Automator that you can use to automate little everyday things. For instance, you can make an app whose sole purpose is, when clicked, to close all other apps. Or you can stitch together loads of images into a PDF. Or you can mass rename things. Or. Or. You can do this:

20131226-102051.jpg

Too perfect. The first bit spits out a list of all the links on the page given to it. The page I sent it to was this one. It has links to all the knots I need plus some extraneous things. I cut out the stuff I didn’t need and fed that into the second bit that, in ten minutes, dumped a biiig text file containing aaaaaall the text from those webpages.

Now. I need to locate the arrays. And convert them into this thing called a .plist file which is what XCode understands very easily. Easy enough, Python! I wrote a Python script that sifts through the text, finds the array, yanks it out, and dumps all them into a neat plist.

20131226-103810.jpg

(I like screenshots.)

Anyway. Now I have a bunch of arrays that I can make knots from. Oh, and by the way. This isn’t in strict chronological order. There’s no way I would go through all this without first having a working piece of code.

And that code was by turns easy and frustrating to write. What I basically had to do was follow the rules of the arc presentation to go from the array of the website to the array of image files I needed to call in order to draw the damn knot. Not difficult. The difficult bits were then recognising which region you tapped in. And once you’ve recognised it, how the hell do you then associate the crossings of that region to the region itself? I had no idea.

For a few hours anyway. Then I broke the problem down. Like this:

Well. I’ll worry about how I get the regions and crossings and all later. First, given the vertices of a polygon, how do I detect when I’ve tapped inside it?

Easy enough. Googleable. Found a website that I want to link to but I can’t seem to find it now. Ah well. After that, I needed a way to actually get those vertices from the array.

I don’t quite know how I arrived at the Jordan Curve Theorem but I did. What the theorem states is basically this: if you have a closed simple curve and you attach a direction to it, travelling along the curve in that direction, the “inside” of that curve will always be to one side of you. Obvious enough no? But this was the catalyst I needed, the guarantee to continue, essentially.

Basically, if you start at one of the corners or a crossing, and follow the path defined by the above rules, you’ll always get back to your original point and you’ll have described a region in the process. You can pick up any crossings along the way and make them “belong” to the region. Done!

Let me illustrate:

20131226-110028.jpg

The 10s are top-left corners, (the “aa” image from the second screenshot). The 3s are crossings. Fill in the rest yourselves. What I mean is, start at every 10 or 3 (nothing else; I’ll explain why in a bit) and then keep following the curve until you hit another corner or crossing, whereupon you then turn in the manner indicated. If you do this, you will have mapped out all the regions on the knot, except for the outside region. Some duplicates exist. The reason I say don’t start at 11s or anything else is because they are always duplicates (think about it). Or, with 11s in particular, they usually map the outside region. Why? Because starting at the bottom most 11, if you go right, you are mapping “down” as a region. And “down” points to the outside. You will traverse all the vertices on the outermost fold of the knot. Cool no?

Anyway. I have all the info I need. (I’m skipping over a bug from repeated regions in the interest of now laughable brevity.) I wrote it all down and boom. I can draw any of 249 knots. I can tap away at any region and all the correct crossings toggle instantly. I’ve even included the outside region. Some knots are ridiculously easy to solve because the crossings are all off to begin with. So I made it so that each time a knot is drawn a random number of crossings are already on. This makes it not as straightforward for easy knots and quite fiendishly hard on the normal knots. Yay.

DONE.

Ish. I still need a menu and buttons and a counter for how many moves you’ve made and a display that tells you the minimum number you actually need and sits and mocks you when you exceed it. All in good time.

Further thoughts I shall add later. When I’m optimising the thing because right now it leaks memory like crazy.

Thanks for reading! (If you survived this far, that is!) Do comment. Or if you code yourself, feel free to tell me better ways to do stuff, especially a non-mac way to yank text from webpages.


On Mohali

One lazy winter evening, Priya happened to mention to me that she was going to attend a program on knot theory in IISER Mohali. She said the organisers were really nice people so I could probably still apply even though it was way past the deadline.

In a singularly uncharacteristic turn of events, I applied, and eventually was told with much gusto that I could attend. At this point I didn’t really think of the whole thing as “real”. I had booked a train ticket (now I know what all the class codes mean!) for Chandigarh but I never thought I’d use it. I had picked out the clothes but never thought I’d pack them. And so on.

But December the 9th came along. And my suitcase was packed (thanks to mother). Final farewells exchanged. Got on the metro to the station, found the train and sat in it. Five hours later, I’m in Chandigarh. A half hour (and one seriously overpriced auto ride) later, I’m in IISER Mohali. Everything is so different. I’m in the guest house. My name isn’t on the list. Priya’s phone is not reachable. I sit and wait for someone to come along and say I can go up. People come and go. And then Priya shows up. And then the guy I’d been emailing shows up. He says to the receptionist to put me in room 501. Priya tells me she’s next door. Happiness!

We go up to my room. Fancy. Big. We go to her room. We meet her roommate, Asha. It takes me a day to memorise her name. She’s from NIT Calicut. She’s very nice. She studied under Rama Mishra during the summer. Knot quandles. Fascinating stuff. Rama Mishra is one of the organisers. Priya had mentioned a bunch of times that she was awesome. We met her and I concurred immediately.

I don’t quite remember what we did that first day. I remember the restaurant. Zozen. What a funny name. What absolutely scrumptious food. (I later found out the food budget for this thing was 4.5 lakhs). For the first week or so, not one dish was repeated. There was always paneer in some new and exciting form. Ditto chicken, or fish, or mutton. Eight kinds of dal. A bunch of state-specific cuisines. Pickled carrots I enjoyed surprisingly a lot. And a different sweet everyday. Heaven. I don’t eat this regularly at home only.

Anyway. On to the program itself. The first day had a little introductory bit by Rama Mishra. She laid down a bunch of terminology and definitions and then introduced the next speaker, Louis Kauffman. He walked up to the board and starting talking in a booming American accent that I could follow without a glitch. After another introductory bit he started writing down some polynomials used in knot theory. The last thing he wrote down in a progression of these polynomials was something called the Kauffman Bracket.

It took a while for that to sink in. He’s teaching us about something named after him. Something that he invented. He’s, like, famous! And he was talking so gleefully about his Bracket polynomial. Talking us through very naturally about what he was thinking while he was developing this idea. I was amazed.

There were many speakers. Slavik Jablan, from Serbia (crystal clear accent), Jozef Pryztycky, from Poland (a bit unclear but understandable), V Bardakov, from Russia (with stereotypical Russian accent), Benjamin Audoux, from France (with stereotypical French accent) and loooooots of Japanese people with varying degrees of clarity in their English.

I’m not exaggerating when I say loooots. There were at least 10 of them. Our runaway favourite was the awesome Akio Kawauchi (河内 明夫, whose name means “a good husband in the middle of a big river”). He sat next to Priya one fine dinner and started philosophising at her about life and knots and how people’s lives are like knots and meeting other people is like performing a crossing change on those knots and so on and so forth. I joined them in a bit. He was a very nice old man. His English was clipped, but he still managed to express himself rather well. After a while he took out his phone and showed us this game called Region Select (search for it on the Google Play Store). He said it had to do with knots and that it was a fun and challenging game. Then he let us play it! Some ten minutes or so was then spent trying to figure out the rules by trial and error (the rules in the game were in Japanese). After a while, it dawned on us that he was one of the co-creators of the game! He must have mentioned it at the start but we didn’t understand. This was so cool! He said one of the others was also here, and she would give a presentation about the game and how it came about. So cool!

Angad. How did I get this far without mentioning him? Angad is Rama ma’am’s son. He’s 11. And much smarter than any other 11 year old I’ve seen before. He is a non stop talking machine. He must have spoken to everyone at the conference. He walked up to all the speakers and asked them something like the following:

Pick a number between 1 and 10. Multiply by 10. Add 5. Multiply by 20. Add 10. Your number is X!

He likes riddles. And tongue twisters. And Harry Potter. He’s in the school choir. He knows a lot of cool songs I didn’t think it was possible for an 11 year old to know. He is also utterly fascinated with gadgets and app stores. He went apeshit when he saw my phone. And Priya’s kindle. He kept telling me to download random apps and games. He didn’t know about angry birds for some reason so I showed it to him. He looooved it. Then he mentioned he liked Prince of Persia and I happened to have that, so we played that as well! He kept dying to the guys you have to sword-fight with though. Kept panicking and mashing all the buttons at once. Anyway.

He’s loads of fun. He’s on google+. You should add him.

His mother must have been so relieved that he took to us so well. Instant babysitters! He was with us a bunch of times and each time was very fun. He says the most surprising things sometimes. He really is quite clever. He also has a “temper” which is very cute and funny. And he knows karate (or at least can fake knowing it very well). I must have missed something or other. I shall update this whenever I remember more.

Class again. Kauffman was talking about rational knots. Very fascinating stuff. At the end of the talk, I went up to him and asked him why they were called “rational”. He had a sudden twinkle in his eye and he asked for a paper and pen. I took my book out and he then proceeded to explain in exquisite detail precisely why they’re called that. Not only that, he also then went on to talk about cool properties these things had. And then he ended it with one particular cool property that he himself discovered. So. Awesome. In the end he had written in about six or seven pages of my notebook. This is worth WAY more than an autograph would ever be, to me. (I later looked up some papers of his on rational knots, and was delighted to notice that all the stuff he explained to us in my notebook constituted 19 pages of a 40ish page paper he wrote).

There is so much more I can tell you. Slavik Jablan is the author (I think, or maybe founder) of LinKnot, a Mathematica package that does knot theory stuff on your computer so you don’t have to yourself. He mentioned it in his talks a lot, and I wanted to know more about it. So one day I asked him if he would demonstrate it to us students, so we would have a vague idea about it. He was so nice about it! He agreed immediately and he showed us the program the next morning, on a Sunday, before breakfast, right before an outing to Chandigarh for the day. His enthusiasm is positively contagious.

Even though I understood way less than even a quarter of what was talked about, I enjoyed the experience immensely. I shall more seriously read about things I don’t yet know but will need (topology!).

Oh! Sujoy! Last story, I promise. From the beginning:
Someone asked Kauffman something about Möbius strips. I was doodling away but Priya wanted to know what the question was. She went and stood near where Kauffman was telling the other guy something. Sujoy was also standing near there. After a few minutes they came back with this nugget: if you have a thrice-twisted Möbius strip that you cut in half, you get a trefoil knot. So to test this out she made the strip, stapled the ends together and cut it in half. Whaddaya know, trefoil knot! The stapler was Sujoy’s so we started talking a liiiitle bit after this.

The day before he left for home, he asked us if we would like to go out and walk around in Chandigarh. Maybe have dinner. We were like yeah, sure! At 7 we set out for sector 35. It was soooo much fun. He took us to a dollar store where we bought little presents for home. Then this bakery which smelled so perfectly of chocolate, where he ordered this sizzling brownie ice cream thing that was scalding and delicious. We walked around. Got some KFC chicken popcorn. Cotton candy. Walked in and out of a Burger Girl. Then eventually went to some punjabi restaurant and spent the rest of the time talking about raaandom things. Was so much fun.

But that’s not the end yet. After we got back to the campus, we walked to his hostel and got some tea and coffee. We were just sitting there and talking about random things again. I don’t quite remember how but we eventually started talking about maths. And studying. And stuff. I cannot summarise the discussion for you but let me tell you it was amazing. He was, for lack of better words and perspective, so wise! I knew someone like him back in Roorkee, but he would talk about physics like this. It was so nice to see someone talk about maths this way. So. Awesome.

Okay. That’s all for now! This is much less than a tenth of all the stuff that happened. I shall probably keep updating this as I remember more and more.

Thanks for reading! And for another point of view, check out Priya’s blog!