Sure, it is mine, slighty decrypted. I suspect gcc -E (or was it -S) and indent..exomo wrote:Anybody know this code?
=>SPOILER<=
Let me explain the exomo-ned code via comments
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
// My sole variable. It has 32 bits.
// IIRC (if I remember correctly):
// Bit 01-01: player
// Bit 02-10: whether a position of the board has been used
// Bit 11-19: the player that used this square, undefined if it
// is not in use.
// Bit 20-23: 4 bits for a runner from 1 to 15.
// Bit 24-31: 8 bits for reading a character from stdin/cin.
// Bit 32 : Erm.. backup bit, just in case one fails...
unsigned b;
// The joke line. In the original, it was [b]extern[/b] char JOKE.
// JOKE[0] is the character that is used for drawing pieces for p0.
// JOKE[1] is the character that is used for drawing pieces for p1.
char JOKE[100] = "#&*^(*=@#^*_: &%(#%)(#&#%@&(*: Don't run me on a c-compiler!";
// The routine to [b]c[/b]heck for "winning lines".
// It actually depends on x. See also main().
// USED OR NOT:
// (bit2>>1) 1 (bit3>>1) 2 (bit4>>1) 4
// (bit5>>1) 8 (bit6>>1) 16 (bit7>>1) 32
// (bit8>>1)64 (bit9>>1)128 (bit10>>1)256
// PIECE DISTRIBUTION:
// (bit11>>10) 1 (bit12>>10) 2 (bit13>>10) 4
// (bit14>>10) 8 (bit15>>10) 16 (bit16>>10) 32
// (bit17>>10)64 (bit18>>10)128 (bit19>>10)256
void C(unsigned x)
{
if(!(b&x)) // Check if all pieces for this lines are used.
if(((b>>10)&(x>>1))==(x>>1)||((b>>10)&(x>>1))==0)
{//Exactly all 3(?) bits are used. Either player 0 or 1.
puts("Win!");
exit(0);
}
}
int main(void)
{
// b start as zero (global variable). += is the same as = here.
// This line should read:
// b += 1 //*2*/2
// ? 1022 : puts (JOKE) < 0, puts ("");
// A c++-compiler reads: b += 1 ? 1022 etc. (Note 1 != 0.)
// A c-compiler reads: b += 1 / 2 ? 1022 etc. (Note 1/2 == 0.)
// The comma-operator add nothing. Could have been a ';'.
// Note: the board is hereby initialized with ONES, meaning the
// board is empty. (Or all zero with c-compilers.)
b+=1?1022:puts(JOKE) < 0 ,puts("");
// Board drawing routine.
// Need at least 4 bits. Used bits 20-23.
// After every 3, a newline must be drawn, hence the use of puts()
// A "good" compiler complains when there is no expression
// between '?' and ':'. I had to insert a dummy '1' :(
for(b&=~(0xf<<19);((b>>19)&0xf)<9;b+=(1<<19),((b>>19)&0xf)%3?1:puts("|"))
// Write space if not used, otherwise a character from JOKE.
// Btw: 022 / 11 == 1.
printf("|%c",b&(2<<((b>>19)&0xf))?' ':JOKE[(b>>(10+((b>>19)&0xf)))&(022/11)]);
// For my art, I sometimes had to insert dummy code:
// 3/2 == 1. Oh well. It obfuscates it a bit more 8)
printf("Player%2d:",b&3/2);
// While the board is not completely filled.
// (C programma won't enter this loop.)
while (b&1022)
{
// Clean bits 24-31.
b&=~(0x1ff<<23);
// Store the character read from keyboard.
b|=(getchar()<<23);
// NOT SURE: 8th bit of the character set
// => not a "real" character.
if(b&(1<<31)) break;
// Check if the character is between 1 and 9.
// Check if the position on the board has been used.
// Note: b >> 23 is the character read from keyboard.
if(((b>>23)-'0')>=1&&((b>>23)-'0')<=9&&(b&(1<<((b>>23)-'0'))))
{
// Mark that this position is in use.
b^=(b&(1<<((b>>23)-'0')));
// b^=1: flip the player.
// Mark position is used by the player.
((b^=1)&1)&&(b|=(0x200<<((b>>23)-'0')));
// Check for winning lines.
C(14); // 2 4 8 | 14
C(112); // 16 32 64 | 112
C(146); // 128 256 512 | 896
C(168); // ----+---------------+----
C(292); // 168 | 146 292 584 | 546
C(546);
C(584);
C(896);
// Board drawing routine again.
puts("");
for(b&=~(15<<19);((b>>19)&0xf)<9;b+=(1<<19),((b>>19)&0xf)%3?1:puts("|"))
printf("|%c",b&(2<<((b>>19)&0xf))?' ':JOKE[(b>>(10+((b>>19)&0xf)))&1]);
printf("Player" "%2d:", b&1);
continue;
}
}
return 0;
}
Thank you! Since this is more readable, I decided to annotate it.exomo wrote:Still crazy enough, but a little more readable.
(Sorry for destroying your Art gamma)
No problems here. Darobar PM-ed me about some errors, but I fixed those. Apparently #define p(...) printf(__VA_ARGS__) is not c++, but only c orso. My original version can be found here btw.exomo wrote:forgot to mention it doesn't compile on Darobat's computer, but on my own.
