hacker

Examination Stereotypes

Exams have a weird effect on people. They affect different people differently. Let’s look at some examination stereotypes.

The Predators

The Evil Teacher

teacher

Some teachers just love to make the lives of their pupils miserable. Their torture increases exponentially during the exams. When they make the exam they try their best to use the obscurest terms and the weirdest grammar known to the English language. Even if you know the answer, you spend hours simply trying to decipher the different levels of meaning hidden in the question, until you develop schizophrenia and start believing the modern education system was developed by the Illuminati to torture the new generation and force them to yield. Here’s an example.

What the teacher is really asking:

What is Newton’s second law?

The question she writes in the exam:

State the sacred arrangement of words and symbols that is widely believed to be the second testament of the Enlightened One who was hit arbitrarily by a scarlet apple in the days of yore.

The scope of her exam too, leads one to suspect the involvement of sinister forces…

What she teaches: 2x + 4 = 5

What she gives in the exam:

standard_model

The Conniving Head-mistress

principal

Armed with her evil grin and her time-table organizing capabilities, she is a force to be reckoned with. She excels in the art of making the worst possible exam schedule in order to ensure a sleepless night for her students. I can imagine her though process…

Hmm.. Let’s see. I have eight subjects and two weeks. I can of course give two holidays before each science subject and one holiday before each arts subject to give the students ample time for preparations and revision. But that’s too main-stream. Let’s spice things up a little. Why don’t I give 4 holidays before English Language, an exam that doesn’t need any revision at all, while give no holiday for Physics? That would be fun. Better still, why don’t I schedule the Maths and Physics exams on the very same day? Hmm… that is pure genius. Muhahahahaha!

The Macho Invigilator

invigilator

These people are nightmares. Their purpose in life is to cancel papers. A slight whisper, and they come running at you and write a huge “Cancelled. Cheated.” on your exam sheet. If they can’t find a culprit, they just select some random person sitting nearby, invent something up, claim to have seen him cheating and cancel his paper. I think they have a secret competition or something. The invigilator who cancels the most papers in a single exam session wins.

The Parasites

The Nervous (Lazy) Guy

nervous

These are usually the people who cared least about their academic standing during regular school days. Some of them suddenly get this exam-phobia that totally makes them go bananas. They will begin irritating their class-mates by asking them to explain stuff which they did not understand (or even listen to) earlier because they were too busy cussing each other and being a general nuisance in regular classes. They don’t actually study either, their nervousness and concern is only limited to the class where they can use it to annoy people in the vicinity.

The New ‘Best-Friend’

exams

These are the people who, in normal school-days, are extremely rude to you. They make fun of you constantly, make racist remarks and annoy you in class. However, suddenly, a day or two before the exams their behaviour alters drastically. They start sitting beside you, start back-biting about other people in front of you to instill a sense of alliance or something, start hanging out with you in the school break and stuff. Then half an hour before the exam they’ll say something like this in a half-conversational, half-threatening tone, “Why of course you’ll help me out in the exams won’t you? Just tilt your sheet a little when I whisper the question I want to see. You’re my best-friend…”.

The Prey

The ‘Don’t Care, Didn’t Study’ Guy

NERD

These people spend all night studying hard for the exam. They have every concept and equation on their fingertips, but yet act as if they don’t know a thing. When people come and ask them stuff, they act stupid. But somehow they always manage to get surprisingly good marks. I always wondered why they act stupid. Perhaps they do this to protect themselves from being victimised by the New ‘Best-Friend’ and the Nervous (Lazy) guys.

The Evil Nerds

evil_nerd

These guys are evil. Evil, I tell you! The teacher gave something out of syllabus in the exams? “No problem, Miss. We know it.” Speak for yourself, dammit! The teacher forgot to take the test today? “Miss, today was the test…”. Curse you! The teacher forgot to give the homework? “Miss, what is the homework?” You son of a …! The teacher is absent? “Let’s go to the principal and demand a substitute teacher.” Kill yourself.

People Like Me

me

These guys are complete punch-bags. They are moderately affected by the examinations. They get victimised by the parasites. They get bullied by the predators. And all they can do about it is write ambiguous blog posts.

The Legendary Rickshay Wala

pakistan_wallpaper_by_mu6_by_mu6-d3l8d3x

