Thursday, April 26, 2012

Solving the "Move the Box" game (Programatically)

A couple of weeks ago some colleagues at work showed me this nice puzzle game called "Move the Box". I've seen dozens of these kinds of puzzle games in different variations, and as usual, I got hooked on it for a while.

I got stuck on a level I couldn't pass a couple of days ago, and this got my programming head thinking...
Hmmm... The board is only 6 by 7 tiles, and the levels only have up to 3 moves maximum... This shouldn't take too long for my computer to brute force through all the levels... :)

So, I got to work, and pretty easily got it solving the puzzles.
It works good on the puzzles i tested it on, which include puzzles with 1, 2 and 3 possible moves to the solution. The annoying part is that you have to enter the whole map of the level you want in a two dimensional array, which can take a long time. Then, all you have to do is tell it how many moves it gets, and hit F5!

Here's a screenshot of what I see when the code solves my puzzle -
Spoiler - This is the solution to the level "Osaka 22"

I put the code up on google code's project hosting if you wanna take a look, but this should come with a disclaimer -
The code is really ugly and hacky! This is only because it is a 'coding for fun' project at home, for something that will never reach any kind of production. The only thing that was important to me at the time coding this was the fact that it will work. I don't see myself using this ever again.
With that said, the logic of the board was still coded using classic TDD. It just seemed logical doing it that way, so it even has some cool tests.

...and if you're wondering, the answer is "yes" - This was a stupid idea, since I basically took all the fun out of playing this game for me! :)

Enjoy :)

Tuesday, April 17, 2012

Am I a good enough programmer ?

Ever since I started programming, this question has been bugging me. Now, I am trying to reflect on it from a different angle and I'm trying to understand what this even means to me and if in fact I am a "good enough programmer".

One of the most important things I learned a couple of years ago (from my team leader at the time), was that you can't define a goal without having a well-defined system to measure the success of reaching it. So, I must first define what being 'good enough' means to me.
In order to do that, I need to go back to the beginning...

The beginning
I started programming when I was about 12 years old (around the year 2000). It was building small applications for my first PC in Visual Basic for a short period, and about a year after that I started building websites using PHP and MySQL. Back in the day, I remember myself learning a lot from some books I ordered from amazon and reading easy-to-understand tutorials on the internet. I think at the time I was pretty much a script kiddie. A lot of the sites I built were from tutorials on the internet, and when I ran into problems I would run straight to the internet forums and wait for someone to help me out. I looked up to the ones in the forums answering my questions and publishing all the open source javascript/php components I was using freely, when sometimes I didn't even understand how they worked.
What I remember clearly from that period was wanting to be as good as those 'guys' on the internet - the ones answering my questions and publishing open source. I wanted to be another success story like the guys from Mirabilis or other companies at the time I was reading about during the dot-com bubble period.

Getting better
After a while, I felt like I had a lot of knowledge about PHP and MySQL (boy, was I wrong at the time), and I started building ecommerce websites as a freelancer. I built some nice websites (which some of are running till this date without any need of maintenance) and I felt like I was on top of the world. I was just waiting to finish high-school and make a career out of my favorite hobby!

Working on a team
After high school I served in the Air Force (mandatory in Israel) for 3 and a half years, 2 of those years as a computer programmer. This was the first time working on a team with other developers. Some of these developers had fancy college degrees and some of them had a couple more years of experience than I did. This blew my mind away! All of a sudden I felt like I met a new species of programmers I didn't know before. It seemed like these guys didn't only know how to program but they had a deep sense of knowledge of what their code means and how it was affecting the CPU. They all had their own blogs and every week one of them would present a lecture, talking about something new and teaching the team about new technologies.
I was totally blown away by this, and this convinced me that I wasn't even close to where I wanna be as a programmer...

Getting even better
I started reading a shit load of programming books, subscribing to some blogs on the internet and started diving into some leading open source code projects that were popular at the time. I even started a blog on my own as a way of learning more myself. During this period I learned so much and looking back at it, I would've never reached the amount of knowledge I know today without working with other people better than me (just a side note to others). By the end of those two years, I even managed to do some lectures myself and I think in some of them I got to teach others something new.

The 'real' world
My first 'real' job was working for an Israeli credit card company. At first I felt intimidated by this, since I didn't know if I gained enough experience to be working in a big company, so I continued doing what I learned to do. Learn, learn and learn! I continued reading a lot of blogs and learning as much as I can, so I can be as good as the best at my current workplace. That didn't take long and I became one of the best there. I soon became bored and started looking for a new job...
I interviewed at a couple of places but only had a connection with one of them. (I wrote about this in a previous post : A new direction) This is Sears Israel (SHC), which has been my current workplace for the past 6-7 months. Not surprisingly, here I met programmers that are even better than I ever met before, and immediately wanted to go in their footsteps.

I could go on about how I continued learning as much as I can, but I think you get the point (and looking back at how much I wrote, I doubt anyone would read this whole post!)...
So now I look back at that feeling I had when I first started out programming, not knowing how good I wanted to be, just knowing I want to be better, and I think today I can say that I feel almost the same way. A couple of times already, I tried to define goals as to 'how good' I want to be, but these definitions never hold, since there are always new technologies out there to conquer and more programming languages to learn. The second I feel like I reached that point, I just find something new I want to learn and think I'm not good enough since I don't know that yet...
This is probably one of the reasons I am still in this field of work. The challenges are never over, and your work is never complete.

Today, I can appreciate the fact that I know that I am working amongst some of the more talented programmers in Israel.
I know I'm not the best, but I am still striving to get there! I still don't know what being the best means, and if I'll ever get there, but I do know that I'm enjoying the whole process. I know as a fact I am getting better all the time and I know that just the fact of wanting to be better and doing something about it makes me better than most.

I know I am a whole lot better than I used to be just a couple of years ago, and I'm pretty sure that in a couple of years from today I will be able to say the same again. This thought gives me some peace :) and is VERY satisfying by itself!

Part of the reason I am writing this post is to be a message to myself and to others - You are not the best (this goes for 99.99% of potential readers), but (and this is a big 'but') you should always strive to be the best. Keep reading, learning and programming as much as you can and maybe one day you will be. Doing this will keep you in a good position and on the way to getting there.