Karel++ Noob help

Ok, heres the story… I got this nifty new Karel++ book today in my intro to Computer Programming class. In my haste to learn I read waaaay ahead and thought of a neat thing to do. I based the length of move commands in how you write the word “move” It is binary based using capitals for on/off.
example:

movE—move one space
moVe—move two spaces
moVE—move three spaces
ect…

The skinny is M=8, O=4, V=2, E=1.

Here is the actual code… the task it performs is just filler to make it a complete code.

class robot_pwn: ur_robot{
	void movE( ); //1
	void moVe( ); //2
	void moVE( ); //3
	void mOve( ); //4
	void mOvE( ); //5
	void mOVe( ); //6
	void mOVE( ); //7
	void Move( ); //8
	void MovE( ); //9
	void MoVe( ); //10
	void MoVE( ); //11
	void MOve( ); //12
	void MOvE( ); //13
	void MOVe( ); //14
	void MOVE( ); //15
	void turnRight( ); //self explanatory genius
	
};

void robot_pwn :: movE( )
{
	move( );
}

void robot_pwn :: moVe( )
{
	move( );
	move( );
}

void robot_pwn :: moVE( )
{
	move( );
	move( );
	move( );
}

void robot_pwn :: mOve( )
{
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: mOvE( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: mOVe( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: mOVE( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: Move( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: MovE( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: MoVe( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: MoVE( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: MOve( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: MOvE( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: MOVe( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: MOVE( )
{
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
	move( );
}

void robot_pwn :: turnRight( )
{
	turnLeft( );
	turnLeft( );
	turnLeft( );
}

task
{	robot_pwn Blitz(1,1, East, 9); //w00t w00t for 9 beepers
	Blitz.turnOff( ); //sad existence for such a complicated binary-move code
} 

Anyone out there with any Karel++ experince… please let me know if what I attempted is possible.

n00b coder,

-Henry

I don’t know Karel++, but it’s definitely possible with almost any other language, so it probably is.

One thing, from looking at your code: you might want to (at the very least) have it loop over the "move();"s There’s probably something called along the lines of a C/C++ “for” loop where you (basically) specify where the loop starts and where it ends.

You could also go for actually determining the actual value of the string, which shouldn’t be that hard, even in a language with mostly low-level string stuff. Then, use that value to determine how many times you move. (If you have a for loop then, you can just stick the variable in instead of a hard value.)

Why not

class robot_pwn: ur_robot
{
	void movE( int n );
};

void robot_pwn :: movE( int n )
{
	int i
	for(i=0; i <= n; i++)
	{
		  move( );
	}
}

I hope this is the correct syntax, but you get the idea. You pass the number of “moves” you want to a function and it loops through the move funtion for that number of times. You wouldn’t need a bunch of functions and be limited to 15 moves. You could put (depending on the compiler’s limits) put 10,000 moves. You can then add whatever else, like turnRight(int degree); and turnLeft(int degree); for how far you want to turn.

Ok, I just took a crash course in Karel++. That was the fastest I’ve ever learned a new language. For those of you who are wondering, it turns out that Karel++ is the language you would get if LOGO and C++ had a child that was raised by BASIC (not sure how that works, but that’s what it looks like to me).

Karel++ doesn’t have a “for” loop, but it does have “loop” loop.


loop(5)
{
  move(); //calls move() 5 times
}

I’m not sure if it supports non-void functions (or “instructions” as they seem to be called). All the examples I found don’t take or return parameters in the functions. Because of the way the language is designed, I suspect that the following code might work, but I don’t have Karel++, so I can’t test it.


void movenum(n)
{
  loop(n)
  {
    move();
  }
}

Just as some general advice: Whenever possible, it’s a good idea to make multipurpose code. Your example of using 15 separate functions works, but it’s not very clean. If you wanted to expand it for some reason, you might have a hard time doing so because it only does one thing. It also makes it hard to read any code that uses those functions.

OK guys. thanks for the help.
I am going to test the code tomorrow with a list of random tasks just to make sure all of the loops that I put in will read.

The purpose of this is to get an all functioning robot. I am going to go through the book I have and code in all of the shortcuts and pre-programmed moves. Then I am going to work on autonomous beeper harvesters for any situation.

On second thought… now that I know the loop function… I don’t need all of what I just did. It would be pretty funny though, when one of my classmates reads my programs and says “HEY! How come your robot moves 9 time when all you have here is ‘MovE’ once !!!”