Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. public boolean hasAWinner(int[][] board) {
  2. for(int r = 0; r<board.length-1; r++){
  3. for(int c = 0; c< board[r].length-1; c++){
  4. int item = board[r][c];
  5. int redCounter=0;
  6. int blackCounter=0;
  7. if (item==RED) {
  8. redCounter=redCounter+1;
  9. blackCounter=0;
  10. }
  11. if (item==BLACK) {
  12. blackCounter=blackCounter+1;
  13. redCounter=0;
  14. }
  15. if (item==OPEN) {
  16. redCounter=0;
  17. blackCounter=0;
  18. }
  19. if (redCounter>=4) {
  20. return true;
  21. }
  22. if (blackCounter>=4) {
  23. return true;
  24. }
  25.  
  26. }
  27. }
  28.  
  29. for(int c = 0; c< board.length; c++){
  30. for(int j = 0; j<board[c].length-1; j++){
  31.  
  32. int item = board[c][j];
  33. int redCounter=0;
  34. int blackCounter=0;
  35. if (item==RED) {
  36. redCounter=redCounter+1;
  37. blackCounter=0;
  38. }
  39. if (item==BLACK) {
  40. blackCounter=blackCounter+1;
  41. redCounter=0;
  42. }
  43. if (item==OPEN) {
  44. redCounter=0;
  45. blackCounter=0;
  46. }
  47. if (redCounter>=4) {
  48. return true;
  49. }
  50. if (blackCounter>=4) {
  51. return true;
  52.  
  53. }
  54. }
  55. }
  56.  
  57. for(int j = 0; j<board.length-1; j++){
  58. for(int k = 0; k< board[j].length-1; k++){
  59. int item = board[j][k];
  60. int redCounter=0;
  61. int blackCounter=0;
  62. if (item==RED) {
  63. redCounter=redCounter+1;
  64. blackCounter=0;
  65. }
  66. if (item==BLACK) {
  67. blackCounter=blackCounter+1;
  68. redCounter=0;
  69. }
  70. if (item==OPEN) {
  71. redCounter=0;
  72. blackCounter=0;
  73. }
  74. if (redCounter>=4) {
  75. return true;
  76. }
  77. if (blackCounter>=4) {
  78. return true;
  79. }
  80. }
  81. }
  82. for(int h = 0; h<board.length-1; h++){
  83. for(int p = 0; p< board[h].length-1; p++){
  84. int item = board[h][p];
  85. int redCounter=0;
  86. int blackCounter=0;
  87. if (item==RED) {
  88. redCounter=redCounter+1;
  89. blackCounter=0;
  90. }
  91. if (item==BLACK) {
  92. blackCounter=blackCounter+1;
  93. redCounter=0;
  94. }
  95. if (item==OPEN) {
  96. redCounter=0;
  97. blackCounter=0;
  98. }
  99. if (redCounter>=4) {
  100. return true;
  101. }
  102. if (blackCounter>=4) {
  103. return true;
  104. }
  105. }
  106. }
  107. return false;
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement