ROBOTC.net forums
http://www.robotc.net/forums/

Guess the code!
http://www.robotc.net/forums/viewtopic.php?f=1&t=4461
Page 1 of 2

Author:  NeXT-Generation [ Sun Apr 22, 2012 9:38 am ]
Post subject:  Guess the code!

Whoever can guess what this code does gets 1,000,000 :shock: internetz points! (should this be in off-topic? It is about a program....)

Code:
void LookupColorText(int Color, int BrickLoc);

task main()
{
  typedef struct
  {
    bool ColorDefined;
    int WhereDoesColorBelong;
    string DoesColorBelong[6];
  }BRICK_STRUCT;

  BRICK_STRUCT BrickInfo[6];

  for(int i = 0; i <= 5; i++)
  {
    BrickInfo[i].ColorDefined = false;
    BrickInfo[i].WhereDoesColorBelong = 0;

    for(int x = 0; x <= 5; x++)
    {
      BrickInfo[i].DoesColorBelong[x] = "unknown";
    }
  }

  nxtDisplayTextLine(0, "Bk Bl Gr Yl Rd Wt");
  nxtDisplayCenteredTextLine(1, "1  2  3  4  5  6");

  while(true)
  {
    int RandomLoc = random[5];
    int BrickColor = random[5];

    if(BrickInfo[BrickColor].ColorDefined == true)
    {
      LookupColorText(BrickColor + 1, BrickInfo[BrickColor].WhereDoesColorBelong);
      wait1Msec(1000);
    }
    else
    {
      bool FoundUnkownLoc = false;

      while(FoundUnkownLoc == false)
      {
        if(BrickInfo[BrickColor].DoesColorBelong[RandomLoc] == "unknown")
        {
          FoundUnkownLoc = true;
        }
        else
        {
          RandomLoc = random[5];
        }
      }
      LookupColorText(BrickColor + 1, RandomLoc + 1);

      while(nNxtButtonPressed == kNoButton);

      if(nNxtButtonPressed == kLeftButton)
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].ColorDefined = true;
        BrickInfo[BrickColor].WhereDoesColorBelong = RandomLoc + 1;
        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "yes";

        for(int y = 0; y <= 5; y++)
        {
          if(BrickInfo[y].DoesColorBelong[RandomLoc] == "unknown")
          {
            BrickInfo[y].DoesColorBelong[RandomLoc] = "no";
          }
        }
      }
      else
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "no";
      }
    }
  }
}

void LookupColorText(int Color, int BrickLoc)
{
  string ColorText;

  switch (Color)
  {
    case 1:
      ColorText = "Black";
    break;
    case 2:
      ColorText = "Blue";
    break;
    case 3:
      ColorText = "Green";
    break;
    case 4:
      ColorText = "Yellow";
    break;
    case 5:
      ColorText = "Red";
    break;
    case 6:
      ColorText = "White";
    break;
  }

  nxtDisplayCenteredTextLine(3, ColorText + " goes in");
  nxtDisplayCenteredTextLine(4, "bin:  " + BrickLoc);
  nxtDisplayCenteredTextLine(7, "Yes          No");
}


Go ahead, guess! :mrgreen:

Author:  miki [ Sun Apr 22, 2012 11:03 am ]
Post subject:  Re: Guess the code!

mmm, it's a kind of IQ test that checks if user understand color abbreviation ?

Author:  NeXT-Generation [ Sun Apr 22, 2012 11:30 am ]
Post subject:  Re: Guess the code!

miki wrote:
mmm, it's a kind of IQ test that checks if user understand color abbreviation ?


Nope! Guess again! Here's a hint: On-brick proof-of-concept for a l****ing ***** ******

Author:  sumasmreq [ Tue Apr 24, 2012 3:50 pm ]
Post subject:  Re: Guess the code!

It looks like some sort of game where the user has to guess what color goes in which bin. (Kind of like mastermind perhaps?)

Author:  NeXT-Generation [ Tue Apr 24, 2012 4:45 pm ]
Post subject:  Re: Guess the code!

sumasmreq wrote:
It looks like some sort of game where the user has to guess what color goes in which bin. (Kind of like mastermind perhaps?)


Close, but not quite!

Author:  NeXT-Generation [ Wed Apr 25, 2012 5:30 pm ]
Post subject:  Re: Guess the code!

Does anyone want another hint?

Author:  miki [ Thu Apr 26, 2012 4:23 am ]
Post subject:  Re: Guess the code!

Hi NextGen,
While all our friends go nuts trying to guess what's the ultimate purpose of your code (I'd bet on 42), it's my turn to launch a game :-).
The challenge is : Can you optimize you code to be smaller and faster with exactly the same inputs and outputs?
Miki.

PS: this message will not self-destruct in 15 seconds. ... I hope.

Author:  NeXT-Generation [ Thu Apr 26, 2012 9:11 am ]
Post subject:  Re: Guess the code!

miki wrote:
Hi NextGen,
While all our friends go nuts trying to guess what's the ultimate purpose of your code (I'd bet on 42), it's my turn to launch a game :-).
The challenge is : Can you optimize you code to be smaller and faster with exactly the same inputs and outputs?
Miki.

PS: this message will not self-destruct in 15 seconds. ... I hope.


Well, sure, I probably could. But, I don't really have time because BrickWorld Chicago is less than two months away. They're having several competitions, and I needz to buildz ROBOTZ!!!!


P.S. Just wondering..... Has anybody actually tried running this code?

Author:  miki [ Thu Apr 26, 2012 11:35 am ]
Post subject:  Re: Guess the code!

