Sunday, 23 December 2012

Photo Journal, Part 2

Hi guys!

As promised, I'm back with the continuation of my Photo Journal. Those who haven't read the first part can go to my post titled 'Photo Journal, Part 1'.

A quick recap: In part 1, I showed you some of my favourite photographs, divided into 2 groups: Group 1 on the photos I took during my road trip in the Himalayas, and Group 2 containing my best wildlife photographs. I had left Group 2 unfinished, which I shall be finishing in this post.

So, here goes:


Group 2 - Wildlife (Continued):

4) Brahminy Kite, taken in Shoja, Himachal Pradesh, India.



5) Shoe-Billed Stork, taken in Jurong Bird Park, Singapore. This one's a real angry bird!



6) Eye of the Peacock - taken in Dapoli village, Maharashtra, India.



7) I really don't know the name of this moth/butterfly, but it looks magnificent. Taken in Spiti Valley. Himachal Pradesh, India.



8) This is a photo of a Glassy Lizard, taken in a forest in Goa, India. It is probably my most prized photograph - I love the effect created by the interplay of light and shadows!




Anyway, that concludes my photo journal.

Hope you liked it!

Signing off,
Pratik.

Photo Journal, Part 1

Apparently, a picture says a thousand words. If so, then this blog post contains more than seventeen thousand words - quite a staggering number, isn't it? Read on if this has piqued your curiosity......

My interest in digital photography grew exponentially around the time I was in the 7th grade. Maybe it was because of my father, who has always been somewhat of a camera buff himself. Maybe it was because of my uncle, who had just bought a brand-new, awesome camera back then. I don't really know. What I do know is that I have loved photography ever since, and given the chance, I am more than willing to spend hours with my camera.

I love being able to capture the memorable moments of my life and the lives of those around me - some of them sad moments, some happy, some just plain hilarious, and some which induce introspect. Every time that I go back to a photograph that I have clicked, I see it in a new light; I see another aspect, another dimension to it. To me, photography is a way of immortalising a beautiful vista, or an inexpressible emotion.

Nature photography is something that I thoroughly enjoy and is very close to my heart (wildlife and environmental conservation is something that I care deeply about). Nothing matches the glory and beauty of a photograph of a massive, ancient Banyan tree, or a snap of a hawk soaring high. For me, part of the fun lies in the actual process of obtaining the picture - chasing a frisky woodpecker through a forest, or waiting in dead silence to photograph a timid Chital deer.

As the title suggests, this post is a photo journal of some of my favourite snaps out of all the photos I have ever clicked. Each one is special to me for a reason - because of the colours and clarity of the picture, the significance of the moment, or simply the overall effect of the photograph. I have divided the pictures into two main groups: Group 1 contains pictures I took on my 15 day road trip with my family in the Kinnaur and Lahaul-Spiti regions of the Himalayas (in Himachal Pradesh, India) during the summer of 2010, a journey that is one of the most memorable ones I have been on. Group 2 is a collection of my best (according to me) wildlife photos. I took all of these photographs with a Canon SX 10 Ultrazoom camera.

I guess I'll just get started with the photos now:


Group 1 - Himalayan Odyssey:

1) A beautiful snowdrift on a distant peak that I managed to capture while camping in Sangla village, Kinnaur:



2) Three adorable kids in a small hamlet in Hamchal Pradesh. You can't but help marvel at their expressions!



3) During the last 8 days of the trip, we were surrounded by dry ravines, barren, snowcapped mountains, and azure skies, with hardly any vegetation in sight, as we journeyed in the Spiti valley. Albeit a non-conventional kind of beauty, but beauty nonetheless!









4) This is a panoramic photograph of a mountain near Tabo village in the Spiti Valley. For some reason, it reminded me of chocolate ice-cream.



5) I just love the colour contrast between the sky and the mountainside in this one:




Group 2 - Wildlife:

1) Vulture in Spiti Valley, Hamichal Pradesh:



2) A Hanuman Langur silhouetted against the evening sky. Taken in Dandeli Forest Reserve, Karnataka, India.



3) Great Pied Hornbill, taken in Dandeli Forest Reserve, Karnataka, India.



I shall be ending this post here. But the photojournal is not yet done. It will be continued in my next blog post.

Good bye for now.


Pratik.



Wednesday, 19 December 2012

Mastermind

Hello world!

While this opening statement may sound cliche, I have used it for a very specific purpose - it's related to the main theme if this post. The phrase is a reference to the classic 'Hello World' computer program (Humorous wordplay. Ha ha). To the uninitiated, the 'Hello World' program is a computer program that displays the sentence 'Hello world!' on a display device - it is generally one of the easiest programs to write, irrespective of the language used. To those of you who got the reference, I suppose there is no point in explaining it and rendering the pun moot. 

So I'm guessing that a lot of you have by now guessed what this post is all about. You're actually partially correct. Yes, this post is about computer programming. But no, it is not a generic post describing a programming language or its evolution.


In the 9th and 10 grade, I took a course in Java programming in high school. It was incredible fun - but I'm not going to focus on that right now (maybe in a later post). Anyway, after I started to get a feel of the language and had completed taking my first baby steps in program writing, I decided to get a little more adventurous. I consolidated my knowledge and Java coding skills and made up my mind - I was going to develop a  . . . . DUN DUN DUN . . . . game.

For my ambitious project (or so it seemed to me), I decided to develop a text-based emulator of the hugely popular board game, Mastermind. (Yes, the one with the coloured pegs). If you haven't heard of or played it, I suggest that you read up on the game before going further into this post (the Wikipedia article on the game is excellent).

In my version of the game, the user plays against the computer. It is the computer that decides the sequence of colours and the user who has to deduce the colour code in 10 turns. As in the original game, the computer does provide a clue after each turn. I haven't kept any provision for it to be the other way around - maybe I'll come up with that one some day. My first beta testers were my parents (my father is the one who introduced me to mastermind in the first place, way back when I was a kid) and my high school course teacher. 

I wrote the code using Java on BlueJ as an Integrated Development Environment (IDE). It turned out pretty well and I'm quite proud of it. While I haven't put it up on the Internet, I have put up the entire code below. Those of you who are interested in reading the code can scroll down the page.

-

CODE FOR MASTERMIND EMULATOR (IN JAVA):


import java.lang.*;
import java.io.*;

public class Mastermind
{
    long noseq[];
    int noseq2[];
    String seq[];
    String eseq[];
    char tmpseq[];
    int white;
    int black;
   
    static String nm;
    static String lines[];
    static int wordcnt = 0;
   
    public Mastermind()
    {
        noseq = new long[4];
        noseq2 = new int[4];
        seq = new String[4];
        eseq = new String[4];
        tmpseq = new char[4];
        white = 0;
        black = 0;
        nm = new String();
        lines = new String[20];
        wordcnt = 0;
    }
   
    public static void timeloop()
    {
        for(double j = 0.0; j < 25000000.0; j++)
        {
        }
    }
   
    public void timeloop2()
    {
        for(double i = 0; i < 7500000000.0; i++)
        {
        }
    }
   
    public void genSequence()
    {
        for(int i = 0; i < 4; i++)
        {
            noseq[i] = Math.round(Math.random()*10);
           
            if(noseq[i] > 6)
            noseq[i] -= 6;
           
            if(noseq[i] < 1)
            noseq[i] += 1;
        }
                    
        for(int i = 0; i < 4; i++)
        {
            noseq2[i] = (int)(noseq[i]);
        }
    }
   
    public void saveSeq()
    {
        for(int i = 0; i < 4; i++)
        {
            switch(noseq2[i])
            {
                case 1: tmpseq[i] = 'G';
                break;
               
                case 2: tmpseq[i] = 'B';
                break;
               
                case 3: tmpseq[i] = 'R';
                break;
               
                case 4: tmpseq[i] = 'Y';
                break;
               
                case 5: tmpseq[i] = 'P';
                break;
               
                case 6: tmpseq[i] = 'O';
                break;
            }
        }
    }
   