Inspired by Dr. Adil Najam’s old blog All Things PakistanI decided to make my own contribution to describing some of the unique aspects of Pakistan and Pakistaniat. However, I ran into a problem. What is the most unique aspect of Pakistan? Well, at first I thought about the things I like about Pakistan. These include the Pakistani culture, prestigious Pakistani institutions like LUMS, NUST etc., the LUMS Olympiad, Pakistani schools, Pakistani students, the Pakistani Army, the Pakistani Air-force, the Pakistani Atomic Energy Commission, the Pakistani cricket team, Dr. Pervez Hoodbhoy, Dr. Abdus Salam, Imran Khan, Wasim Akram, Javed Miandad and the various other Pakistanis who’ve made us proud. However, I was not particularly inclined to write about any of these great people and organizations. So, I tried the opposite tact. I thought of the things I hate about Pakistan. Well, there was Agha Waqar, load-shedding, corruption, the Taliban, terrorism, sectarian terrorism, broken roads, Rehman Malik etc. What else did I hate? And then I finally hit upon it… the Rickshay Walas.

rickshaw

The Rickshay Walas aren’t just unique, they’re legendary! Their disregard for traffic rules, their epic turns, their bizarre stunts and their sky-rocketing charges make them a force to be reckoned with.  The most astounding thing about Rickshaws is their tendency to do things that defy both classical and modern Physics. There are three cases where the laws of classical Physics break down, a big-bang, a black hole and a Rickshaw. They should make “Need for Speed: Rickshaw Edition”. Seriously, I’ve seen Rickshaws going faster than the speed of light. Take that, CERN!

karachi_rickshaw

It isn’t just the stunts that make-up the legendary Rickshay Wala. A true Rickshay Wala should also have catastrophic driving skills. By “catastrophic”, I don’t mean those ordinary mistakes people do such as driving in the opposite directing on a one-way road or overtaking someone without flashing an indicator. In order to become a Rickshay Wala, one has to do something really catastrophic, something that will not only affect you, but will ensure that everyone in a 50 km radius stays jammed in traffic for the next two hours. Examples include parking your rickshaw in the middle of the road in order to go out and greet a friend you saw walking on the foot-path, not looking at the traffic signals and colliding head-on with the on-coming traffic, and trying to drive through the middle of two cars with less than one inch of free space between them, hitting both cars as a result. It is things like this that distinguish an ordinary driver from a Rickshay Wala.

Another commendable quality of a Rickshay Wala is the ability to feel completely at home on a busy road. This is especially useful when arguing after an accident. I’ve seen cases where Rickshay Walas have won a road-side argument, even when the accident was clearly their fault, just because the other person was too tired to continue arguing.

rickshaw-Wisdom

Perhaps one of the best things about a rickshaw is the great literary and artistic work printed at its back. The exquisite language and unique style surpasses even Homer and Shakespeare. Forget about universities and libraries. The next time I want to read quality literature and poetry, I’ll drive behind a rickshaw. In my opinion, one should automatically be awarded a PhD. in literature after reading things written on the back of more than 20 Rickshaws.

Chapter 3 – A Text-Based Console World

First, let’s focus on the game logic. For now I won’t start using pixel graphics and just use the console. Let’s create a little ASCII adventure to stretch our legs. Now keep in mind that the logic remains the same regardless of the interface I’m using. Hence the logic code I write for an ASCII Console Game can be pretty easily adapted to work with a Windows Graphics Game.

Here’s a rough working sketch of the game:


/////////////////////////////////////
// Simple ASCII Console World
// Author: Muhammad Ahmad Tirmazi
// Date: 12 July 2012
// License: BSD 4-Clause
/////////////////////////////////////

#include <cstdlib>
#include <windows.h>

#include <iostream>
#include <string>
#include <vector>

// Our Custom Namespace
namespace pro {

///////////////////////////////
// Just a typedef for 'char'
///////////////////////////////
typedef char GameTile;

///////////////////////////////
// Simple Point Class
// Holds the X and Y values
// of a 2D Object
//////////////////////////////
template< typename T > struct Point
{
    Point(void) : X(0), Y(0) {}
    Point(T x, T y) : X(x), Y(y) {}
    T X;
    T Y;
};

/////////////////////////////
// Simple GamePlayer Class
// For controlling the
// Main Character
/////////////////////////////
struct GamePlayer
{
    Point< int > Position;
    GameTile Tile;

    GamePlayer(std::vector< std::string >& map);

    void MoveLeft(std::vector< std::string >& map);
    void MoveRight(std::vector< std::string >& map);
    void MoveUp(std::vector< std::string >& map);
    void MoveDown(std::vector< std::string >& map);

