• Welcome to Valhalla Legends Archive.
 

What NOT to do

Started by iago, February 19, 2004, 12:51 PM

Previous topic - Next topic

iago

I've been marking assignments, wherein a chessboard is read in from a file that looks something like:
rbnqknbrppppppppxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxPPPPPPPPRBNQKNBR
And it has to process the board.  Problem is, a lot of people change the boards they download so they look like this:
rbnqknbr
ppppppp
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
PPPPPPPP
RBNQKNBR
And they assume there will be endlines there or spaces between the characters.

On most assignments, don't make assumptions about the format of the input file, and make sure it works with given input files.  I can't believe how many people don't :(
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Grok

The bishops go in C1, F1, C8, F8.  Swap them with the Knights.

iago

Quote from: Grok on February 19, 2004, 01:07 PM
The bishops go in C1, F1, C8, F8.  Swap them with the Knights.

I always forget chess boards, and I had a feeling I was doing it wrong.  But that's not the point! :P

I also did the king/queen backwards, probably
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Grok

Quote from: iago on February 19, 2004, 02:32 PM
Quote from: Grok on February 19, 2004, 01:07 PM
The bishops go in C1, F1, C8, F8.  Swap them with the Knights.

I always forget chess boards, and I had a feeling I was doing it wrong.  But that's not the point! :P

I also did the king/queen backwards, probably

Looks fine, assuming white is on bottom edge.  Queen always goes on her own color.  Bottom-right corner of chessboard (as viewed by either player) is a white square.

iago

Quote from: Grok on February 19, 2004, 04:11 PM
Quote from: iago on February 19, 2004, 02:32 PM
Quote from: Grok on February 19, 2004, 01:07 PM
The bishops go in C1, F1, C8, F8.  Swap them with the Knights.

I always forget chess boards, and I had a feeling I was doing it wrong.  But that's not the point! :P

I also did the king/queen backwards, probably

Looks fine, assuming white is on bottom edge.  Queen always goes on her own color.  Bottom-right corner of chessboard (as viewed by either player) is a white square.

Well, I can't quite see the colors from here.  I don't even remember which is white :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Grok

Chess is racist anyway.  White always gets the first move.  ;p

iago

it makes sense, white is better!  Wait, that's not nice :(