Me at least. I have a lot of time since my main computer is still out of order ;-)

Miki.

Author:  NeXT-Generation [ Fri Apr 27, 2012 9:05 pm ]
Post subject:  Re: Guess the code!

Ok, your mission: Figure out what this code does by the time the weekend ends, that is Monday, or else I'm just going to tell you. And that wouldn't be any fun.

Author:  NeXT-Generation [ Sun Apr 29, 2012 6:38 pm ]
Post subject:  Re: Guess the code!

I'm warning you: If nobody has guessed correctly by 5:00PM, US Central Time, Monday, I will post a solution video.

Author:  RoboDesigners [ Sun Apr 29, 2012 7:38 pm ]
Post subject:  Re: Guess the code!

NeXT-Generation wrote:
Nope! Guess again! Here's a hint: On-brick proof-of-concept for a learning brick sorter

My guess...

Am I right?

//Andrew

Author:  NeXT-Generation [ Sun Apr 29, 2012 8:27 pm ]
Post subject:  Re: Guess the code!

RoboDesigners wrote:
NeXT-Generation wrote:
Nope! Guess again! Here's a hint: On-brick proof-of-concept for a learning brick sorter

My guess...

Am I right?

//Andrew


Annnd...... That is correct!!!!! Here's your prize!!! *hands over 1,000,000 symbolic internetz points* Thank you, and come again to play *fictional audience shouting* "Guess.... That..... Code!!!".

For those of you who don't know, here's some commented code explaining how it works. Each comment will be explaining the line(s) of code it's on, and all those above it until the next comment:

Code:
void LookupColorText(int Color, int BrickLoc);

task main()
{
  typedef struct
  {
    bool ColorDefined;
    int WhereDoesColorBelong;
    string DoesColorBelong[6];
  }BRICK_STRUCT;

  BRICK_STRUCT BrickInfo[6];

  for(int i = 0; i <= 5; i++)
  {
    BrickInfo[i].ColorDefined = false;
    BrickInfo[i].WhereDoesColorBelong = 0;

    for(int x = 0; x <= 5; x++)
    {
      BrickInfo[i].DoesColorBelong[x] = "unknown";
    }
  }

  nxtDisplayTextLine(0, "Bk Bl Gr Yl Rd Wt");
  nxtDisplayCenteredTextLine(1, "1  2  3  4  5  6");//Initialization procedure.  Structure, and structure array created.  All elements of array initialized.

  while(true)
  {
    int RandomLoc = random[5];
    int BrickColor = random[5];//I don't think I need to explain these.

    if(BrickInfo[BrickColor].ColorDefined == true)
    {
      LookupColorText(BrickColor + 1, BrickInfo[BrickColor].WhereDoesColorBelong);
      wait1Msec(1000);
    }//Checks if the color is known.  If it is, then go directly to the known location.  If not, then engage learning procedure (below).
    else
    {
      bool FoundUnkownLoc = false;

      while(FoundUnkownLoc == false)
      {
        if(BrickInfo[BrickColor].DoesColorBelong[RandomLoc] == "unknown")
        {
          FoundUnkownLoc = true;
        }
        else
        {
          RandomLoc = random[5];
        }
      }//This loop applies a random number to put the brick in.  But, we don't want it trying spaces that have already proven to be false.  So, it keeps trying random numbers until it finds an unknown space.
      LookupColorText(BrickColor + 1, RandomLoc + 1);//Displays the brick color and randomly chosen location.

      while(nNxtButtonPressed == kNoButton);

      if(nNxtButtonPressed == kLeftButton)
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].ColorDefined = true;
        BrickInfo[BrickColor].WhereDoesColorBelong = RandomLoc + 1;
        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "yes";

        for(int y = 0; y <= 5; y++)
        {
          if(BrickInfo[y].DoesColorBelong[RandomLoc] == "unknown")
          {
            BrickInfo[y].DoesColorBelong[RandomLoc] = "no";
          }
        }
      }//If you press yes, then it sets ColorDefined to true, the location of the color to the randomly chosen location, that you confirmed, and that same slot in all the other color arrays to "no".
      else
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "no";
      }//If you said no, then it simply sets that slot to "no".
    }
  }
}

void LookupColorText(int Color, int BrickLoc)
{
  string ColorText;

  switch (Color)
  {
    case 1:
      ColorText = "Black";
    break;
    case 2:
      ColorText = "Blue";
    break;
    case 3:
      ColorText = "Green";
    break;
    case 4:
      ColorText = "Yellow";
    break;
    case 5:
      ColorText = "Red";
    break;
    case 6:
      ColorText = "White";
    break;
  }

  nxtDisplayCenteredTextLine(3, ColorText + " goes in");
  nxtDisplayCenteredTextLine(4, "bin:  " + BrickLoc);
  nxtDisplayCenteredTextLine(7, "Yes          No");
}//This function simply takes two variables, the brick color and the location, and displays them with the proper additions.


P.S. Here's the demo video anyway.


Sorry if I rambled. I was a bit tired when I took this.

Author:  Spiked3 [ Mon Apr 30, 2012 12:24 pm ]
Post subject:  Re: Guess the code!

Cool stuff again, as usual. When will the .LDD file be up ? :)

Author:  NeXT-Generation [ Mon Apr 30, 2012 12:34 pm ]
Post subject:  Re: Guess the code!

Spiked3 wrote:
Cool stuff again, as usual. When will the .LDD file be up ? :)


Umm, I think your joking, right? This was just running on the virtual emulator. It was just the code, with no physical interface.

P.S. Thanks! :wink:

Page 1 of 2 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/