    void Draw(void);
};

//////////////////////////////////////////
// Constructor
// Sets the Player's original position
// 1 is the code for a happy face
/////////////////////////////////////////
GamePlayer::GamePlayer(std::vector< std::string >& map)
    : Position(2, 2), Tile(1)
{
    if (map[Position.X][Position.Y] == ' ')
    {
        map[Position.X][Position.Y] = Tile;
    }
    else
    {
        std::cerr << "Player's Tile is Occupied" << std::endl;
    }
}

//////////////////////////////////////////
// Moves the Player 1 Tile To the Left
/////////////////////////////////////////
void GamePlayer::MoveLeft(std::vector< std::string >& map)
{
    // If the tile is empty
    if (map[Position.Y][Position.X - 1] == ' ')
    {
        // Remove our player's tile from it's original position
        map[Position.Y][Position.X] = ' ';

        Position.X --;
        // Fill it with our player's tile
        map[Position.Y][Position.X] = Tile;
    }
}

//////////////////////////////////////////
// Moves the Player 1 Tile To the Right
/////////////////////////////////////////
void GamePlayer::MoveRight(std::vector< std::string >& map)
{
    // If the tile is empty
    if (map[Position.Y][Position.X + 1] == ' ')
    {
        // Remove our player's tile from it's original position
        map[Position.Y][Position.X] = ' ';

        Position.X ++;
        // Fill it with our player's tile
        map[Position.Y][Position.X] = Tile;
    }
}

//////////////////////////////////////////
// Moves the Player 1 Tile Upwards
/////////////////////////////////////////
void GamePlayer::MoveUp(std::vector< std::string >& map)
{
    // If the tile is empty
    if (map[Position.Y - 1][Position.X] == ' ')
    {
        // Remove our player's tile from it's original position
        map[Position.Y][Position.X] = ' ';

        Position.Y --;
        // Fill it with our player's tile
        map[Position.Y][Position.X] = Tile;
    }
}

//////////////////////////////////////////
// Moves the Player 1 Tile Downwards
/////////////////////////////////////////
void GamePlayer::MoveDown(std::vector< std::string >& map)
{
    // If the tile is empty
    if (map[Position.Y + 1][Position.X] == ' ')
    {
        // Remove our player's tile from it's original position
        map[Position.Y][Position.X] = ' ';

        Position.Y ++;
        // Fill it with our player's tile
        map[Position.Y][Position.X] = Tile;
    }
}

} // namespace pro

////////////////////////////////
// A Character Representation
// Of Our Tile Map
///////////////////////////////
static std::string tileMap[] = {

"==========",
"=        =",
"=        =",
"=        =",
"=        =",
"=        =",
"=        =",
"=========="
};

/** Not recommended, but works for simple stuff... **/

///////////////////////////////////////////////////
// Calculates the vertical length of the tile map
//////////////////////////////////////////////////
static int mapLenght = sizeof(tileMap) / sizeof(tileMap[0]);

///////////////////////////////////////////////////
// Calculates the horizontal width of the tile map
///////////////////////////////////////////////////
static int mapWidth = tileMap[0].size();

///////////////////////////////////////////////////////////////
// Vector, to prevent us from dealing with the lousy pointer
// arithmetic that comes with arrays
///////////////////////////////////////////////////////////////
static std::vector< std::string > tileVector(tileMap, tileMap + mapLenght);

//////////////
// The player
//////////////
static pro::GamePlayer player(tileVector);

////////////////////////
// Draws the Tile Map
///////////////////////
void Draw(void)
{
    std::system("cls");

    for (int y = 0; y < mapLenght; y++)
    {
        for (int x = 0; x < mapWidth; x++)
        {
            std::cout << tileVector[y][x];
        }

        std::cout << "\n";
    }
}

//////////////////////////////////////
// Gets and Responds to user input
// from the keyboard
/////////////////////////////////////
bool GetInput(void)
{
    if (GetAsyncKeyState(VK_UP))
    {
        player.MoveUp(tileVector);
    }
    else if (GetAsyncKeyState(VK_DOWN))
    {
        player.MoveDown(tileVector);
    }
    else if (GetAsyncKeyState(VK_LEFT))
    {
        player.MoveLeft(tileVector);
    }
    else if (GetAsyncKeyState(VK_RIGHT))
    {
        player.MoveRight(tileVector);
    }
    else
    {
        return false;
    }
    return true;
}

//////////////////////////////////////////
// Exit when the player presses 'Escape'
/////////////////////////////////////////
bool CheckExit()
{
    if (GetAsyncKeyState(VK_ESCAPE))
    {
        return true;
    }

    return false;
}

