home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / MacGnuGo 0.5e / gnugo.src / macgoboard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  4.2 KB  |  152 lines  |  [TEXT/R*ch]

  1. #include "comment.header"
  2.  
  3. #define EMPTY 0
  4. #define WHITE 1
  5. #define BLACK 2
  6.  
  7. extern unsigned char p[19][19], l[19][19], ma[19][19], ml[19][19];
  8. extern int mymove, umove;
  9. extern int rd, lib, play, pass;
  10. extern int mik, mjk, uik, ujk, mk, uk;  /* piece captured */
  11. extern int opn[9];  /* opening pattern flag */
  12.  
  13. /* added from NextGo */
  14. extern int MAXX, MAXY, blackCapturedKoI, blackCapturedKoJ, whiteCapturedKoI,
  15.   whiteCapturedKoJ, blackCaptured, whiteCaptured,
  16.   blackStones, whiteStones, currentStone, opposingStone, blackPassed, whitePassed;
  17. extern int blackTerritory, whiteTerritory;
  18.  
  19. extern unsigned char capturedmat[19][19];
  20. extern int mx, my, atari;
  21. extern int hcap;
  22. extern int uflag;
  23. extern int lastMove;
  24.  
  25. unsigned char op[19][19];
  26. extern unsigned char ownermat[19][19];
  27. extern int size;
  28.  
  29. drawterritory(x,y,color)
  30. int x,y,color;
  31. {
  32.   x = 2*size*(x) + 1 + (3*size)/2;
  33.   y = 2*size*(y) - 2 + (5*size)/2;
  34.   MoveTo(x,y);
  35.   TextFont(1); TextSize(12); TextMode(srcOr);
  36.   if (color == WHITE) DrawChar('W');
  37.   if (color == BLACK) DrawChar('B');
  38. }
  39.  
  40. drawstone(x,y,color)
  41. int x,y,color;
  42. {
  43.   Rect r,r2;
  44.   x = 2*size*(x);
  45.   y = 2*size*(y);
  46.   SetRect(&r,x+size,y+size,x+3*size,y+3*size);
  47.   if (color == 1) {
  48.     FillOval(&r,white);
  49.     FrameOval(&r);
  50.   } else if (color == 2) {
  51.     /* FillOval(&r,dkGray); */
  52.     FillOval(&r,black);
  53.       if (size > 7) SetRect(&r2,x+3*size/2-1,y+3*size/2-1,x+2*size-3,y+2*size-3);
  54.       else SetRect(&r2,x+3*size/2,y+3*size/2,x+2*size-2,y+2*size-2);
  55.       FillOval(&r2,white);
  56.     FrameOval(&r);
  57.   } else if (color == -1) {
  58.     FillRect(&r,white);
  59.   }
  60. }
  61.  
  62. markStone(x,y,color)
  63. int x,y,color;
  64. {
  65.   Rect r;
  66.   if (x < 0) return;
  67.   x = 2*size*(x);
  68.   y = 2*size*(y);
  69.   SetRect(&r,x+3*size/2+1,y+3*size/2+1,x+5*size/2-1,y+5*size/2-1);
  70.   FillRect(&r,ltGray);
  71.   if (color == WHITE) FrameRect(&r);  
  72. }
  73.  
  74. RedrawScreen()
  75. {
  76.   int i,j;
  77.   char buf[128];
  78.   int slin = 20;
  79.   
  80.   for (i=0;i<MAXX;i++)
  81.     for (j=0;j<MAXX;j++) {
  82.       if (p[i][j] != op[i][j]) { drawstone(i,j,-1); op[i][j] = p[i][j]; }
  83.     }
  84.   for (i=0;i<MAXX;i++) {
  85.     MoveTo(2*size,2*size+i*2*size); LineTo(2*size+(MAXX-1)*2*size,2*size+i*2*size);
  86.     MoveTo(2*size+i*2*size,2*size); LineTo(2*size+i*2*size,2*size+(MAXX-1)*2*size);
  87.   }
  88.   for (i=0;i<MAXX;i++) for (j=0;j<MAXX;j++) {
  89.     if (p[i][j] != 0)   drawstone(i,j,p[i][j]);
  90.     else if (pass >= 2) drawterritory(i,j,ownermat[i][j]);
  91.   }
  92.   if (mx >= 0 && p[mx][my] != 0) markStone(mx,my,currentStone);
  93.     
  94.   TextFont(4); TextSize(9); TextMode(srcCopy);
  95.   MoveTo(2*size*(MAXX+2),2*slin);
  96.   if (atari) DrawCStr("Atari! ");
  97.   else DrawCStr("GnuGo  ");
  98.   DrawNum(MAXX); DrawChar('x'); DrawNum(MAXY);
  99.   MoveTo(2*size*(MAXX+2),3*slin);
  100.   i = mx; if (i > 7) i++;
  101.   if (i >= 0 && pass < 2) {
  102.     DrawCStr("My move: "); DrawChar('A'+i); DrawNum(MAXY - my); DrawCStr("   ");
  103.   }
  104.   else  DrawCStr("I pass      ");
  105.   MoveTo(2*size*(MAXX+2),4*slin);
  106.   if (opposingStone == BLACK) DrawChar('>');
  107.   DrawCStr("black "); DrawNum((pass < 2) ? whiteCaptured : blackTerritory + blackStones);
  108.   DrawCStr("    ");
  109.   MoveTo(2*size*(MAXX+2),5*slin);
  110.   if (opposingStone == WHITE) DrawChar('>');
  111.   DrawCStr("white "); DrawNum((pass < 2) ? blackCaptured : whiteTerritory + whiteStones);
  112.   DrawCStr("    ");
  113.   MoveTo(2*size*(MAXX+2),6*slin); 
  114.   if (pass >= 2) { DrawCStr("game over    "); }
  115.   else { DrawCStr("move "); DrawNum(lastMove-2*hcap+(hcap>0)); DrawCStr("   "); }
  116.   MoveTo(2*size*(MAXX+2),7*slin); 
  117.   if (hcap > 0) { DrawCStr("handicap "); DrawNum(hcap); DrawCStr(" "); }
  118.   return;
  119. }
  120.  
  121. extern void Idle(int t);
  122.  
  123. clicktask(x,y,m) short x; short y; short m;
  124. {
  125.   x = ((x-10)/(2*size)); if (x < 0) x = 0; if (x >= MAXX) x = MAXX-1;
  126.   y = ((y-10)/(2*size)); if (y < 0) y = 0; if (y >= MAXY) y = MAXY-1;
  127.   if (p[x][y] != 0 || suicide(x,y) || pass >= 2) { MyBeep(1); return; }
  128.   op[x][y] = umove; if (uflag) drawstone(x,y,umove);
  129.   if (pass < 2) movenplay(x,y);
  130.   /* Idle(30); */
  131.   RedrawScreen();
  132.   return; 
  133. }
  134.  
  135. extern WindowPtr myWindow;
  136. extern int nWidth, nHeight;
  137.  
  138. refresh() { Rect r; r = myWindow->portRect; EraseRect(&r); RedrawScreen(); }
  139.  
  140. resize()
  141. {
  142.   size = 7;
  143.   if (MAXX <= 17) size = 8;
  144.   if (MAXX <= 13) size = 10;
  145.   if (MAXX <= 11) size = 12;
  146.   if (MAXX <=  7) size = 18;
  147.   SizeWindow(myWindow,nWidth = 2*size*(MAXX+2) + 120,
  148.                       nHeight = 2*size*(MAXX+1) + (size/2) + 4, -1);
  149.   refresh();
  150. }
  151.  
  152. /* end */