Name: Anonymous 2011-02-22 18:31
public Piece getWinner(){
//HORIZONTAL WIN
//iterate through every square on the board except the squares on the last 3 columns
for(int i = 0; i < NUMROWS; i++ ){
for(int j = 0; j < NUMCOLS - 3; j++){
//check horiztonal condition and return whatever colour wins
if( theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i+1][j] &&
theBoard[i][j] == theBoard[i+2][j] &&
theBoard[i][j] == theBoard[i+3][j]
){
return theBoard[i][j];
}
}
}
//CHECK VERTICAL WIN
//every
for(int i = 0; i < NUMROWS - 3; i++){
for(int j = 0; j < NUMCOLS; j++){
if( theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i+1][j] &&
theBoard[i][j] == theBoard[i+2][j] &&
theBoard[i][j] == theBoard[i+3][j]
){
return theBoard[i][j];
}
}
}
//CHECK UPWARD DIAGONAL WIN //minas 4
for(int i = 0; i < NUMROWS -3; i++){
for(int j = 0; j < NUMCOLS -3; i++){
if( theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i+1][j+1] &&
theBoard[i][j] == theBoard[i+2][j+2] &&
theBoard[i][j] == theBoard[i+3][j+3]
){
return theBoard[i][j];
}
}
}
//CHECK DOWNWARD DIAGONAL WIN! //minas 1 numrows
for(int i = 3; i < NUMROWS; i++){
for(int j = 0; j < NUMCOLS - 3; j++){
if(theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i-1][j+1] &&
theBoard[i][j] == theBoard[i-2][j+2] &&
theBoard[i][j] == theBoard[i-3][j+3]
){
return theBoard[i][j];
}
}
}
return Piece.EMPTY;
}
//HORIZONTAL WIN
//iterate through every square on the board except the squares on the last 3 columns
for(int i = 0; i < NUMROWS; i++ ){
for(int j = 0; j < NUMCOLS - 3; j++){
//check horiztonal condition and return whatever colour wins
if( theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i+1][j] &&
theBoard[i][j] == theBoard[i+2][j] &&
theBoard[i][j] == theBoard[i+3][j]
){
return theBoard[i][j];
}
}
}
//CHECK VERTICAL WIN
//every
for(int i = 0; i < NUMROWS - 3; i++){
for(int j = 0; j < NUMCOLS; j++){
if( theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i+1][j] &&
theBoard[i][j] == theBoard[i+2][j] &&
theBoard[i][j] == theBoard[i+3][j]
){
return theBoard[i][j];
}
}
}
//CHECK UPWARD DIAGONAL WIN //minas 4
for(int i = 0; i < NUMROWS -3; i++){
for(int j = 0; j < NUMCOLS -3; i++){
if( theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i+1][j+1] &&
theBoard[i][j] == theBoard[i+2][j+2] &&
theBoard[i][j] == theBoard[i+3][j+3]
){
return theBoard[i][j];
}
}
}
//CHECK DOWNWARD DIAGONAL WIN! //minas 1 numrows
for(int i = 3; i < NUMROWS; i++){
for(int j = 0; j < NUMCOLS - 3; j++){
if(theBoard[i][j] != Piece.EMPTY &&
theBoard[i][j] == theBoard[i-1][j+1] &&
theBoard[i][j] == theBoard[i-2][j+2] &&
theBoard[i][j] == theBoard[i-3][j+3]
){
return theBoard[i][j];
}
}
}
return Piece.EMPTY;
}