home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 270_01 / t3player.c < prev    next >
Text File  |  1979-12-31  |  2KB  |  75 lines

  1.  
  2. /*
  3.      HEADER:     CUG270.05 ;
  4.      TITLE:      TTT3D player move subroutine ;
  5.      DATE:       06/08/1988 ;
  6.      VERSION:    1.0 ;
  7.      FILENAME:   T3PLAYER.C ;
  8.      AUTHORS:    Scott Holland ;
  9.      SEE-ALSO:   T3.DOC;
  10. */
  11.  
  12. /* COPYRIGHT 1988 SCOTT HOLLAND */
  13.  
  14. /* This routine gets the players move and verifies that it is valid */
  15.  
  16. #include <stdio.h>
  17. #include "t3global.h"
  18.  
  19. player_move()
  20.   {
  21.     char *gets() ;
  22.     char str[80];
  23.     char *line = &str[0] ;
  24.     int move ;
  25.     int level,column,row ;
  26.     strategy = 0 ;
  27.     legal = 1 ;
  28.     printf("Enter your move : ");
  29.     gets(line);
  30.     /*  printf("%s\n",line); */
  31.     if (*line == 'Q' || *line == 'q')
  32.       {
  33.         strategy = -1 ;
  34.         game_over = 1 ;
  35.         return ;
  36.       };
  37.     if (*line == '0') return ;
  38.     level = cnvtint(line) ;
  39.     *line++;
  40.     row = cnvtint(line) ;
  41.     *line++;
  42.     column = cnvtint(line) ;
  43.  
  44.     if (diag)
  45.     {
  46.       printf("strat %2d leg %2d level %2d row %2d col %2d\n",
  47.              strategy,legal,level,row,column) ;
  48.     }
  49.  
  50.     fflush(stdout) ;
  51.     if (legal == 0) return ;
  52.     
  53.     move = conv_move(level,row,column) ;
  54.     if (board[move] != 0)
  55.       { /* if square already taken */
  56.      strategy = -2 ;
  57.          legal = 0 ;
  58.      return ;
  59.       }
  60.     board[move] = 1 ;
  61.   }
  62.  
  63. /* This routine converts a character to an integer */
  64.   
  65. cnvtint(s)
  66. char *s;
  67. {
  68.     if (*s < '1' || *s > '4' ) {
  69.     strategy = -3 ;
  70.     legal = 0 ;
  71.     }
  72.     return( *s -'0');
  73. }
  74.  
  75.