Need help with connect 4 program!!!

0 Aaron Hebert · June 30, 2014
For some reason, when either player 1 or AI reaches 4 in a row, it doesn't place a winner. Thanks in advance!
import java.util.*;
public class Connectfourgame
{

public static final char nullChar = '\u0000';
public static final char player1 = 'R';
public static final char playerPC = 'B';

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

//Print out title of game.
System.out.println("//////CONNECT 4//////");
System.out.println("*********************");
System.out.println("---------------------");
System.out.println();

//create an array string
char [][] board = new char[6][7];
int inputCol = 0;
boolean gameWon = false;



while(gameWon == false)
{


//public static void playerDropDisk (char[][] board, int index,)
//{
//Ask where Red goes.
System.out.println("Player RED: Please Drop a disk at column (0-6).");
inputCol = input.nextInt();
int c = (int)(Math.random() *7);


for (int row = 5; row >=0; row--)
{
if (board == nullChar)
{
board = 'B';
}
else
{
printBoard(board);

}


}

}

}







//create pattern method
public static void printBoard (char [][] board)
{
for( int row = 0; row < board.length; row++)
{
//System.out.print("");
for( int column = 0; column < board == playerColor
&& board == board
&& board == board
&& board == board)
{
return true;
}

else if (row < 3 && board == playerColor
&& board == board
&& board == board
&& board == board)
{
return true;
}

if (row < 3 && col <=3
&& board == playerColor
&& board == board
&& board == board
&& board == board)
{
return true;
}

if (row < 3 && col >=3
&& board == playerColor
&& board == board
&& board == board
&& board == board)
{
return true;
}

}
}
return false;
}



//If there is a piece in every slot in top row then it is a Cat Game

public static boolean catGame(char board[][])
{
for (int col = 0; col < board[0].length; col++)
{
if (board[0] == nullChar)
{
return false;
}
}
return true;
}
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Pere Garau Burguera · July 2, 2014
In the while loop you need to check if the game is won and refresh the variable gameWon for the while loop condition. Otherwise, gameWon will always be false and the game will never end
  • 1

Java / Android Development

107,094 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator