How to re take move in 2D array for tic tac toe in Java? -


i making tic tac toe game. works fine except can't determine condition should write in order re-take invalid move.

this how move taken (there public method call these 2 private methods.)

private string gethumanmove() {     scanner in = new scanner(system.in);     system.out.println("enter move: ");     string str = in.next();     return str; }  private string getcomputermove() {     system.out.println("enter move: ");     random r = new random();     int r_row = r.nextint(3) +1;     int r_col = r.nextint(3) +1;     string str = string.valueof(r_row)+ string.valueof(r_col);     return str; } 

this isvalidmove() method

public boolean isvalidmove(string move) {     int row = (int)(move.charat(0)-'0');     int col = (int)(move.charat(1)-'0');      if(board[row-1][col-1] == ' ')     {         return true;     }     return false; } 

i tried using while loop within isvalidmove() didn't work. please show me how input move again?

something

string move; {      move = gethumanmove(); } while(!isvalidmove(move)); 

?


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -