[LONG] Checkers mini game (part 2)

From: Shane P. Lee (tacodog21@yahoo.com)
Date: 03/31/01


Those of you familiar with the chess patch will notice that I
shamelessly hacked the diagonal_path along with everything else.
The paths for l_black and l_red are similar, but limited to either
S_W to S_E or N_W to N_E.

Here is the actual move code:
int check_valid_move(struct move_p_type *move,int player,struct
c_obj_data *board,
struct char_data *ch) {

  if(MYPIECE == CLOSED) {
    send_to_char("That square can't be used even if you DID have a
piece there.\r\n",ch);
    return FALSE;
  }
  if(MYPIECE == OPEN) {
    send_to_char("There is no piece there.\r\n",ch);
    return FALSE;
  }
  if((IS_SET(MYPIECE,PC_BLACK) && player == PC_RED) ||
    (IS_SET(MYPIECE,PC_RED) && player == PC_BLACK)) {
    send_to_char("That is not your piece.\r\n",ch);
    return FALSE;
  }
  if(IS_SET(MYPIECE, L_RED)) {
    return valid_lrman(move,player,board,ch);
  } else if (IS_SET(MYPIECE, L_BLK)) {
    return valid_lbman(move,player,board,ch);
  } else if(IS_SET(MYPIECE,K_RED)) {
    return valid_cking(move,player,board,ch);
  } else if(IS_SET(MYPIECE,K_BLK)) {
    return valid_cking(move,player,board,ch);
  } else {
    return FALSE;
  }

}

And here is the valid_cking code:
int valid_cking(struct move_p_type *move,int player,struct c_obj_data
*board, struct char_data *ch) {
        /* terribly simple, check and make sure that it's a valid
           non-jumping diagonal move, and if so, allow it */
  if(!diagonal_kpath(move,board)) {
    /* false means nothings in the way */
    perform_this_move(move,board);
    return TRUE;
  }
  return FALSE;
}

And finally, here is the perform_this_move code:

void perform_this_move(struct move_p_type *move, struct c_obj_data
*board)
{
  if(IS_SET(MYPIECE,L_RED) && IS_SET(MYPIECE,PC_RED) && move->row2==0)
{
    REMOVE_BIT(MYPIECE,L_RED);
    SET_BIT(MYPIECE,K_RED); /* kingme! */
  }
  if(IS_SET(MYPIECE,L_BLK) && IS_SET(MYPIECE,PC_BLACK) &&
move->row2==7) {
    REMOVE_BIT(MYPIECE,L_BLK);
    SET_BIT(MYPIECE,K_BLK); /* kingme! */
  }

  MYTARGET = MYPIECE;
  MYPIECE = OPEN;
}


What I want to do now is check for an actual jump. The code above
allows only diagnol movement, and if you move into a square that is
currently occupied, you capture whatever is there. This is a BadThing
because in checkers you JUMP, not capture.
I can't seem to get the math down, but I need to check the third
square down (or up, depending on your color) to see if it is OPEN.
If it is, and the second square down != OPEN, the second square
should be changed to OPEN and the current MYPIECE should be moved
to the third square.
Like so:

 if(SQUARE3 == OPEN) {
   if(MYTARGET == L_RED && MYPIECE == L_BLK) {
   SQUARE3 = L_BLK;
   }

 if(SQUARE3 == OPEN) {
   if(MYTARGET == L_BLK && MYPIECE == L_RED) {
   SQUARE3 = L_BLK;
  }

 if(MYTARGET != OPEN) {
  return;
 }

This is what the squares would look like:
+---+---+---+
|   |   | b |   (1)
+---+---+---+
|   | r |   |   (2)
+---+---+---+
| ! |   | * |   (3)
+---+---+---+
 (a) (b) (c)

Assuming it is b's (L_BLK) turn to move, they should be able
to move from c1 to a3, rendering b2 (L_RED) closed.

Not only do I not know how to define SQUARE3, but I wouldn't be able
figure out which function to put the above check in.

If this isn't too confusing for those of you who stuck around long
enough to read my entire message, I would appreciate any replies.

-FIRE

p.s. Again, the code all works, except for the check I wrote for the
purposes of this email. The only problem is figuring out jumps as
opposed to captures (SQUARE3 vs. MYTARGET).


__________________________________________________
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