/** * Handle command line from user. * * @return true if quit command received. */ private boolean handleCommand(String cmdLine) { String[] cmdArray = StringUtil.splitArguments(cmdLine); String cmd = cmdArray[0]; if (cmd.equals("quit")) { send("quit"); return true; } if (cmd.equals("genmove")) genmove(); else if (cmd.equals("help")) help(); else if (cmd.equals("list")) listCommands(); else if (cmd.equals("load")) load(cmdArray); else if (cmd.equals("newgame")) newGame(cmdArray); else if (cmd.equals("save")) save(cmdArray); else if (cmd.equals("undo")) undo(cmdArray); else if (GtpUtil.isStateChangingCommand(cmd)) System.out.println("Command not allowed"); else { try { GoPoint point = GtpUtil.parsePoint(cmdLine, m_board.getSize()); cmdPlay(point); } catch (GtpResponseFormatError e) { StringBuilder response = new StringBuilder(); send(cmdLine, response); System.out.println(response); } } return false; }
private void genmove() { GoColor toMove = m_board.getToMove(); String command = m_gtp.getCommandGenmove(toMove); StringBuilder response = new StringBuilder(); if (!send(command, response)) { System.out.println(response); return; } try { GoPoint point = GtpUtil.parsePoint(response.toString(), m_board.getSize()); System.out.println("Computer move: " + GoPoint.toString(point)); play(Move.get(toMove, point)); printBoard(); } catch (GtpResponseFormatError e) { System.out.println(response); } }