package Proyectos;

import java.util.Random;
import java.util.Scanner;

public class HundirLaFlota {
    //OBJETOS
    static Random rd = new Random();
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        //VARIABLES

        String[] nombreJugadores = new String[2];
        /*
        nombreJugadores[0] → Usuario.
        nombreJugadores[1] → CPU
        */
        char[][] tablero1 = new char[10][10];
        char[][] tablero2 = new char[10][10];

        //CONSTANTES


        //Código ------

        System.out.println("Introduce el nombre del Jugador 1: ");
        nombreJugadores[0] = sc.nextLine();
        //Se establece el nombre del J2.
        nombreJugadores[1] = "CPU";

        generarTablero(tablero1,4);
        generarTablero(tablero2,4);
    }

    public static void generarTablero(char[][] tablero, int posicionesPorBarco) {
        final int LIMITE_Y = 9+1;
        final int LIMITE_X= 9+1-posicionesPorBarco+1;
        //Se realiza la suma de 1 unidad, debido a que, cuando se genera el número random no incluye el número dado.

        for (int j = 0; j < 3; j++) {

            int y = rd.nextInt(LIMITE_Y);
            int x = rd.nextInt(LIMITE_X);

            // VALIDACIÓN
            if (validarSiguienteBarco(tablero,posicionesPorBarco,x,y)) {

                for (int i = x; i < x + posicionesPorBarco; i++) {
                    tablero[y][i] = 'B';
                }
            }else{
                j--;
            }
        }

    }
    public static boolean validarSiguienteBarco(char[][] tablero, int posicionesPorBarco,int x,int y){
        for (int i = x; i < x+posicionesPorBarco; i++) {
            if (tablero[y][i] != '\u0000'){ //'\u0000' es == NULL en char
                return false;
            }
        }
        return true;
    }

}
