0

why isnt it working?

why isnt it working? code: https://code.sololearn.com/cSSyEtqUZn0X

22nd Oct 2020, 2:10 PM
Yahel
Yahel - avatar
4 Answers
+ 1
hm.put(inpu, 'x') ; But should separate input from HashMap creation otherwise it is created new one every time and cause it's no use. And take static Scanner object at class level.
22nd Oct 2020, 3:29 PM
Jayakrishna 🇼🇳
0
Martin Taylor so what can I do?
22nd Oct 2020, 2:51 PM
Yahel
Yahel - avatar
0
there might be a simpler solution, but I try keep your idea: public class Main { //... static HashMap<String,Position> hm = new HashMap<>(); static Position[][] ticTacToe = new Position[3][3]; class Position { char value = ' '; public String toString() {return String.valueOf( value );} } { for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { ticTacToe[i][j] = new Position(); }} hm.put("top left" , ticTacToe[0][0]); //... --- public static void main(String[] args) { var m = new Main(); m.printBoard(m.ticTacToe); while (m.goodAttemps < 9) { m.game(); } } --- public static void printBoard(Position[][] arr) { //... --- public static void takeInputAndCheckValid() { //... if (containsSpot == 9) { //... } else { Position position = hm.get(input); if (position.value == ' ') { position.value = turn; //...
23rd Oct 2020, 10:32 PM
zemiak