home *** CD-ROM | disk | FTP | other *** search
/ The Ultimate House of Games 2000 / UHOG2000.iso / Games / Strategy / WINFOUR / FOUR.C next >
Text File  |  1995-12-08  |  1KB  |  78 lines

  1. #include <stdio.h>
  2.  
  3. int my_algo(int mycode,int hiscode,int board[7][6])
  4. {
  5. return(0);
  6. }
  7.  
  8. int human(int mycode,int hiscode,int board[7][6])
  9. {
  10. int i;
  11. printf("Enter column \n");
  12. scanf("%d",&i);
  13. i--;
  14. return(i);
  15. }
  16.  
  17. printboard(int board[7][6])
  18. {
  19. int i,j;
  20. for(j=5;j>=0;j--)
  21.         {
  22.         printf("|");
  23.         for(i=0;i<7;i++)
  24.                 {
  25.                 if (board[i][j]==10) printf("0");
  26.                 else if (board[i][j]==20) printf("1");
  27.                 else printf(" ");
  28.                 }
  29.         printf("|\n");
  30.         }
  31. return(0);
  32. }
  33.  
  34. int full(int board[7][6])
  35. {
  36. int i;
  37. for (i=0;i<7;i++) if(board[i][5]==0) return(0);
  38. return(1);
  39. }
  40.  
  41. move(int board[7][6],int color,int column)
  42. {
  43. int i;
  44. i=5;
  45. while(board[column][i]==0 && i>0) i--;
  46. if(board[column][i]!=0) i++;
  47. board[column][i]=color;
  48. }
  49.  
  50. getmove(int mycode,int hiscode,int board[7][6],int p)
  51. {
  52. if(p==1) return(my_algo(mycode,hiscode,board));
  53. if(p==2) return(human(mycode,hiscode,board));
  54. }
  55.  
  56. dogame(int mycode,int hiscode,int board[7][6])
  57. {
  58. while(!full(board))
  59.         {
  60.         printboard(board);
  61.         move(board,mycode, getmove(mycode,hiscode,board,2));
  62.         printboard(board);
  63.         move(board,hiscode,getmove(hiscode,mycode,board,1));
  64.         printf("\n");
  65.         }
  66. printboard(board);
  67. return(0);
  68. }
  69.  
  70. main()
  71. {
  72. int board[7][6];
  73. int i,j;
  74. for(i=0;i<7;i++) for(j=0;j<6;j++) board[i][j]=0;
  75. dogame(10,20,board);
  76. return(0);
  77. }
  78.