
/*
Online Java - IDE, Code Editor, Compiler

Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/
import java.util.Scanner;

interface playConnectFour
{
    public void insertChip();
    public boolean checkAvailability(int input, int colour);
    public boolean checkConnectFour();
    
}

class connectFour implements playConnectFour 
{
    private int [][] board;
    int rows = 6;
    int columns = 7;
    int j;
    int input;
    
    Player1 p1 = new Player1(this, board);  // not sure why this object ref needs to be passed down
    //Player2 p2 = new Player2(this,board);
    
    
    public connectFour(int[][] board)
    {
        this.board=board;
        
    }
    
    public void insertChip()
    {
        
    }
    
    public boolean checkConnectFour()
    {
        
        //this will have to check if 4 in a row.
        
        // this will check first in the vertical direction
        
        int rowsBelow = j;
        int rowsAbove = (rows-1) -j;
        int verticalYellow=0;
        
        
        // CHECKING VERTICALLY
        
        for (int k = rowsBelow; k<j; k++)  // this is checking all rows below (same column) for yellows
        {
            if (board[k][input]==1)  //there is also a yellow in that position
            {
                verticalYellow++;
                
            }
        }
        
         for (int k = rowsAbove; k>j; k--)  // this is checking all rows below (same column) for yellows
        {
            if (board[k][input]==1)  //there is also a yellow in that position
            {
                verticalYellow++;
                
            }
        }
        
        if (verticalYellow==3)
        {
            System.out.println("connect 4");
            //perhaps need a function here to display the board array.
            return true;
        }
        
        return false;
        
    }
    
    public boolean checkAvailability(int input, int colour)
    {
        this.input=input;
        boolean availability=false;
        //yellow is being assigned value 1
        
        System.out.println("This is the input:" + input);
        
        for (j=0; j<7;j++)
        {
            System.out.println("value of j: " + j);
            
            System.out.println(board[0][1]);
            //System.out.println(board[j][input]);
            
            
            // the coin will drop to lowest position on the grid
            
            if (board[j][input]==0)   // all default values in declared array is 0
            {
                board[j][input]=1;  // this will input a 1 to denote yellow if available
                availability=true;
                checkConnectFour();
                break;
                
            }
            
        }
        
        
        
        if (availability)
        {
            return true;
            
        }
        
        p1.insertYellowChip();
        
        return false;
        
    }
    
}


public class Main
{
    public static void main(String[] args) {
    System.out.println("Welcome to Online IDE!! Happy Coding :)");
    
    int [][] board = new int [5][6];   // this ensures  7 columns and 6 rows
    
    connectFour cf = new connectFour(board);
    
    }
    
}

class Player1
{
    int[][] currentBoard;
    connectFour cf;
    chips yellow;
    
    Player2 p2;
    
    enum chips
    {
        YELLOW, RED;
    }
    
    
    public Player1(connectFour cf, int[][] currentBoard)
    {
        this.currentBoard=currentBoard;
        this.cf=cf;
        chips yellow = chips.YELLOW;
        this.yellow=yellow;
        
        
        insertYellowChip(yellow);
        p2=new Player2(currentBoard);
        
    }
    
   
    public void insertYellowChip(chips yellow)
    {
        System.out.println("Which column would you like to insert the coin");
        Scanner scan = new Scanner(System.in);
        int selection = scan.nextInt();
        
        cf.checkAvailability(selection,1);
        
        
    }
    
    public void insertYellowChip()
    {
        insertYellowChip(yellow);
    }
    
    
}


class Player2
{
    int[][]currentBoard;
    
    enum chips
    {
        YELLOW, RED;
    }
    
    
    public Player2(int[][] currentBoard)
    {
        this.currentBoard=currentBoard;
        //chips yellow = chips.YELLOW;
        chips red = chips.RED;
        insertRedChip(red);
    }
    
    public void insertRedChip(chips red)
    {
        
    }
    
    
}