import mc600.gamemanager.*; import mc600.boardgames.*; /** * Meu jogadorzinho */ public class Meidanis { private static mc600.gamemanager.PlayerServer player; private static boolean fechei = false; /** * Classe principal, responsavel pela organizacao do "campeonato" * Dispara varias threads do objeto Juiz, fazendo com que todos os * jogadores joguem entre si. * * Os jogadores devem estar conectados a uma porta TCP, dentro da faixa * determinada pelo objeto "Player", antes do inicio do campeonato. * * Ao final do campeonato gera um html com a classificacao dos jogadores. * */ public Meidanis() { super(); } /** * Starts the application. * @param args an array of command-line arguments */ public static void main(String[] args) { // Insert code to start the application here. String myMove = "", reply; String name = args[0]; try{ player = new PlayerServer(name); while(true){ // iniciando o jogo // constroi novo tabuleiro, inicialmente vazio StickBoard board = new StickBoard(Player.XDIM, Player.YDIM); try{ reply = player.waitClient(); boolean advFechou = false; while(true) { System.out.println(name + " got " + reply); if (!reply.equals(Player.STARTCMD) && !fechei) { advFechou = marcaLance(reply,board); } if (!advFechou) { // bolaLance also marks it, // and sets boolean fechei myMove = bolaLance(board); } else { myMove = reply; } System.out.println(name + " did " + myMove); reply = player.play(myMove); } //-------------------- fim do seu codigo } catch (Exception e) { System.out.println("Jogo encerrado: "+ e.getMessage()); } // end catch // Saiu do bloco... player.shutdown(); } // end while }catch(Exception e){ System.out.println("Sistema reportou erro: " + e.getMessage()); } } public static boolean marcaLance (String move, StickBoard board) { try { // opponent is not P1; I am P1 // so, second parameter is FALSE return board.play(move,false); } catch (InvalidCastException e) { System.err.println("something wrong: received bad move"); return false; } } public static String bolaLance (StickBoard board) { // try all possible moves, until one works for(int i=1; i<=Player.XDIM; i++) for(int j=1; j