Page 1 of 1

### I lost my rant :(

Posted: Tue Mar 12, 2019 6:02 am
I logged in, started a new topic ranting about my life's programming experience and how difficult it was because I have a learning disability that prevents me from actually learning C. I hit preview and it sent me to the login screen losing my post. So you get the scaled way back version. I have to relearn how to do things in C every time I set down to write code. Initialization code is most difficult because it can be quite esoteric. The problem for me is not finishing it in one day. The next day I often look at the code and wonder who wrote it. I just did not remember writing it or how it was supposed to work. So I had to start over. Today I was able to simplify the code so I could write it in one day. It took me about 8 hours to complete. The code is the initializing of a move lookup table--just the bishop as it had to be a 'small task' if I were to finish it before bed.

Code: Select all

``````typedef struct {
int ts;
int ns;
int nd;
} mt;

mt m;

void InitMovTbl();
void Initialize();
int main();

void InitMovTbl() {
int sq, ns, y, x, dy, dx, o, p, i;

for (sq = ns = 0; sq < 64; sq++) {
y = sq >> 3;
x = sq & 7;

for (p = ns, dy = 1, dx = -1; y + dy < 8 && x + dx > -1; dy++, dx--) {
o = p;
m[ns].ts = sq + (dy << 3) + dx;
m[ns].ns = ns + 1; ns++;
} for (i = p; i < ns; i++) m[i].nd = ns;

for (p = ns, dy = 1, dx = 1; y + dy < 8 && x + dx < 8; dy++, dx++) {
o = p;
m[ns].ts = sq + (dy << 3) + dx;
m[ns].ns = ns + 1; ns++;
} for (i = p; i < ns; i++) m[i].nd = ns;

for (p = ns, dy = -1, dx = -1; y + dy > -1 && x + dx > -1; dy--, dx--) {
o = p;
m[ns].ts = sq + (dy << 3) + dx;
m[ns].ns = ns + 1; ns++;
} for (i = p; i < ns; i++) m[i].nd = ns;

for (p = ns, dy = -1, dx = 1; y + dy > -1 && x + dx < 8; dy--, dx++) {
o = p;
m[ns].ts = sq +  (dy << 3) + dx;
m[ns].ns = ns + 1;
m[ns].ns = 0; ns++;
} for (i = p; i < ns; i++) m[i].nd = ns;

m[ns - 1].ns = 0;
for (i = o; i < ns; i++) m[i].nd = 0;
}

}

void Initialize() {
InitMovTbl();
}

int main() {
Initialize();
}
``````

### Re: I lost my rant :(

Posted: Tue Mar 12, 2019 10:12 am
Michael Sherwin wrote:
Tue Mar 12, 2019 6:02 am
I hit preview and it sent me to the login screen losing my post.
Yes, this used to happen to me as well. It taught me to always copy the whole post to the clipboard before previewing/posting.

### Re: I lost my rant :(

Posted: Tue Mar 12, 2019 10:35 am
mar wrote:
Tue Mar 12, 2019 10:12 am
Michael Sherwin wrote:
Tue Mar 12, 2019 6:02 am
I hit preview and it sent me to the login screen losing my post.
Yes, this used to happen to me as well. It taught me to always copy the whole post to the clipboard before previewing/posting.
never happened to me in this forum but the in a different forum when it happened there were cases when I could return back to the previous screen so I did not lose my post.

### Re: I lost my rant :(

Posted: Tue Mar 12, 2019 5:29 pm
I recommend additionally saving what you write to the file (if the text is very large). Then just don't lose what you write.

### Re: I lost my rant :(

Posted: Wed Mar 13, 2019 1:04 am
Part of the problem is your coding style. Your function names are OK, but your variable names are not informative at all. I have no idea what `ts', `ns', `nd', `mt', or `m' mean. Chances are you won't know when you encounter the code in a couple of days either. You should write code that is easy for a human to read. Getting the compiler to understand you is the easy part, but that's not good enough.