    public void assignColours()
    {
        for(int i = 0; i < 4; i++)
        {
            if(noseq[i] == 1)
            {
                seq[i] = "Green";
            }
       
            else if(noseq[i] == 2)
            {
                seq[i] = "Blue";
            }
       
            else if(noseq[i] == 3)
            {
                seq[i] = "Red";
            }
       
            else if(noseq[i] == 4)
            {
                seq[i] = "Yellow";
            }
       
            else if(noseq[i] == 5)
            {
                seq[i] = "Purple";
            }
       
            else if(noseq[i] == 6)
            {
                seq[i] = "Orange";
            }
        }
    }
   
    public void instructions()
    {
        System.out.println();
        System.out.println("There are 6 main colours in this game: Green, Blue, Red, Yellow, Purple & Orange.");
        System.out.println("Each colour has a corresponding letter:");
        System.out.println("G – Green");
        System.out.println("B - Blue");
        System.out.println("R - Red");
        System.out.println("Y - Yellow");
        System.out.println("P - Purple");
        System.out.println("O - Orange");
        System.out.println("The letters written next to the colours are used to select the respective colours during the game.");
        System.out.println("It is recommended that you write down the color code(key) as it will not be displayed again.");
        timeloop2();
               
        System.out.println();
        System.out.println("The computer will select a random sequence of 4 colours out of the 6 main ones.");
        System.out.println("A colour may be repeated.");
        System.out.println("Your job is to deduce the correct sequence of colours in 10 chances.");
        System.out.println("In each chance, you will have to enter your own sequence to see if it matches with the computer’s sequence.");
        System.out.println("After you have entered your sequence, the computer will compare the 2 sequences & display a message.");
        System.out.println("If a colour in your sequence is present in the computer’s sequence at the same position, you will be");
        System.out.println("given a white peg (the word white will be written on the screen).");
        System.out.println("If a colour in your sequence is present in the computer’s sequence but at a different position, you ");
        System.out.println("will be given a black peg (the word black will be written on the screen).");
        timeloop2();
       
        System.out.println();
        System.out.println("Example 1:");
        System.out.println("Computer’s sequence:  Green Blue Red Yellow");
        System.out.println("Your sequence:       Green Orange Yellow Red");
        System.out.println("Display:              1 white & 2 black");
        System.out.println("Green is at the same position in both sequences (1 white).");
        System.out.println("Red is at different positions in the 2 sequences(1 black).");
        System.out.println("Yellow is at different positions in the 2 sequences(1 black).");
        timeloop2();
       
        System.out.println();
        System.out.println("Example 2: ");
        System.out.println("Computer’s sequence:    Orange Orange Purple Yellow");
        System.out.println("Your sequence:         Orange Red Purple Green");
        System.out.println("Display:               2 whites");
        System.out.println("Purple at position 3 in both – 1 white");
        System.out.println("Orange at position 1(your sequence) & position 1(computer’s sequence) – 1 white");
        System.out.println("The orange at position 2(computer's sequence) will not give a black peg as the orange at 1 is giving a white.");
        System.out.println("This holds true for all such cases in the game.");
        timeloop2();
        System.out.println();
       
        wordcnt = 0;
       
        lines[0] = "You will get 10 chances to solve the code.";
        lines[1] = "In every chance, you will have to enter a sequence based on the result of the previous sequence.";
        lines[2] = "The sequence should consist of only the starting letters of 4 colours based on the key displayed earlier.";
        lines[3] = "Example: For Green Blue Red Yellow, you will enter – GBRY (no spaces!!). ";
        lines[4] = "You are now ready to play the game. Good Luck!!! ";
        while(wordcnt < 5)
        {
            timeloop();
               
            for(int i = 0; i < lines[wordcnt].length(); i++)
            {
                System.out.print(lines[wordcnt].charAt(i));
                timeloop();
            }
           
            System.out.println();
            wordcnt++;
        }
        System.out.println();
        System.out.println();
    }
    public void game()throws IOException
    {
        String ch = new String();
        char ch1[] = new char[4];
        white = 0;
        int wh[] = new int[4];
        black = 0;
        int bl[] = new int[4];
        int cnt = 1;
              
        InputStreamReader reader = new InputStreamReader(System.in);
        BufferedReader input = new BufferedReader(reader);
       
        System.out.println("The computer has selected a random sequence of 4 colours. You have 10 chances to deduce it.");
        System.out.println("A final reminder: the 6 colours are - Green, Blue, Red, Yellow, Purple & Orange.");
        System.out.println("PLEASE TURN ON THE CAPS LOCK ON YOUR KEYBOARD AS ALL SEQUENCES HAVE TO BE ENTERED IN CAPITAL LETTERS ONLY!");
        System.out.println();
       
        outer:
        do 
        {
            saveSeq();
           
            System.out.print("Chance " + cnt + ":         ");
       
            ch = input.readLine();
           
            for(int i = 0; i < 4; i++)
            {
                ch1[i] = ch.charAt(i);
            }
           
            for(int i = 0; i < 4; i++)           //white
            {
                if(ch1[i] == tmpseq[i])
                {
                    wh[i]++;
                    ch1[i] = 'Z';
                    tmpseq[i] = 'Z';
                }
            }
       
       
            for(int i = 0; i < 4; i++)           //black
            {
                for(int j = 0; j < 4; j++)
                {
                    if(i != j)
                    {
                        if((ch1[i] == tmpseq[j]) && (ch1[i] != 'Z'))
                        {
                            bl[i]++;
                            ch1[i] = 'Z';
                            tmpseq[j] = 'Z';
                        }
                    }
                }
            }
           
            for(int i = 0; i < 4; i++)
            {
                black += bl[i];
                white += wh[i];
            }
           
            if(white == 4)
            {
                System.out.println();
                System.out.println("Congratulations " + nm + "! You have won the game.");
                break outer;
            }
            
            else
            {
                System.out.print("                                " + black + " Black & " + white + " White");
                System.out.println();
                System.out.println();
               
                for(int i = 0; i < 4; i++)
                {
                    wh[i] = 0;
                    bl[i] = 0;
                }
            }
           
            black = 0;
            white = 0;
           
            cnt++;           
        }
        while(cnt <= 10);
       
        System.out.println();
       
        if(white != 4)
        {
            System.out.println(nm + ", you have been unable to deduce the correct code. You have lost the game.......");
            System.out.println("The correct sequence was:");
            for(int i = 0; i < 4; i++)
            {
                System.out.print(seq[i] + " ");
            }
        }
    }
   
