In my main class I have this input method:
private static void userInput(char[][] board){
System.out.println("Select your pos 1-9");
int roundCount = 0;
while(board != null && roundCount < 10){
int pos = new java.util.Scanner(System.in).nextInt();
/*while(spielerPos.contains(pos) || comPos.contains(spielerPos)){
System.out.println("Position besetzt. versuchen Sie bitte nochmal!");
pos = new java.util.Scanner(System.in).nextInt();
}*/
Random rdm = new Random();
int comPos = rdm.nextInt(9) + 1; //the AI can replace this line to inject pos
/*while(spielerPos.contains(comPos) || spielerPos.contains(comPos)){
comPos = rdm.nextInt(9) + 1;
}*/
caseDecision(board, pos, "human");
caseDecision(board, comPos, "com");
roundCount++;
}
crl.trackPositions();
}
The very last line crl.trackPositions();
shall bring me to operate another class:
static String winOrLose(List topRow, List midRow, List botRow, List leftCol, List midCol, List rightCol, List diagonal1, List diagonal2){
new Tic_Tac_Toe(); //calling my main class here
List iWon = new ArrayList<>();
iWon.add(topRow);
iWon.add(midRow);
iWon.add(botRow);
iWon.add(leftCol);
iWon.add(midCol);
iWon.add(rightCol);
iWon.add(diagonal1);
iWon.add(diagonal2);
for(var l: iWon){
if(spielerPos.containsAll((Collection<?>) l )){
return "you won!";
} else if (comPos.contains(l)){
return "com won, try again";
} else if (spielerPos.size() + comPos.size() == 9) { //board is full
return "we're all tied";
}
}
return "have you seen me";
}
But my program does not display anything from the other class (it was supposed to pring who was the winner, me or cpu) - it simply ends itself once I completed the 10th round with a cpu.
Could anyone kindly point me in the right direction?
My full codes are here TTT_experiements/ColRowLists.java at master · morry239/TTT_experiements · GitHub and here TTT_experiements/Tic_Tac_Toe.java at master · morry239/TTT_experiements · GitHub (this is my main class).