Okay, I'm gonna break down and go to the list with this problem.
I sure hope some of you can help me with this.
I am basing a mini game of checkers on PJD's chess patch and have
run into a few small problems.
I'm going to paste some of the code in here, so those of you that
aren't interested/inclined to read it may delete this message now.
Here's my current structs:
/* Move type struct */
struct move_p_type {
int row1;
int row2;
int row3;
int col1;
int col2;
int col3;
};
/* Board data struct */
struct c_obj_data {
struct c_obj_data *next;
int player;
int my_board_num;
long board[N_ROWS][N_COLS];
int win; /* game over? */
long player1; /* red PC */
long player2; /* black PC */
};
And here are my current defines:
/* Number of rows and collumns */
#define N_ROWS 8
#define N_COLS 8
/* Piece values */
#define CLOSED (1 << 0)
#define L_RED (1 << 1)
#define L_BLK (1 << 2)
#define K_RED (1 << 3)
#define K_BLK (1 << 4)
#define OPEN (1 << 5)
/* Define player-color values */
#define PC_RED (1 << 5)
#define PC_BLACK (1 << 6)
/* Ermm, okay.... */
#define MYPIECE (board->board[move->row1][move->col1])
#define MYTARGET (board->board[move->row2][move->col2])
And here is the function I am having problems with:
#define N_W 1
#define N_E 2
#define S_W 3
#define S_E 4
/* Okies, kings path first */
int diagonal_kpath(struct move_p_type *move, struct c_obj_data *board)
{
int temp1,temp2;
int dir;
/* check if it's actually diagonal */
if(abs(move->row1 - move->row2) != abs(move->col1 - move->col2)) {
return TRUE;
}
if(move->row1 < move->row2) { /* sudlich */
if(move->col1 > move->col2) {
dir=S_W;
} else {
dir=S_E;
}
} else { /* nordlich */
if(move->col1 > move->col2) {
dir=N_W;
} else {
dir=N_E;
}
}
/* okay, we know direction so we know which way to iterate */
temp1=move->row1;
temp2=move->col1;
/* wish there was a nice way to do this, but this works..
iterate it to the next space.. then follow the loop-
return true if current space is the end point.
else, return false if current space is occupied,
else, iterate to next space and continue. */
if(dir == S_W) {
temp1++;
temp2--;
} else if(dir == S_E) {
temp1++;
temp2++;
} else if(dir == N_W) {
temp1--;
temp2--;
} else {
temp1--;
temp2++;
}
while(temp1 != move->row2 && temp2 != move->col2) {
if(board->board[temp1][temp2] != OPEN) {
return FALSE;
}
if(dir == S_W) {
temp1++;
temp2--;
} else if(dir == S_E) {
temp1++;
temp2++;
} else if(dir == N_W) {
temp1--;
temp2--;
} else {
temp1--;
temp2++;
}
}
if(temp1 == move->row2 && temp2 == move->col2) {
return FALSE;
}
return TRUE;
}
-This message is continued in part 2-
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/?.refer=text
--
+---------------------------------------------------------------+
| FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
| Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
+---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/04/01 PST