Pages

Friday, April 24, 2009

Crunch time!

1 comments
Well, I'm back to post about something after quite a long time! I can tell you what I want to tell using a simple equation.

" Practical examinations + End-Semester exams + IPL = No time for blogging "

With exams around, I dont think I'll find time to post anything in the coming fortnight. Hoping to get back with a bang from May 12th(Yeah, thats when the exams get over).

Saturday, April 11, 2009

SAE Baja 2010

0 comments

As soon as I saw a poster in my class's notice board inviting second year students for an open interview for recruiting second year members for CEG's SAE(Society of Automotive Engineers) Baja 2010 team, I remembered the baja vehicle that was displayed during Kurukshetra '08. Building an ATV(All Terrain Vehicle) during the second year of your Engineering course sounds great! I badly wanted to be a part of that team. I attended the interview with a strong resume backing me. After the 15-minute interview(quite long for this kind), I came out confident of getting selected. As I expected, my name was present in the selection list.

Now that the team is finalised and registered for Baja 2010, its time to wonder about what exactly we're gonna do - build an ATV from scratch? Probably yes! Baja tests every aspect of your vehicle - the design, stability, power, speed and aesthetics too! The venue for baja 2010 is the same as that of 2009 - Pithampur, Madhya Pradesh. As we'd be starting our work soon, I guess there are exciting times ahead!

This is the SAE baja's website... http://bajasaeindia.org/

Sunday, March 29, 2009

AI Programming

3 comments
From the time I entered college, I was fascinated about game programming. Once my senior told me, when the API of the game is already in you hands, the coding part can be as easy and fun as it can ever get. Yet it took me almost two years to get the determination to code for a game programming event. It was for Abacus '09, the National level symposium organised by the Department of computer science in our college. The game scenario was simple. Its similar to the snake game that everyone invariably must have played on a nokia mobile. The difference was there will be two snakes on the arena and food will be randomly generated at four points on the play area. Also, the snakes will have an energy associated with them which will decrease by a unit for every move and increase by some units for each food particle consumed. The organisers provided the API and all we had to do is to code a function that returns one of the four characters - U, D, R, L as output corresponding to the up, down, right and left movement of the snake. We are provided with the snake's position i.e., row and column number of each of the element of the snake's body, opponents position, our energy and opponents energy. Each coordinate of the play area is assigned a character where 'E' corresponds to empty, 'F'-food, 'X'-boundary, 'A'-snake A's body, 'B'-snake B's body. With so much information available at hand, the coding becomes really easy. but still, I'm a beginner! :)

I started coding and tested the game by using the same code for both the snakes(during the event, one snake will use your code and the other will use your opponent's code). After a couple of days, I thought I've done whatever I could do and submitted the code. As I'm not a great programmer, I didnt plan the algorithm at the beginning. I kept changing the structure as I kept testing the game. during submission, I could easily see that my code was divided into 4 parts.

1) Locating all the 4 food particles
2) Locating the food particle that is nearest to the snake's position
3) An initial instruction for navigation towards the food(avoiding the boundary)
4) Checking whether the initial instruction is a valid move(bumping into yourself or the opponent means you are out of the game!) and giving a valid and safe instruction.

This code works efficiently until the randomly generated food makes you move in such a way that you make a trap for yourself!


In the above picture you can see the snakes moving towards the nearest food.

In this picture, snake a bumped onto itself and lost the game!

As, many of the participants(except one) coded in a similar way, it was obvious that the random generation of the food will be the factor determining the winner. The better your luck, the greater your chances of winning. My luck was so good that my code won the second position!! Only later I heard from the organisers that the guy's code which won the first place was far more superior than the rest. That code was such that the snake wont trap itself often and also it'll try to blog the opponent and trap it!! How about that?!?!