import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class BingoGame {
public static void main(String[] args) throws IOException {
int card[][] = {{100,200,300,400,500,},
{100,200,300,400,500,},
{100,200,300,400,500,},
{100,200,300,400,500,},
{100,200,300,400,500,}};
Vector cardNumV = new Vector();
int cardNum = 0;
String cardNums[][];
String cardstring;
try{
FileInputStream fstream = new FileInputStream("CardNumbers.txt");
BufferedReader fin = new BufferedReader(new InputStreamReader(fstream));
while (fin.ready() != false) {
cardNumV.add(fin.readLine());
}
fin.close();
fstream.close();
cardNums = new String[cardNumV.size()][25];
for (int i = 0; i < cardNumV.size(); i++){
String temp[] = ((String) cardNumV.elementAt(i)).split("\\,");
cardNums[i] = temp;
}
}
catch (Exception e) {
System.err.println("File input error");
cardNums = new String[0][25];
}
for (int i = 0; i < cardNums.length; i++){
}
Random randomGenerator = new Random();
boolean CardDone = false;
boolean B = false;
boolean B_Repick = false;
boolean I = false;
boolean I_Repick = false;
boolean N = false;
boolean N_Repick = false;
boolean G = false;
boolean G_Repick = false;
boolean O = false;
boolean O_Repick = false;
while (CardDone == false) {
boolean PickNums = false;
while (PickNums == false) {
for (int a = 0; a < 5; a++) {
for (int b = 0; b < 5; b++) {
if (card[a][b] == 100) {
card[a][b] = randomGenerator.nextInt(15)+1;
}
else if (card[a][b] == 200) {
card[a][b] = randomGenerator.nextInt(15)+16;
}
else if (card[a][b] == 300) {
card[a][b] = randomGenerator.nextInt(15)+31;
}
else if (card[a][b] == 400) {
card[a][b] = randomGenerator.nextInt(15)+46;
}
else if (card[a][b] == 500) {
card[a][b] = randomGenerator.nextInt(15)+61;
}
}
}
PickNums = true;
}
boolean CheckNums = false;
while (CheckNums == false && PickNums == true) {
while (B == false && B_Repick == false) { //Checks all B's Numbers
if (card[0][0] == card[1][0] || card[0][0] == card[2][0] || card[0][0] == card[3][0] ||
card[0][0] == card[4][0] || card[1][0] == card[2][0] || card[1][0] == card[3][0] ||
card[1][0] == card[4][0] || card[2][0] == card[3][0] || card[2][0] == card[4][0] ||
card[3][0] == card[4][0]) {
B = false;
B_Repick = true;
}
else {
B = true;
}
}
while (I == false && I_Repick == false) { //Checks all I's Numbers
if (card[0][1] == card[1][1] || card[0][1] == card[2][1] || card[0][1] == card[3][1] ||
card[0][1] == card[4][1] || card[1][1] == card[2][1] || card[1][1] == card[3][1] ||
card[1][1] == card[4][1] || card[2][1] == card[3][1] || card[2][1] == card[4][1] ||
card[3][1] == card[4][1]) {
I = false;
I_Repick = true;
}
else {
I = true;
}
}
while (N == false && N_Repick == false) { //Checks all N's Numbers
if (card[0][2] == card[1][2] || card[0][2] == card[2][2] || card[0][2] == card[3][2] ||
card[0][2] == card[4][2] || card[1][2] == card[2][2] || card[1][2] == card[3][2] ||
card[1][2] == card[4][2] || card[2][2] == card[3][2] || card[2][2] == card[4][2] ||
card[3][2] == card[4][2]) {
N = false;
N_Repick = true;
}
else {
N = true;
}
}
while (G == false && G_Repick == false) { //Checks all G's Numbers
if (card[0][3] == card[1][3] || card[0][3] == card[2][3] || card[0][3] == card[3][3] ||
card[0][3] == card[4][3] || card[1][3] == card[2][3] || card[1][3] == card[3][3] ||
card[1][3] == card[4][3] || card[2][3] == card[3][3] || card[2][3] == card[4][3] ||
card[3][3] == card[4][3]) {
G = false;
G_Repick = true;
}
else {
G = true;
}
}
while (O == false && O_Repick == false) { //Checks all O's Numbers
if (card[0][4] == card[1][4] || card[0][4] == card[2][4] || card[0][4] == card[3][4] ||
card[0][4] == card[4][4] || card[1][4] == card[2][4] || card[1][4] == card[3][4] ||
card[1][4] == card[4][4] || card[2][4] == card[3][4] || card[2][4] == card[4][4] ||
card[3][4] == card[4][4]) {
O = false;
O_Repick = true;
}
else {
O = true;
}
}
boolean Reset = false;
while (Reset == false) { //reset values of incorrect columns
if (B_Repick == true) {
card[0][0] = 100;
card[1][0] = 100;
card[2][0] = 100;
card[3][0] = 100;
card[4][0] = 100;
B_Repick = false;
}
if (I_Repick == true) {
card[0][1] = 200;
card[1][1] = 200;
card[2][1] = 200;
card[3][1] = 200;
card[4][1] = 200;
I_Repick = false;
}
if (N_Repick == true) {
card[0][2] = 300;
card[1][2] = 300;
card[2][2] = 300;
card[3][2] = 300;
card[4][2] = 300;
N_Repick = false;
}
if (G_Repick == true) {
card[0][3] = 400;
card[1][3] = 400;
card[2][3] = 400;
card[3][3] = 400;
card[4][3] = 400;
G_Repick = false;
}
if (O_Repick == true) {
card[0][4] = 500;
card[1][4] = 500;
card[2][4] = 500;
card[3][4] = 500;
card[4][4] = 500;
O_Repick = false;
}
Reset = true;
PickNums = false;
}
if (B == true && I == true && N == true && G == true && O == true) {
CheckNums = true;
CardDone = true;
cardstring = cardNum + "," + card[0][0] + "," + card[1][0] + "," + card[2][0] + "," + card[3][0] + "," + card[4][0] + "," +
card[0][1] + "," + card[1][1] + "," + card[2][1] + "," + card[3][1] + "," + card[4][1] + "," +
card[0][2] + "," + card[1][2] + "," + card[2][2] + "," + card[3][2] + "," + card[4][2] + "," +
card[0][3] + "," + card[1][3] + "," + card[2][3] + "," + card[3][3] + "," + card[4][3] + "," +
card[0][4] + "," + card[1][4] + "," + card[2][4] + "," + card[3][4] + "," + card[4][4];
try {
BufferedWriter fout = new BufferedWriter(new FileWriter("CardNum.txt"));
fout.write(cardstring + "\n");
fout.close();
}
catch (Exception e) {
System.err.println("File output error");
}
cardNum++;
System.out.println("Card Number: " + cardNum);
}
}
}
//System.out.println("");
System.out.println("B \t I \t N \t G \t O");
for (int i = 0; i < 5; i++) {
System.out.println(" ");
for (int j = 0; j < 5; j++) {
System.out.print(card[i][j] + "\t ");
}
}
}
}