Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

DEBUG MY CODE BITCHES

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;
  }

Name: Anonymous 2011-02-22 18:32

So basically its a connect 4 program. NUMCOLS is set to 8 and NUMROWS is set to 6. This is the method that figures out if somebody has connected 4

Name: Anonymous 2011-02-22 20:18

How wasteful.  Why don't you just check the last piece added.

Name: Anonymous 2013-04-22 22:15

aye

Don't change these.
Name: Email:
Entire Thread Thread List