wuzi(1)(1).cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4. char a[255];
  5. void say(){//没有返回值得改成void
  6. cout<<"0123456789012345"<<endl;
  7. for(int i=0;i<211;i=i+15){
  8. cout<<(i/15+1)%10;
  9. for(int j=i+1;j<i+16;j++){
  10. cout<<a[j];
  11. }
  12. cout<<endl;
  13. }
  14. }
  15. int x,y,k,m,n;
  16. bool judge(int b,char c,int l1,int r1,int l2,int r2){
  17. for(int i=l1;i<r1;i++){
  18. for(int j=l2;j<r2;j++){
  19. k=j*15+i;
  20. if(a[k]==c&&a[k+1*b]==c&&a[k+2*b]==c&&a[k+3*b]==c&&a[k+4*b]==c){
  21. return true;
  22. cout<<a[k]<<' '<<k<<' '<<b<<' '<<c<<endl;
  23. }
  24. }
  25. }
  26. return false;//不写这行很危险
  27. }
  28. bool work(char c,string side){
  29. say();
  30. if(judge(1,c,5,12,0,15)||judge(-1,c,5,12,0,15)){
  31. cout<<side+" win!1"<<endl;
  32. return false;
  33. }
  34. if(judge(15,c,1,16,4,11)||judge(-15,c,1,16,4,11)){
  35. cout<<side+" win!2"<<endl;
  36. return false;
  37. }
  38. if(judge(14,c,5,12,4,11)||judge(-14,c,5,12,4,11)||judge(16,c,5,12,4,11)||judge(-16,c,5,12,4,11)){
  39. cout<<side+" win!3"<<endl;
  40. return false;
  41. }
  42. return true;
  43. }
  44. int main(){
  45. char c;
  46. for(int i=0;i<226;i++){
  47. a[i]=' ';
  48. }
  49. while(true){
  50. cout<<"black:";
  51. while(cin>>x>>y){
  52. cout<<endl;
  53. k=(y-1)*15+x;
  54. if(a[k]==' '){
  55. a[k]='X';
  56. break;
  57. }
  58. else cout<<"nope"<<endl;
  59. }
  60. if(!work('X',"black"))break;
  61. cout<<"white:";
  62. while(cin>>x>>y){
  63. cout<<endl;
  64. k=(y-1)*15+x;
  65. if(a[k]==' '){
  66. a[k]='O';
  67. break;
  68. }
  69. else cout<<"nope"<<endl;
  70. }
  71. if(!work('O',"white"))break;
  72. }
  73. system("pause");
  74. return 0;
  75. }