Anyway, here's a sample of a piece of code (no, the forum didn't eat the indents, there weren't any to begin with)
int checkBlack() {
int tmp[8][8];
int returnValue = -1;

for (i=0;i<8;i++)
for (k=0;k<8;k++) {
tmp[7-i][7-k] = board[i][k];
if (tmp[7-i][7-k]>96) tmp[7-i][7-k] -= 32;
else if (tmp[7-i][7-k]<97 && tmp[7-i][7-k] != 'X') tmp[7-i][7-k] += 32;
}


That's AFTER he got 0 for last assignment with comments like, "indent, don't use constants, comment your code"
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

Quote from: iago on February 19, 2004, 06:32 PM
it makes sense, white is better!  Wait, that's not nice :(

Anyway, here's a sample of a piece of code (no, the forum didn't eat the indents, there weren't any to begin with)
int checkBlack() {
int tmp[8][8];
int returnValue = -1;

for (i=0;i<8;i++)
for (k=0;k<8;k++) {
tmp[7-i][7-k] = board[i][k];
if (tmp[7-i][7-k]>96) tmp[7-i][7-k] -= 32;
else if (tmp[7-i][7-k]<97 && tmp[7-i][7-k] != 'X') tmp[7-i][7-k] += 32;
}


That's AFTER he got 0 for last assignment with comments like, "indent, don't use constants, comment your code"

Where do you want him to use non-constant expressions? Making the size of a chessboard or the ascii difference between lowercase and uppercase variable doesn't seem all that necessary...

iago

Quote from: Adron on February 20, 2004, 01:45 PM
Quote from: iago on February 19, 2004, 06:32 PM
it makes sense, white is better!  Wait, that's not nice :(

Anyway, here's a sample of a piece of code (no, the forum didn't eat the indents, there weren't any to begin with)
int checkBlack() {
int tmp[8][8];
int returnValue = -1;

for (i=0;i<8;i++)
for (k=0;k<8;k++) {
tmp[7-i][7-k] = board[i][k];
if (tmp[7-i][7-k]>96) tmp[7-i][7-k] -= 32;
else if (tmp[7-i][7-k]<97 && tmp[7-i][7-k] != 'X') tmp[7-i][7-k] += 32;
}


That's AFTER he got 0 for last assignment with comments like, "indent, don't use constants, comment your code"

Where do you want him to use non-constant expressions? Making the size of a chessboard or the ascii difference between lowercase and uppercase variable doesn't seem all that necessary...


Sorry, I typed that fast; I meant USE constants.  Don't use magic numbers.  Like, 96 and 97 for instance when 'a' would have worked much better.  And the size of a chessboard should be #define 8, because that's how they were taught to do things in class.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

Ah. Somewhat a matter of opinions - his code seems more readable that way than with constants and comments:


// Width of chessboard
#define CHESSBOARD_WIDTH 8
// Height of chessboard
#define CHESSBOARD_HEIGHT 8
// Start of range for black pieces
#define CHESSBOARD_MINBLACK 'a'
// Start of range for white pieces
#define CHESSBOARD_MINWHITE 'A'
// End of range for white pieces
#define CHESSBOARD_MAXWHITE (CHESSBOARD_MINBLACK - 1)
// Difference used to convert pieces between black and white
#define CHESSBOARD_DIFFBLACKWHITE (CHESSBOARD_MINBLACK - CHESSBOARD_MINWHITE)
// Some magic value, used slot?
#define CHESSBOARD_MAGICVALUE 'X'
// The default error return value from the checkBlack function
#define CHECKBLACK_RETURN_ERROR -1

int checkBlack() {
int tmp[CHESSBOARD_WIDTH][CHESSBOARD_HEIGHT];
int returnValue = CHECKBLACK_RETURN_ERROR;

// Copy the board matrix to a temporary matrix
// At the same time:
//   Swap the colors
//   Invert the board
for (i=0;i<CHESSBOARD_WIDTH;i++)
 for (k=0;k<CHESSBOARD_HEIGHT;k++) {
   tmp[CHESSBOARD_WIDTH-1-i][CHESSBOARD_HEIGHT-1-k] = board[i][k];
   if (tmp[CHESSBOARD_WIDTH-1-i][CHESSBOARD_HEIGHT-1-k]>CHESSBOARD_MAXWHITE) tmp[CHESSBOARD_WIDTH-1-i][CHESSBOARD_HEIGHT-1-k] -= CHESSBOARD_DIFFBLACKWHITE;
   else if (tmp[CHESSBOARD_WIDTH-1-i][CHESSBOARD_HEIGHT-1-k]<CHESSBOARD_MINBLACK && tmp[CHESSBOARD_WIDTH-1-i][CHESSBOARD_HEIGHT-1-k] != CHESSBOARD_MAGICVALUE) tmp[CHESSBOARD_WIDTH-1-i][CHESSBOARD_HEIGHT-1-k] += CHESSBOARD_DIFFBLACKWHITE;
 }

iago

Yeah, his algorithm is bad, too.  He has a lot of problems.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


MrRaza

For a school programming projects, my friend created a four player chess game with either 1, 2, 3 computers and the rest human players, he added a GUI aswell.

Eli_1

oh yea? well my daddy is cooler than your daddy...  ;)

K

Quote from: Eli_1 on February 24, 2004, 09:25 PM
oh yea? well my daddy is cooler than your daddy...  ;)

No, it's TCC!

Quote
Two Clown Complex. It is derived thusly: imagine that you will have a clown at your birthday party. Should this joyous event be overheard by a person in the throes of TCC, they must declare that they had not one but two clowns, in addition to a bouncy castle.
- (penny arcade)