//////////////////////////////////
// The main entrypoint function
/////////////////////////////////
int main()
{
    bool open = true;

    Draw();

    /////////////////////////
    // The Main Game Loop
    ////////////////////////
    while (open)
    {
        ////////////////////////////////////////////
        // Redraw if the player's position changes
        ////////////////////////////////////////////
        if (GetInput()) Draw();

        if (CheckExit()) open = false;
    }

    return 0;
}

Some Issues

  • GetASyncKeyState() and system(“cls”) are not cross-platform, we may need to use something else
  • We may need to make the code more comprehensive, object-oriented and improve the design
  • We still need to code the player’s interaction with other tiles

Writing Cross-platform Code

Although the above code will probably compile without any errors on most versions of Windows, there are a few things that may not work well on other operating systems such as Ubuntu etc. Firstly, I use a system call for clearing the screen. One solution to making the call cross-platform is to use pre-processor definitions to find out what platform we’re compiling on and use that system’s specific command for clearing the screen. For example:

void clear_screen(void)
{
    #if defined (WIN32) || defined (_WIN32)
    
    system("cls"); // use the "cls" command on windows
   
    #else
   
    system("clear"); // otherwise use the unix "clear" command

    #endif
}

Secondly, I use GetASyncKeyState() for input, which is a windows api function and hence is only supported on windows.

The best thing for writing cross-platform code is to use a third-party cross-platform library.

Developing a Rogue-Like Top-Down RPG Game in SFML

I’ve been busy developing one of those old-school 2d RPG games in the past week. It’s still far from complete, but I thought I should just document a bit of the development process. Firstly, I chose the Simple and Fast Media Layer (SFML) API for graphics, sound and input processing. Why? Because unlike SDL it has a C++ OOP Interface and I don’t have to deal with all the ugly C stuff and Pointers. It could have been a bit better though, if it implemented exceptions instead of returning error codes. For example

try
{
    img.LoadFromFile("my_img.png");
}
catch(ImageNotLoadedException& e)
{
    ...
}

Is much better, in my opinion, than