    public static void main()throws IOException
    {
        Mastermind mf4 = new Mastermind();
       
        InputStreamReader reader = new InputStreamReader(System.in);
        BufferedReader input = new BufferedReader(reader);
       
        int ch = 0;
        wordcnt = 0;
       
        lines[0] = "Welcome to Pratik Gandhi's version of the all time classic game - MASTERMIND!!!!!!!";
        lines[1] = "This game is a challenge for people of age 10 & above.";
        lines[2] = "All you need to play this game is a peice of paper, a pen and some logic.";
        lines[3] = "";
        lines[4] = "To get started, type in your name & then press enter.";
        while(wordcnt < 5)
        {
            timeloop();
               
            for(int i = 0; i < lines[wordcnt].length(); i++)
            {
                System.out.print(lines[wordcnt].charAt(i));
                timeloop();
            }
           
            System.out.println();
            wordcnt++;
        }
        nm = input.readLine();
        System.out.println();
        wordcnt = 0;
       
        lines[0] = "To play after reading the instructions, press 1 & then press enter.";
        lines[1] = "To start the game straightaway, press 2 & then press enter.";
        while(wordcnt < 2)
        {
            timeloop();
               
            for(int i = 0; i < lines[wordcnt].length(); i++)
            {
                System.out.print(lines[wordcnt].charAt(i));
                timeloop();
            }
           
            System.out.println();
            wordcnt++;
        }
        System.out.println();
        wordcnt = 0;
       
        ch = Integer.parseInt(input.readLine());
       
        switch(ch)
        {
            case 1:
            {
                mf4.instructions();
                mf4.genSequence();
                mf4.saveSeq();
                mf4.assignColours();
                mf4.game();
            }
            break;
           
            case 2:
            {
                mf4.genSequence();
                mf4.saveSeq();
                mf4.assignColours();
                mf4.game();
            }
            break;
        }
    }
}


CODE ENDS HERE.


That's all for this post.

Hope you enjoyed it!

Pratik.