Discussion of chess software programming and technical issues.
Moderators: bob, hgm, Harvey Williamson
Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
-
Michael Sherwin
- Posts: 3046
- Joined: Fri May 26, 2006 1:00 am
- Location: WY, USA
- Full name: Michael Sherwin
Post
by Michael Sherwin » 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[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();
}
I hate if statements. Pawns demand if statements. Therefore I hate pawns.
-
mar
- Posts: 2015
- Joined: Fri Nov 26, 2010 1:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Post
by mar » 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.
Martin Sedlak
-
Uri Blass
- Posts: 8611
- Joined: Wed Mar 08, 2006 11:37 pm
- Location: Tel-Aviv Israel
Post
by Uri Blass » 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.
-
sovaz1997
- Posts: 235
- Joined: Sun Nov 13, 2016 9:37 am
Post
by sovaz1997 » 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.
-
AlvaroBegue
- Posts: 922
- Joined: Tue Mar 09, 2010 2:46 pm
- Location: New York
- Full name: Álvaro Begué (RuyDos)
Post
by AlvaroBegue » 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.