home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume2 / dots2 / comp2.c < prev    next >
C/C++ Source or Header  |  1987-09-18  |  2KB  |  93 lines

  1. /*    COMP2.C    */
  2.  
  3. #include "dots.h"
  4.  
  5. goto_next_square(BorG, x, y)    /* returns 1 if there is one, 0 if not */
  6. int BorG, *x, *y;
  7. {
  8.     int x1, y1, x2, y2;
  9.  
  10.     find_adj_squares(*x, *y, &x1, &y1, &x2, &y2);
  11.     if (x1 != NULL && closure(BorG, x1, y1) == 3) {
  12.     *x = x1, *y = y1;
  13.     return (1);
  14.     }
  15.     if (x2 != NULL && closure(BorG, x2, y2) == 3) {
  16.     *x = x2, *y = y2;
  17.     return (1);
  18.     }
  19.     return (0);
  20. }
  21.  
  22. find_adj_squares(x, y, x1, y1, x2, y2)
  23. int x, y, *x1, *y1, *x2, *y2;
  24. {
  25.     if (isodd(x)) {    /* Vertical line */
  26.     *x1 = x - 1;
  27.     *y1 = y;
  28.     *x2 = x + 1;
  29.     *y2 = y;
  30.     } else {        /* Horizontal line */
  31.     *x1 = x;
  32.     *y1 = y - 1;
  33.     *x2 = x;
  34.     *y2 = y + 1;
  35.     }
  36.     if (!is_on_board(*x1, *y1))
  37.     *x1 = NULL, *y1 = NULL;
  38.     if (!is_on_board(*x2, *y2))
  39.     *x2 = NULL, *y2 = NULL;
  40. }
  41.  
  42. goto_adj_free_line(BorG, x, y)
  43. int BorG;
  44. int *x, *y;
  45. {
  46.     int xtemp, ytemp;
  47.  
  48.     for (xtemp = *x - 1; xtemp <= *x + 1; xtemp += 2)
  49.     if ((BorG == BAD ? badboard[xtemp][*y] : board[xtemp][*y]) == FREE) {
  50.         *x = xtemp;
  51.         return;
  52.     }
  53.     for (ytemp = *y - 1; ytemp <= *y + 1; ytemp += 2)
  54.     if (board[*x][ytemp] == FREE)
  55.         if (((BorG == BAD)? badboard[*x][ytemp] : board[*x][ytemp])
  56.             == FREE) {
  57.         *y = ytemp;
  58.         return;
  59.         }
  60.     printf("You fucked up, buddy!");
  61.     fflush(stdout);
  62.     die();
  63. }
  64.  
  65. /*****************************************************************************\
  66. |*  right now, this function doesn't actually go to the middle of a path,    *|
  67. |*  it simply goes one line away from the edge. If the length of the path is *|
  68. |*  two, the effect is the same.                                             *|
  69. \*****************************************************************************/
  70. goto_middle_of_path(BorG, x, y)
  71. int BorG, *x, *y;
  72. {
  73.     int origx, origy, x1, y1, x2, y2;
  74.  
  75.     find_adj_squares(*x, *y, &x1, &y1, &x2, &y2);
  76.     if (closure(BorG, x1, y1) == 2 && closure(BorG, x2, y2) == 2)
  77.     return;        /* you're sitting on it to begin with */
  78.     origx = *x, origy = *y;
  79.     if (BorG == GOOD)
  80.     board[origx][origy] = USED;
  81.     else
  82.     badboard[origx][origy] = USED;
  83.     /* Temporarily */
  84.     goto_next_square(BorG, x, y);
  85.     goto_adj_free_line(BorG, x, y);
  86.  
  87.     if (BorG == GOOD)
  88.     board[origx][origy] = FREE;
  89.     else
  90.     badboard[origx][origy] = FREE;
  91.     /* SIGH! */
  92. }
  93.