I lost my rant :(
Posted: Tue Mar 12, 2019 7: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[10000];
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();
}