package GPN; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.LoggerConfig; import javax.swing.*; import java.io.*; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; public class BotGame { private static boolean respawn = true; private boolean kill = false; private boolean switchItharder = false; private Queue returnMsgs = new ConcurrentLinkedQueue<>(); Object syncer = new Object(); static Logger l = LogManager.getLogger(); private int[] []board = new int[1][1]; int[][] boards; int[][] boardFF; int ticksSinceStart = 0; int[][] tickets = null; boolean danger = false; private int cx=0,cy=0,cw=1,ch=1; private String playerid; int playercount = 0; boolean[][] headBuffer; int lastDir = 0; String debugdir = " "; boolean gaming = false; boolean switcheroo=false; public static void main(String[] args) { setupLogging(true,2); l.info("shizzlemork"); while(true) { try{ l.info("LOOP, spawning new bot"); new BotGame().game(); } catch (Error e){l.error(e);} //H4x catch (Exception e){l.error(e);} //H4x } } int lastcase=-1; private int boardFF(int x, int y, int id) { int cni = y-1; if(cni==-1) cni=ch-1; int csi=(y+1)%ch; int cwi = x-1; if(cwi==-1) cwi=cw-1; int cei=(x+1)%cw; return boardFF(x,y,id,0); } Queue FFQueue = new LinkedList<>(); private int boardFF(int x, int y,int id,int g) { FFQueue.add(new int[]{x,y,g}); return boardFF(id); } int heads_touched = 0; private int boardFF(int id) { int rv_r=0; while(!FFQueue.isEmpty()) { int rv=0; int[] ffq = FFQueue.remove(); int x=ffq[0]; int y=ffq[1]; int g=ffq[2]; if(boardFF[y][x]!=0) { if(boardFF[y][x]>0&&boardFF[y][x]!=id&&g==0) { l.info("1337#d"); rv_r += -1337; continue; } rv_r+=0; continue; } rv = 2 ; int cni = y-1; if(cni==-1) cni=ch-1; int csi=(y+1)%ch; int cwi = x-1; if(cwi==-1) cwi=cw-1; int cei=(x+1)%cw; if(headBuffer[y][cwi]||headBuffer[y][cei]||headBuffer[csi][x]||headBuffer[cni][x]) { rv_r+= g==0?1:0; heads_touched++; continue; } boardFF[y][x]=id; if(g<15) { FFQueue.add(new int[]{x, cni, g + 1}); FFQueue.add(new int[]{x, csi, g + 1}); FFQueue.add(new int[]{cwi, y, g + 1}); FFQueue.add(new int[]{cei, y, g + 1}); } rv_r+=rv; } return rv_r; } static void setupLogging(boolean verbose,int verbosityLevel) { System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager"); //HACK to catch java.util.logging loggers l=LogManager.getLogger(); LoggerContext cx = (LoggerContext) LogManager.getContext(false); org.apache.logging.log4j.core.config.Configuration config = cx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); LoggerConfig vlcj = config.getLoggerConfig("uk.co.caprica.vlcj"); LoggerConfig externalloggerConfig = config.getLoggerConfig("External"); LoggerConfig trueVFSlloggerConfig = config.getLoggerConfig("net.java"); if (verbose) { loggerConfig.setLevel(Level.TRACE); if(verbosityLevel>1) { vlcj.setLevel(Level.TRACE); externalloggerConfig.setLevel(Level.TRACE); trueVFSlloggerConfig.setLevel(Level.TRACE); } else { vlcj.setLevel(Level.INFO); externalloggerConfig.setLevel(Level.INFO); trueVFSlloggerConfig.setLevel(Level.INFO); } } else { loggerConfig.setLevel(Level.INFO); externalloggerConfig.setLevel(Level.INFO); trueVFSlloggerConfig.setLevel(Level.INFO); } cx.updateLoggers(); } public void game(){ if(System.getProperties().containsKey("botdebug")) { returnMsgs.add("join|Red5-devel|mösenpilze-8=====D-fdewcugeww"); } else { returnMsgs.add("join|Red5|mösenpilze-8=====D-fdewcugewgw"); } try { SocketAddress scka=new InetSocketAddress(InetAddress.getByName("gpn-tron.duckdns.org"), 4000); Socket sck = new Socket(); sck.connect(scka,1000); BufferedReader r = new BufferedReader(new InputStreamReader(sck.getInputStream())); PrintStream out = new PrintStream(sck.getOutputStream(),true,"UTF-8"); String jm = returnMsgs.poll(); System.out.print(jm+'\n'); out.print(jm+'\n'); out.flush(); //Thread t = new Thread(()->{ while(sck.isConnected()) { if(sck.isClosed()) { return; } if(kill) { return; } //l.trace("Munching ahead..."); String request = ""; try { String ln = r.readLine(); //if(gaming) // l.trace("packet line = "+ln); if(ln!=null) { if(ln.contains("message")) { continue; } if(ln.contains("lose")) { if(boards==null) { l.info("Boards nulled?"); kill=true; respawn=true; } String boardview = "\nDumping Core....\nDone:\n"; for(int i=0;i9&&board[cs][cx]>9&&board[cy][ce]>9&&board[cy][cw_]>9) { l.info("giving up?"); randomDone=true; lastcase=3; } int west=0,east=0,south=0,north=0; if(ticksSinceStart >0) { if(ticksSinceStart <0) {east = boardFF(ce, cy,1); west = boardFF(cw_, cy,2); north = boardFF(cx, cn,3); south = boardFF(cx, cs,4); } else { //int rnd = (int) (Math.random()*6); //int rnd=(fuck/13)%4; int rnd=lastDir; if(ticksSinceStart %100==0) returnMsgs.add("chat|Stay on Target! Stay on Target!"); if(ticksSinceStart %100==50) returnMsgs.add("chat|Red 5 standing by"); if(ticksSinceStart %100==75) returnMsgs.add("chat|rm -rf ~/botarmee*"); String lmaa = returnMsgs.poll(); l.info("22MP="+lmaa); out.print(lmaa+'\n'); out.flush(); l.info("lastdir"+lastDir); //boolean switcheroo = new File("/home/lh/switch").exists(); switch(rnd) { case 3://prev=east if(switcheroo) south = boardFF(cx, cs,1); else north = boardFF(cx, cn,2); east = boardFF(ce, cy,3); if (switcheroo) north = boardFF(cx, cn,2); else south = boardFF(cx, cs,1); west = boardFF(cw_, cy,4); l.info("lnesw"+lastDir+";"+north+";"+east+";"+south+";"+west); break; case 1: //prev=west if(switcheroo) north = boardFF(cx, cn,1); else south = boardFF(cx, cs,2); west = boardFF(cw_, cy,3); if (switcheroo) south = boardFF(cx, cs,2); else north = boardFF(cx, cn,1); east = boardFF(ce, cy,4); break; case 2://prev=down if(switcheroo)west = boardFF(cw_, cy,1); else east = boardFF(ce, cy,2); south = boardFF(cx, cs,3); if(switcheroo)east = boardFF(ce, cy,2); else west = boardFF(cw_, cy,1); north = boardFF(cx, cn, 4); break; case 0: //prev=up if(switcheroo)east = boardFF(ce, cy,1); else west = boardFF(cw_, cy,2); north = boardFF(cx, cn,3); if(switcheroo) west =boardFF(cw_, cy,2); else east =boardFF(ce, cy,1); south = boardFF(cx, cs,4); break; } } } else{ if(ticksSinceStart <30) { south = boardFF(cx, cs,1); north = boardFF(cx, cn,2); west = boardFF(cw_, cy,3); east = boardFF(ce, cy,4); } } ticksSinceStart++; int highest=Math.max(Math.max(north,south),Math.max(west,east)); l.info("hnesw"+highest+";"+north+";"+east+";"+south+";"+west); if( ( (ticksSinceStart <20 ||(ticksSinceStart >40 && ticksSinceStart <60) ||(500+ ticksSinceStart -330)%500<30) ||(playercount<3&&(ticksSinceStart %100<50) ) )&&highest>1000) { l.info(ticksSinceStart <20); l.info(((500+ ticksSinceStart -330)%500)<30); l.info("remappingparty"); if(east==-1337) east=highest; if(west==-1337) west=highest; if(south==-1337) south=highest; if(north==-1337) north=highest; } else { { if(east==-1337) east=0; if(west==-1337) west=0; if(south==-1337) south=0; if(north==-1337) north=0; } } if((highest<((cw*ch)/(playercount+1))||playercount<3)) { l.info("Switcheroo zone reached"); if(ticksSinceStart %10==0) { l.info("chkFlick"); if(heads_touched<2&&playercount>5&&ticksSinceStart>150) { l.info("headcount:"+heads_touched); switcheroo=!switcheroo; } if((ticksSinceStart /10)%3<2) { l.info("flick"); switcheroo=!switcheroo; } } } l.info("switcheroo="+switcheroo); l.info("fnesw"+ ticksSinceStart +";"+north+";"+east+";"+south+";"+west); int rnd=(int)(Math.random()*4); if(ticksSinceStart %300<25&& ticksSinceStart >15) { rnd=0; } int lastchoice=-1; int treshold=1; while(!randomDone) { //rnd = (int) (Math.random()*4); //rnd=lastchoice; /*lastchoice+=1; if(lastchoice>3) { lastchoice=0; treshold++; } if(treshold>3) { }*/ //l.info("rnd="+rnd+"lastcse="+lastcase); /*if(rnd==lastcase) { l.info("reroll"); continue; }*/ if(highest<10) { returnMsgs.add("chat|godmayFUCKingdamnit=="+";"+north+";"+east+";"+south+";"+west); l.info("GMFDI"); out.print(returnMsgs.poll()+'\n'); out.flush(); } switch(rnd) { case 1: //if((board[cy][cw_]>>move|"+direction+'\n'); out.flush(); } } else { l.info("SCK:"); l.info(sck.isClosed()); l.info(sck.isConnected()); l.info(sck.isInputShutdown()); kill=true; respawn=true; throw new Error(); } } catch (IOException ex) { //l.warn("NETZAP"); return; //break; } //l.trace(request); } //}); //t.setName("InputCruncher"); //t.start(); /*Thread t2 = new Thread(()->{ //System.out.println("Gefangen!"); try { while(sck.isConnected()) { if(kill) { l.info("time to say goodbye"); return; } synchronized(syncer) { mösenpilze++; if(mösenpilze>300000000) { mösenpilze=0; l.info("WHY THZE FUDGE"); } while(!returnMsgs.isEmpty()) { mösenpilze=0; submöse++; if(submöse>3) { möseon=true; } // FUCK YOU DUMB IDIOT; NO THREAD.SLEEP() HERE!!!!!11!!11elf String returnMsg = returnMsgs.poll(); if(returnMsg == null) { submöse2++; if(submöse2<3) { l.trace("22MP"); } else { if(submöse2==4) { l.trace("Hodentasche"); submöse2=0; returnMsgs = new ConcurrentLinkedQueue<>(); //kill=true; //respawn=true; //sck.close(); //return; } } continue; } out.print(returnMsg+'\n'); out.flush(); l.trace("PKT="+returnMsg); out.print(returnMsg+'\n'); out.flush(); } //l.trace("end of MessageStream"); } } } catch (Exception e) { l.error("ZZMP"); l.error(e); System.exit(1337); } System.out.println("Flucht ist zwecklos"); System.exit(1337); }); t2.setName("OutputCruncher"); t2.start();*/ l.info("asdfqwxix"); } catch (IOException ex) { respawn=true; ex.printStackTrace(); l.error(" Unable to connect to Host. Aborting now"); try { Thread.sleep(199); } catch (InterruptedException e) { throw new RuntimeException(e); } } } //int submöse2=0; //int submöse=0; //boolean möseon=false; //long mösenpilze = 0; }