Guest User

Untitled

a guest
Dec 13th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. char goBoard[19][19];
  4. int i, j;
  5.  
  6. void initialize()
  7. {
  8. for(i = 0; i < 19; i++)
  9. {
  10. for(j = 0; j < 19; j++)
  11. {
  12. goBoard[i][j] = '-';
  13. }
  14. }
  15. }
  16.  
  17. int placeStone(int color, int row, int col)
  18. {
  19. if(color == 0)
  20. {
  21. goBoard[row-1][col-1] = 'B';
  22. return 1;
  23. }
  24. else if(color == 1)
  25. {
  26. goBoard[row-1][col-1] = 'W';
  27. return 1;
  28. }
  29. else
  30. return 0;
  31. }
  32.  
  33. void showBoard()
  34. {
  35. for(i = 0; i < 19; i++)
  36. {
  37. for(j = 0; j < 19; j++)
  38. {
  39. printf("%c ", goBoard[i][j]);
  40. }
  41. printf("\n");
  42. }
  43. }
  44.  
  45. int checkOmok(int color, int row, int col)
  46. {
  47. int i = 0, bCnt = 0, wCnt = 0, maxCount = 0;
  48.  
  49. for(i = 0; i < 19; i++)
  50. {
  51. if(goBoard[row - 1][i] == 'B' || goBoard[i][col - 1] == 'B')
  52. bCnt++;
  53. else if(goBoard[i][i] == 'B')
  54. bCnt++;
  55. else if(goBoard[row - 1][i] == 'W' || goBoard[i][col - 1] == 'W')
  56. wCnt++;
  57. else if(goBoard[i][i] == 'W')
  58. wCnt++;
  59. else
  60. {
  61. if(color == 0)
  62. {
  63. if(bCnt >= maxCount)
  64. maxCount = bCnt;
  65. bCnt = 0;
  66. }
  67. else if(color == 1)
  68. {
  69. if(wCnt >= maxCount);
  70. maxCount = wCnt;
  71. wCnt = 0;
  72. }
  73. else
  74. return 0;
  75. }
  76. }
  77. if(maxCount >= 5)
  78. return 1;
  79. else
  80. return 0;
  81. }
  82.  
  83. int main()
  84. {
  85. int turn = 0, row, col;
  86. initialize();
  87. while(1)
  88. {
  89. if(turn == 0)
  90. printf("흑 > ");
  91. else
  92. printf("백 > ");
  93. scanf("%d %d", &row, &col);
  94. if(row == 0 || col == 0)
  95. break;
  96. if(goBoard[row-1][col-1] == '-')
  97. {
  98. placeStone(turn, row, col);
  99. if(checkOmok(turn, row, col) == 1)
  100. {
  101. if(turn == 0)
  102. {
  103. printf("흑인 승\n");
  104. break;
  105. }
  106. else
  107. {
  108. printf("백인 승\n");
  109. break;
  110. }
  111. }
  112. if(placeStone(turn, row, col) == 0)
  113. break;
  114. if(turn == 0)
  115. turn = 1;
  116. else
  117. turn = 0;
  118. }
  119. else
  120. printf("이미 돌이 있는 위치입니다.\n");
  121.  
  122. showBoard();
  123. }
  124. }
Add Comment
Please, Sign In to add comment