if (!img.LoadFromFile("my_img.png")
{
    ...
}

Anyway… Where was I?

Well, I began with creating some custom classes. I created a Player class for the main character. Next I created a Tile class for the RPG tiles. I derived both of them from sf::Sprite. Next I created three classes for level parsing. LevelReader, LevelSymbolTable and LevelRenderer. Although I am parsing the level line-by-line instead of character-by-character, it still works pretty well. A typical level script for the game looks like this:


// Level 1 Map
// Comments start with '//'
// Symbol -> Tile Assignments start with '=>'

=> G ? data/tiles/grass.png ? false
=> W ? data/tiles/wall.png

// Symbol Representation of the Map
WWWWWWWWWWWWWWW
WGGGGGGGGGGGGGW
WGGGGGGGGGGGGGW
WGGGGGGGGGGGGGW
WGGGGGGGGGGGGGW
WGGGGGGGGGGGGGW
WWWWWWWWWWWWWWW

Now the above script renders this:

The syntax for a symbol – tile assignment is

=> {Symbol} ? {Filename} ? optional {Solid} ? optional {depth}
// e.g
=> A ? Wall.png

All tokens are separated by a ‘?’. The first token is the symbol which is later used for representing the tile in the map. The second token is the filename of the tile’s image. The third optional token is for setting whether the tile is solid or not. If the tile is solid, it will collide with the player. Otherwise, the player will just walk over it. Hence the ‘false’ at the end of the assignment for ‘G’ tells the level parser not to make the player collide with the grass tile. Finally the last optional token, ‘depth’, sets the depth level of the tile. It should be a value between 1 and 3. Tiles with depth 1 will be drawn first, followed by tiles with depth 2 and then depth 3. Depth 1 and 2 are drawn before the main character, depth 3 tiles are drawn after the main character, hence the player will walk under tiles with depth 3.

Next, I wrote code for camera management, so that the main character can scroll around even if the level script is bigger than the screen resolution. I also wrote collision detectors and handlers.

Currently I’m coding a ‘text area’ class in order to display updates and messages. I’m in a hurry right now, so I’ll explain the whole process of developing the game in detail in later posts, perhaps even create some tutorials.

Callbacks, Objects and Private Methods in C?

I’ve been tinkering with C  for a few hours after getting a bit tired of all the OOP and C++.  I just tried to do some high-level stuff, and here’s one or two ideas that worked. I don’t recommend any C++ developers to start using these instead of the good old OO System. That would be re-inventing the wheel. I’m just sharing these because they seem interesting.

pro_lang.h

/* header guards etc. */

typedef struct _Pro_Object Pro_Object;

struct _Pro_Object
{
    /* members */
    int money;

    /* callbacks */
    void (*on_print)(Pro_Object*);
    void (*on_start)(Pro_Object*);
};

Pro_Object* pro_object_new( void );

/* inline functions */
#define pro_object_set_money( obj, v ) obj->money = v
#define pro_object_get_money( obj ) obj->money

/* methods */
void pro_object_print_money( Pro_Object* );
void pro_object_start_up( Pro_Object* );

pro_lang.c

/* Simply declare private methods as 'static'
   in your source file! */

static void pro_object_init( Pro_Object* obj );

Pro_Object* pro_object_new( void )
{
    Pro_Object* obj = (Pro_Object*) malloc( sizeof( Pro_Object ) );
    pro_object_init( obj );
}

void pro_object_init( Pro_Object* obj )
{
    obj->money = 0;

    obj->on_print = NULL;
    obj->on_start = NULL;
}

void pro_object_start_up( Pro_Object* obj )
{
    if ( obj->on_start ) ( *obj->on_start )( obj );
}

void pro_object_print_money( Pro_Object* obj )
{
    printf( "\nMoney : %i \n", obj->money );
    if( obj->on_print ) ( *obj->on_print )( obj );
}

main.c

void print_callback( Pro_Object* obj )
{
    printf( "THIS IS A PRINT CALLBACK! \n" );
}

void start_callback( Pro_Object* obj )
{
    printf( "\nTHIS IS A START CALLBACK! \n");
}

int main()
{
    /* constructor */
    Pro_Object* obj = pro_object_new();

    /* testing the methods and inline functions */
    int tmp = pro_object_get_money( obj );
    printf( "Default Money Value: %i \n", tmp );

    pro_object_set_money( obj , 23 );

    tmp = pro_object_get_money( obj );
    printf( "New Money Value: %i \n", tmp );

    /* setting the callback functions */
    obj->on_print = print_callback;
    obj->on_start = start_callback;
    
    /* these will call the callback functions */
    pro_object_start_up( obj );
    pro_object_print_money( obj );

    /* destructing */
    free( obj );

    return 0;
}

Output

Default Money Value: 0
New Money Value: 23

THIS IS A START CALLBACK!

Money : 23
THIS IS A PRINT CALLBACK!

I hope to learn more about C’s latent potential and the various creative ways of unleashing it. I’ll post more discoveries…. as soon as I discover them 8-) .

Mom’s Calling


"Muhammad!!!" comes the dynamic shout,
   Come on, help me, stop wandering about!

"Muhammad!!!" comes the angry roar,
   Don't hang around, don't yawn, don't snore!

"Muhammad!!!" comes the valiant cry,
   Stop that! Come here, hang the clothes to dry!

"Muhammad!!!" comes the horrifying moan,
   Hurry up! Help me, I'm working alone!

"Muhammad!!!" comes the endless chant, 
   Come here quickly, can't you hear my rant?

~ Muhammad Ahmad Tirmazi

An Ode To Examinations

O' Level exams are coming up, my spirits are going down Exam tensions are heating up, anxiety spreading all around! Not a whisper, not a sound I already know I'm doomed to drown! O' Level exams are coming up, my spirits are going down Exam tensions are heating up, anxiety spreading all around! I'm doomed as I said, that is all I'm doomed to fail, no doubt no poll! I'm doomed can't you hear? There's no doubt By this time next year, I'll be down and out! I'm doomed, you fool, why can't you comprehend? It's the final straw, the invasion, the end! I'm doomed to failure, let me emphasize it some more There's a cyclone, and my ship is off-shore! I'm doomed as you know, now I'm overdoing it But that's the plain truth, there's no denying it! O' Level exams are coming up, my spirits are going down Exam tensions are heating up, anxiety spreading all around! Oh! Can't you hear the dooms-day count? The Grim-Reaper is roaming about! Oh! You ask, what am I sulking about? I say it's the exams, I'll fail no doubt! O' Level exams are coming up, my spirits are going down Exam tensions are heating up, anxiety spreading all around! The supervisors tell me to cover my working But what is there to hide? I didn't write a damn thing! As you know, I'm doomed, didn't learn a thing Even now, instead of learning, I sing! With a heavy heart, I'm writing this ode Cuz' all the books seem to be in machine code!

by Muhammad Ahmad Tirmazi