#### Archived

This topic is now archived and is closed to further replies.

# Strangest Piece of Code

This topic is 6147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Post the strangest piece of code you or someone else has written! Mine:
  //before int a int b int e //SNIPPET void SlowComputerDown(e) { for(a=0; a<=(computer_speed()*e); a++;)//computer speed { //was found in another b+=a //function } } 
But still, I''d have to say, the code was still slow without it (it was a 16bit program, that ran slowly...)

##### Share on other sites
You know, no matter how many times I look at this code, I still can''t recall how I arrived at it. Some parts make perfect sense, but others...

  bool CheckMove(int X, int Y, direction Move){ if(Move==LEFT) { if(X==1)//Is the left wall in the way? return false;//Move is illegal if((Y!=1) && (Y!=((2*level_size)+1))) { if((((X-1)%2)==0) && ((Y%2)==0))//Is there a block in the way? return false;//Move is illegal } } else if(Move==DOWN) { if(Y==1)//Is the bottom wall in the way? return false;//Move is illegal if((X!=1) && (X!=((2*level_size)+1))) { if((((Y-1)%2)==0) && ((X%2)==0))//Is there a block in the way? return false;//Move is illegal } } else if(Move==RIGHT) { if(X==((2*level_size)+1))//Is right wall in the way? return false;//Move is illegal if((Y!=1) && (Y!=((2*level_size)+1))) { if((((X+1)%2)==0) && ((Y%2)==0))//Is there a block in the way? return false;//Move is illegal } } else if(Move==UP) { if(Y==((2*level_size)+1))//Is top wall in the way? return false;//Move is illegal if((X!=1) && (X!=((2*level_size)+1))) { if((((Y+1)%2)==0) && ((X%2)==0))//Is there a block in the way? return false;//Move is illegal } } return true;//Passed all tests, the move is legal}

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."

##### Share on other sites
This thing is called "Duff''s device". Apparently, it''s some awesome optimization from back in the day

This was taken from the C FAQ: http://www.faqs.org/faqs/C-faq/faq/

  register n = (count + 7) / 8;switch (count % 8){case 0: do { *to = *from++;case 7: *to = *from++;case 6: *to = *from++;case 5: *to = *from++;case 4: *to = *from++;case 3: *to = *from++;case 2: *to = *from++;case 1: *to = *from++; } while (--n > 0);}

##### Share on other sites
Oh dear! I am rather embarrased by this ...
  for(i=0;i

Edited by - Martee on January 16, 2002 2:06:30 AM

##### Share on other sites
  void Do_What_I_Mean_God_Dammit() { //To be completed later...} `

Edited by - Graylien on January 16, 2002 2:11:28 AM

##### Share on other sites
heehee, Martee.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633313
• Total Posts
3011319
• ### Who's Online (See full list)

There are no registered users currently online

×