home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / MacGnuGo 0.5e / gnugo.src / history.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-26  |  967 b   |  49 lines  |  [TEXT/R*ch]

  1. #include "comment.header"
  2.  
  3. #ifndef _game_history_
  4. #define _game_history_
  5.  
  6. typedef struct {
  7.   int color, x, y;
  8. } gameHistory;
  9.  
  10. #endif
  11.  
  12. #define WHITE 1
  13. #define BLACK 2
  14. extern unsigned char p[19][19];
  15. extern int MAXX, MAXY;
  16. static gameHistory gameMoves[600];
  17. int lastMove;
  18.  
  19. initHistory()
  20. {
  21.   int i,j;
  22.   lastMove = 0;
  23.   for (i=0;i<MAXX;i++) for (j=0;j<MAXY;j++)
  24.     if (p[i][j] != 0) {
  25.       addHistory(p[i][j],i,j);        /* adds handicap stones */
  26.     }
  27.   gameMoves[lastMove].color = -1;
  28. }
  29.  
  30. addHistory(int color, int x, int y)
  31. {
  32.   if ((lastMove & 1) == 0 && color == WHITE) addHistory(BLACK,-1,-1);
  33.   else if ((lastMove & 1) && color == BLACK) addHistory(WHITE,-1,-1);
  34.   gameMoves[lastMove].color = color;
  35.   gameMoves[lastMove].x = x;
  36.   gameMoves[lastMove].y = y;
  37.   if (lastMove < 599) lastMove++;
  38.   gameMoves[lastMove].color = -1;
  39. }
  40.  
  41. int getHistory(int i, int *color,int *x,int *y)
  42. {
  43.   *color = gameMoves[i].color ;
  44.   *x = gameMoves[i].x ;
  45.   *y = gameMoves[i].y ;
  46. }
  47.  
  48. /* */
  49.