Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean hasAWinner(int[][] board) {
- for(int r = 0; r<board.length-1; r++){
- for(int c = 0; c< board[r].length-1; c++){
- int item = board[r][c];
- int redCounter=0;
- int blackCounter=0;
- if (item==RED) {
- redCounter=redCounter+1;
- blackCounter=0;
- }
- if (item==BLACK) {
- blackCounter=blackCounter+1;
- redCounter=0;
- }
- if (item==OPEN) {
- redCounter=0;
- blackCounter=0;
- }
- if (redCounter>=4) {
- return true;
- }
- if (blackCounter>=4) {
- return true;
- }
- }
- }
- for(int c = 0; c< board.length; c++){
- for(int j = 0; j<board[c].length-1; j++){
- int item = board[c][j];
- int redCounter=0;
- int blackCounter=0;
- if (item==RED) {
- redCounter=redCounter+1;
- blackCounter=0;
- }
- if (item==BLACK) {
- blackCounter=blackCounter+1;
- redCounter=0;
- }
- if (item==OPEN) {
- redCounter=0;
- blackCounter=0;
- }
- if (redCounter>=4) {
- return true;
- }
- if (blackCounter>=4) {
- return true;
- }
- }
- }
- for(int j = 0; j<board.length-1; j++){
- for(int k = 0; k< board[j].length-1; k++){
- int item = board[j][k];
- int redCounter=0;
- int blackCounter=0;
- if (item==RED) {
- redCounter=redCounter+1;
- blackCounter=0;
- }
- if (item==BLACK) {
- blackCounter=blackCounter+1;
- redCounter=0;
- }
- if (item==OPEN) {
- redCounter=0;
- blackCounter=0;
- }
- if (redCounter>=4) {
- return true;
- }
- if (blackCounter>=4) {
- return true;
- }
- }
- }
- for(int h = 0; h<board.length-1; h++){
- for(int p = 0; p< board[h].length-1; p++){
- int item = board[h][p];
- int redCounter=0;
- int blackCounter=0;
- if (item==RED) {
- redCounter=redCounter+1;
- blackCounter=0;
- }
- if (item==BLACK) {
- blackCounter=blackCounter+1;
- redCounter=0;
- }
- if (item==OPEN) {
- redCounter=0;
- blackCounter=0;
- }
- if (redCounter>=4) {
- return true;
- }
- if (blackCounter>=4) {
- return true;
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement