private boolean CheckVertical() { if (isGameOver()) return true; System.out.println("Vertical"); Counter _occurrence = new Counter(3, 0); /* * Horizontal scan */ for (int y = 0; y < BOARD_HEIGHT; y++) { _occurrence.reset(0); int _prevState = _board[0][y]; for (int x = 0; x < BOARD_HEIGHT; x++) { int _currentState = _board[x][y]; if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) { if (_occurrence.isAtMax()) { System.out.println("Game over, VERTICALSTAGE0"); GameOver(_prevState); return true; } } _prevState = _currentState; } } return false; }
private boolean CheckDiagonal() { if (isGameOver()) return true; System.out.println("Diagonal"); Counter _occurrence = new Counter(3, 0); /** ******************************************** */ /** Diagonal lines starting from topmost row * */ /** ******************************************** */ /** Stage 1 - Right bottom diagonal check */ /** ******************************************** */ /** - Starting from leftmost */ /** - Iterating to rightmost point */ /** ******************************************** */ for (int baseX = 0; baseX < BOARD_WIDTH; baseX++) { /* Assign starting point's state to the previous state */ int _prevState = _board[baseX][0]; _occurrence.reset(0); for (int x = baseX, y = 0; (x < BOARD_WIDTH) && (y < BOARD_HEIGHT); x++, y++) { int _currentState = _board[x][y]; if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) { if (_occurrence.isAtMax()) { System.out.println("Game over, DLTOPSTAGE1"); GameOver(_prevState); return true; } } _prevState = _currentState; } } _occurrence.reset(0); /** ******************************************** */ /** Stage 2 - Left bottom diagonal check */ /** ******************************************** */ /** - Starting from rightmost */ /** - Iterating to leftmost point */ /** ******************************************** */ for (int baseX = BOARD_WIDTH - 1; baseX >= 0; baseX--) { /* Assign starting point's state to the previous state */ int _prevState = _board[baseX][0]; _occurrence.reset(0); for (int x = baseX, y = 0; (x >= 0) && (y < BOARD_HEIGHT); x--, y++) { int _currentState = _board[x][y]; if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) { if (_occurrence.isAtMax()) { System.out.println("Game over, DLTOPSTAGE2"); GameOver(_prevState); return true; } } _prevState = _currentState; } } _occurrence.reset(0); /** ******************************************** */ /** Diagonal lines starting from bottom row * */ /** ******************************************** */ /** Stage 1 - Right top diagonal check */ /** ******************************************** */ /** - Starting from leftmost */ /** - Iterating to rightmost point */ /** ******************************************** */ for (int baseX = 0; baseX < BOARD_WIDTH; baseX++) { /* Assign starting point's state to the previous state */ int _prevState = _board[baseX][BOARD_HEIGHT - 1]; _occurrence.reset(0); for (int x = baseX, y = BOARD_HEIGHT - 1; (x < BOARD_WIDTH) && (y > 0); x++, y--) { int _currentState = _board[x][y]; if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) { if (_occurrence.isAtMax()) { System.out.println("Game over, DLBOTSTAGE1"); GameOver(_prevState); return true; } } _prevState = _currentState; } } _occurrence.reset(0); /** ******************************************** */ /** Stage 2 - Left top diagonal check */ /** ******************************************** */ /** - Starting from leftmost */ /** - Iterating to rightmost point */ /** ******************************************** */ for (int baseX = BOARD_WIDTH - 1; baseX > 0; baseX--) { /* Assign starting point's state to the previous state */ int _prevState = _board[baseX][BOARD_HEIGHT - 1]; _occurrence.reset(0); for (int x = baseX, y = BOARD_HEIGHT - 1; (x > 0) && (y > 0); x--, y--) { int _currentState = _board[x][y]; if (Counter.ComparePointAndCount(_prevState, _currentState, _occurrence)) { if (_occurrence.isAtMax()) { System.out.println("Game over, DLBOTSTAGE2"); GameOver(_prevState); return true; } } _prevState = _currentState; } } return false; }