C Contest Code

Pages: 1234
Very nice Disch, I don't get the reference but I am impressed :) also, it closes when I press the enter key even if it doesn't have focus :o

Edit: Video: http://www.youtube.com/watch?v=x6GS12kU9z4

@Slumpers http://www.cplusplus.com/forum/lounge/92555/#msg497906
What does that code do? It doesn't output anything for me.
Last edited on
One piece of code that is very elegant, but perhaps hard to realise it could be used to compute values of pi to 10 trillion digits, is this code by the chudnovsky brothers:

ftp://ftp.gmplib.org/pub/misc/gmp-chudnovsky.c
http://en.wikipedia.org/wiki/Chudnovsky_algorithm


It is perhaps off topic, because the code is not deliberately obscure, just the algorithm is a little unexpected. I mean if someone showed that code and asked what it did, I guess not many people would realise it's intention until they arrived at the comment near the end. Interesting nonetheless.
in Disch's code how did he make a new frame? I didn't see a system("CLS") there, and you clearly didn't use endl to make a new frame... So how did you do this? I have been wondering how to do this without CLS for some time now.
I move the cursor position before every print with SetConsoleCursorPosition (WinAPI function).

De-obfuscated code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <Windows.h>
#include <cstdio>

const char shapes[][8] = 
{
    {0x18,0x24,0x42,0x42,0x7E,0x42,0x42,0x42},  //a
    {0x7C,0x42,0x42,0x7C,0x42,0x42,0x42,0x7C},  //b
    {0x1C,0x22,0x40,0x40,0x40,0x40,0x22,0x1C},  //c
    {0x78,0x44,0x42,0x42,0x42,0x42,0x44,0x78},  //d
    {0x7E,0x40,0x40,0x7C,0x40,0x40,0x40,0x7E},  //e
    {0x7E,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},  //f
    {0x1C,0x22,0x40,0x40,0x4E,0x42,0x22,0x1C},  //g
    {0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42},  //h
    {0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},  //i
    {0x3E,0x04,0x04,0x04,0x04,0x24,0x24,0x38},  //j
    {0x42,0x44,0x48,0x70,0x48,0x44,0x42,0x42},  //k
    {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7E},  //L
    {0x6C,0x92,0x92,0x92,0x82,0x82,0x82,0x82},  //M
    {0x42,0x62,0x52,0x52,0x4A,0x4A,0x46,0x42},  //N
    {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},  //O
    {0x7C,0x42,0x42,0x7C,0x40,0x40,0x40,0x40},  //P
    {0x3C,0x42,0x42,0x42,0x42,0x4A,0x44,0x3A},  //Q
    {0x3C,0x42,0x42,0x42,0x7C,0x44,0x42,0x42},  //R
    {0x3C,0x42,0x40,0x3C,0x02,0x02,0x42,0x3C},  //S
    {0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10},  //T
    {0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},  //U
    {0x42,0x42,0x44,0x44,0x48,0x48,0x50,0x20},  //V
    {0x82,0x82,0x82,0x82,0x54,0x54,0x54,0x28},  //W
    {0x42,0x24,0x24,0x18,0x18,0x24,0x24,0x42},  //X
    {0x44,0x44,0x44,0x28,0x10,0x10,0x10,0x10},  //Y
    {0x7E,0x02,0x04,0x08,0x10,0x20,0x40,0x7E}   //Z
};

const char* words[] = {
    "        ",
    "   you  ",
    "  know  ",
    "  this  ",
    " boogie ",
    "   is   ",
    "   for  ",
    "  real  ",
    "        ",
    " nothing",
    "  left  ",
    "   for  ",
    "   me   ",
    "   to   ",
    "   do   ",
    "   but  ",
    "  dance ",
    "  dance ",
    "        ",
    "   got  ",
    " canned ",
    "  heat  ",
    "   in   ",
    "   my   ",
    "  heels ",
    " tonight",
    "  baby  "
};

const int maxwords = 27;
char data[8][64];
int pos[8];
int nextword;
int direction;
auto hand = GetStdHandle( STD_OUTPUT_HANDLE );

void loadword()
{
    for(int y = 0; y < 8; ++y)
    {
        for(int x = 0; x < 64; ++x)
        {
            data[y][x] = shapes[words[nextword][x>>3]-'a'][y] & (1<<(7^x&7)) ? (nextword == 17 ?' ':'#') : (nextword != 17 ?' ':'#');
        }
    }
}

void setpos()
{
    for(int i = 0; i < 8; ++i)
        pos[i] = direction > 0 ? -i : 64+i;
}

int main()
{
    nextword = 1;
    loadword();
    nextword = 2;
    direction = 1;
    setpos();
    COORD c;

    while(!GetAsyncKeyState(VK_RETURN))
    {
        for(c.Y = 0; c.Y < 8; ++c.Y)
        {
            c.X = pos[c.Y]-direction;
            if(c.X >= 0 && c.X < 64)
            {
                SetConsoleCursorPosition(hand,c);
                printf("%c",data[c.Y][c.X]);
            }
            c.X = pos[c.Y];
            if(c.X >= 0 && c.X < 64)
            {
                SetConsoleCursorPosition(hand,c);
                printf("*");
            }
        }
        Sleep(10);
        for(int i = 0; i < 8; ++i)  pos[i] += direction;
        if((pos[7] < -1 && direction < 0) || (pos[7] >= 65 && direction > 0))
        {
            loadword();
            nextword = (nextword+1) % maxwords;
            direction=-direction;
            Sleep(200);
            setpos();
        }
    }
}
If I just want to make a function that works like system("CLS") how would I do that? This is a function I need for many of my ideas!
FWIW... if you want to clear the screen with the console, you're probably misusing the console.
For text based games a way to make a new frame is convenient, and it is even more convenient if the cursor is in the top left corner.
This is what i have used before:
1
2
3
4
  void ClearScreen()
    {
    cout << string( 100, '\n' );
    }
text based games


Well there's your problem. ;P

http://www.cplusplus.com/forum/articles/28558/
I haven't had use for the system("CLS") equivalent for quite some time. I have already begun using SDL, hoping to learn to make something interesting that is also interactive. SDL takes some time to learn, but atleast I got the library working :)
Is there a code::blocks plugin to activate c++11 and many other languages?
Is there a code::blocks plugin to activate c++11


When you open up CodeBlocks there is an option at the top that says "Settings."

You may want to check into that.
nope cire.
You might have to upgrade your version of C::B and/or gcc.
OOOooooh, what are the Effective C++ warnings like? :D
Umm, I just upgraded to code::blocks 12.11

And the compiler i'm using is: GNU GCC Compiler
wait does that mean i have c++11?
I guess, but ....
does c++11 have threads, ive been dying to try out threads with c++ but have been to retarded to install any extra libraries...baring opengl and sdl which are proven by me to be idiot proof
Pages: 1234