language-agnosticcode-golfrosetta-stone

Code Golf: 2D Platformer


The Challenge

Disallowed

How To

Your program receives the level below(without line breaks) via standard input.
It then has to print out a commands which are needed to successfully complete the level.

The Level

All levels are 4 lines height, with each of the lines 63 chars wide. That makes a total of 252 characters per level.

>                       ______  ____       ________  ___        <
>    C            ______|    |  |  |  C  __|      |  | |   ____E<
>S______  __  ____|          |  |  |_____|        |__| |___|    <
>       xx  xx                xx                                <

Notes: The >< are just to illustrate the borders, they are NOT included in the input to your program. Also watch out for your text editor, as mine screwed up the whitespace a number of times

The Commands

The Solution(With Coin Blocks)

Successive commands are stacked on top of each other.
F indicates where you will fall(remember you can't do anything while falling),

                            MMMF                 MMMF            
    M                 MMMMMMJ  MMMMF M   MMMMMMMMJ  MMMF        
M   J MMMFMMMF  MMMMMMJ|    |  |  |F J MMJ|      |  | |F MMMMME
SMMMJMJ  MJ  MMMJ|          |  |  |MMJMJ|        |__| |MMJ|    
       xx  xx                xx                                

Resulting command sequence, 75 characters long:

MMMMJJMMJMMMMJMMMMMMJMMMMMMJMMMMMMJMMMMMMMMMJJMMJMMJMMMMMMMMJMMMMMMMMJMMMMM

Hope this yields some interesting results... and not tons of flames :O

EDIT

OK, there are way more possibilities than I initially thought of, I apologize for all the edits.


Solution

  • Javascript:

    Short Version (334 280 256 240 238 236 233 223 207 205 196 184 182 characters)

    a=prompt();j=i=0;while(a[++j*63]<(o="M"));while(++i<62){while(a[h=j*63+i]<"_")j++;if(a[h-63]>"B")o+="JJ";if(a[h+1]>"z")o+="J",j--;if(a[h+3]+a[h+1]=="_ ")o+="JMM",i+=2;o+="M"}alert(o)
    

    Note: The Javascript method prompt tends to remove space on some browser (ex.: Google Chrome). It might not work as expected for that reason for those browsers. On others (ex.: Firefox), it will work fine.

    Commented Version

    a=prompt(); // Read the input //
    j=i=0;
    while(a[++j*63]<(o="M")); // Place the cursor at the "S" //
    while(++i<62){ // While we are not at the end point //
     while(a[h=j*63+i]<"_")j++; // If we are on a space, we fall //
     if(a[h-63]>"B")o+="JJ";// We jump for coins //
     if(a[h+1]>"z")o+="J",j--; // We jump when we reach a wall //
     if(a[h+3]+a[h+1]=="_ ")o+="JMM",i+=2; // We jump on gap //
     o+="M" // We add the movemment in the output
    }
    alert(o) // Output