From 14e77646ff5cea1b837db067cddd39f116d39f46 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 12 Feb 2025 11:30:44 +0100 Subject: [PATCH] =?UTF-8?q?src=20gel=C3=B6scht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + ProgA-Bot.iml | 11 ++ out/production/ProgA-Bot/.idea/.gitignore | 8 ++ out/production/ProgA-Bot/.idea/misc.xml | 6 + out/production/ProgA-Bot/.idea/modules.xml | 8 ++ out/production/ProgA-Bot/.idea/vcs.xml | 6 + out/production/ProgA-Bot/ProgA-Bot.iml | 11 ++ out/production/ProgA-Bot/README.md | 3 + out/production/ProgA-Bot/src/Bot$View.class | Bin 0 -> 1402 bytes out/production/ProgA-Bot/src/Bot.class | Bin 0 -> 2662 bytes out/production/ProgA-Bot/src/EscapeBot.class | Bin 0 -> 1273 bytes out/production/ProgA-Bot/src/ManualBot.class | Bin 0 -> 1195 bytes out/production/ProgA-Bot/src/RumbleBot.class | Bin 0 -> 1719 bytes out/production/ProgA-Bot/src/SnakeBot.class | Bin 0 -> 2192 bytes out/production/ProgA-Bot/src/test.class | Bin 0 -> 1141 bytes src/Bot.java | 88 +++++++++++++ src/EscapeBot.java | 49 +++++++ src/ManualBot.java | 34 +++++ src/RumbleBot.java | 92 +++++++++++++ src/SnakeBot.java | 128 +++++++++++++++++++ src/test.java | 31 +++++ 24 files changed, 503 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 ProgA-Bot.iml create mode 100644 out/production/ProgA-Bot/.idea/.gitignore create mode 100644 out/production/ProgA-Bot/.idea/misc.xml create mode 100644 out/production/ProgA-Bot/.idea/modules.xml create mode 100644 out/production/ProgA-Bot/.idea/vcs.xml create mode 100644 out/production/ProgA-Bot/ProgA-Bot.iml create mode 100644 out/production/ProgA-Bot/README.md create mode 100644 out/production/ProgA-Bot/src/Bot$View.class create mode 100644 out/production/ProgA-Bot/src/Bot.class create mode 100644 out/production/ProgA-Bot/src/EscapeBot.class create mode 100644 out/production/ProgA-Bot/src/ManualBot.class create mode 100644 out/production/ProgA-Bot/src/RumbleBot.class create mode 100644 out/production/ProgA-Bot/src/SnakeBot.class create mode 100644 out/production/ProgA-Bot/src/test.class create mode 100644 src/Bot.java create mode 100644 src/EscapeBot.java create mode 100644 src/ManualBot.java create mode 100644 src/RumbleBot.java create mode 100644 src/SnakeBot.java create mode 100644 src/test.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a6e1098 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b41d4a1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProgA-Bot.iml b/ProgA-Bot.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ProgA-Bot.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/ProgA-Bot/.idea/.gitignore b/out/production/ProgA-Bot/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/out/production/ProgA-Bot/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/out/production/ProgA-Bot/.idea/misc.xml b/out/production/ProgA-Bot/.idea/misc.xml new file mode 100644 index 0000000..a6e1098 --- /dev/null +++ b/out/production/ProgA-Bot/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/ProgA-Bot/.idea/modules.xml b/out/production/ProgA-Bot/.idea/modules.xml new file mode 100644 index 0000000..b41d4a1 --- /dev/null +++ b/out/production/ProgA-Bot/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/ProgA-Bot/.idea/vcs.xml b/out/production/ProgA-Bot/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/out/production/ProgA-Bot/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/ProgA-Bot/ProgA-Bot.iml b/out/production/ProgA-Bot/ProgA-Bot.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/out/production/ProgA-Bot/ProgA-Bot.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/ProgA-Bot/README.md b/out/production/ProgA-Bot/README.md new file mode 100644 index 0000000..1b6b3b5 --- /dev/null +++ b/out/production/ProgA-Bot/README.md @@ -0,0 +1,3 @@ +# ProgA-Bot + +Jeder erstellt seinen eigenen Branch und wir mergen am ende das was am besten funktioniert \ No newline at end of file diff --git a/out/production/ProgA-Bot/src/Bot$View.class b/out/production/ProgA-Bot/src/Bot$View.class new file mode 100644 index 0000000000000000000000000000000000000000..3409b25dad4cfa90918a5d5dffcc48fb4cee75b5 GIT binary patch literal 1402 zcmZuw%Tg0T6g{08m?Vw@Q2~h$@EKwxzF&c;phz@46f2fHCrOK=VJ0;*@v-+y*tpix zSfy1iwaTqO;0O2vS}LBN1O?+_x^GY4d+t5w-v0FK?Rx+dScoG6&46yA3*7>}53EO4 zwq`j?+4=GVSqTKX$8EX|iG0s?v+YfELFlmE{afv88LXggA1TWYlUFJvx;J|qlmHL(rb1x(+oWGCHVf611Q z1@x*FSOSU8I90@ei9zgO=~lfiovOf*RHtKS&Nhu)97*gnu*<}5?Af46i!Om{(pd`b zhnf^rr6VTxVxK_QW4o&Ui-M}-fQf@jglOQlB4bEl)Ii$AVPrNUKlKB-OhC6m&9}G8 zrECk-H(;=|mczQnOk{CXAm%s9ekeXQP8ABBZ0LR*Ck&i4aSEpewyt$z9i)I!R|#qk zbN)}G5~ZGUt87w_>eXChxh%a~R=LJMiK1JvY9-6F)w%ss5ANH(z?S0re&vXw+AWZ5 zC+Qf7+$d8CTOeYymcc*#H;xT~B7Rw5M@Ku?dMB`XF|aBRXRUg>qWG0365iwIv?1iG4GTDlq%?i!d7-CWP`l;tkCcctGzyr2=mS+43D$l)AUv*m#E zJgfV0KHW$d{5gaN=H9`$^9Hfm^x-DruhE-+h2D?QUu2ZgME~t{%NTl%VLiW#hv5|@ zGRj-sKGVeW)vxJH6Z;vgs?fqJ#`v6pONe3;y_muPF7s_oliXEgFoV-5-~#t6xQF zQ*e1jYPj}hr3N2Y2sMR9)G_2h{6tKMZ|tr{IaGtLQ4X~iNg0SU KzK`}iV!r{)3oE+- literal 0 HcmV?d00001 diff --git a/out/production/ProgA-Bot/src/Bot.class b/out/production/ProgA-Bot/src/Bot.class new file mode 100644 index 0000000000000000000000000000000000000000..70468d6ac7b7e6f6b9733882028f099723e08b1c GIT binary patch literal 2662 zcmaJ@SyS6q6#g!j5q6Z2m_UFu2}wx;hTtr1N-9cw)r(098k;!XD+7+nnH!ahBSRl~RIbMf4fl$s)>$$95a6<@V ziwaG{R%{bc3r;#VVADvEQh`Wv4KL+7rZp80V>@=Jh-hfQPJtb33JJ?KrVK}*F0VTU zgG+(Nj*SSNi2(4|AM)&78k*6<)aj!sYMUtS{ zm!8UG9HUSOV-MOS3;P9{HaRuXIWBST)z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z(z+P(Y!)~Np7A=~pucsreG_ky)$6F||J(c`tEJq@j3p3Sr9sfkSgVS& zDxxYcUU`)ynM@X%FOtc;unJZF9%6E-dcoTY{tYpp;!?e$$eWf2yhB)p?67un#K4OQV4{gXz#nBivu&WL51rXL-)+8gzUi;u-+uzQhIs=q#C2#Uy3j442YzjO z-U|h~XC2oG=L80Gk19{?b$fc%cI(qiq3^i$VtzS^1d=)o6Fo2mQYvsEsM%{W3hxO* zxmNO;ZYX^LQC9A06B*^344b|i*%aDqA{(LWj(mBKHKaoOO$;bB9fZE^)Ei+%y7jPO z&=gn8u!#{I5QzItmupU4XbcB+95Qhj;{s;8lgVYK70_1f&=$!4+e!jQc|p&>B#!Ag zZsG)T0@mLx3nXfu8`_Q=2#n@B@{}63za(EYrCXE5{6m$fU}6d<*=f+MvH>!tcr2Im z9bs)Id9{+aA_X!P$CZoC=T+(7x2vl}vK6mpuP)oZqt0zm3mXn^kg4n=yvQ`RU#Fq( zKWfqVoEIlgRV8i0m9N4(-a1S4=At~5EaIt{FVR;CLFV^cDDhHg*Ph+6*V;ER7GBll zTIhIgpyL`V?@_jE5ipj#reBk{9Mw^JcS24pXR1_oUFnxr?I4i6yr#s$5$YS`cxwD{ zxVSP(;seTsEu^|WBHQZd!4~?o zC+vu@&Y#+?#wWH(i>@rX^?0*I0g;qKQr6t2${4qd9pt0D@6k;+1zLt>cA~Q_G-YKv z(N+R0V~up8>znaSHX4tJT|^(hl{`ZvbeM#WU;?8gZ;byp2XTYXa{=SHOPTNSsjT1_ z>Nt+qe0Oh4h4MX3;IIJ_QcrO6=MUJafPH^Wu+waiLu`Pfq?-OdDIBclE*oI Q$8eqHl*)p|W4MXrA1=D`G5`Po literal 0 HcmV?d00001 diff --git a/out/production/ProgA-Bot/src/ManualBot.class b/out/production/ProgA-Bot/src/ManualBot.class new file mode 100644 index 0000000000000000000000000000000000000000..e64c52bde5d6dd019b302fa688ae5d2ae2de3323 GIT binary patch literal 1195 zcmZuw>rN9v6#k}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LQ-Eb|X-6Sw|8n zfpDd|T&bxbwV9t!ot-|SV-#1|X0h!0mgBOqo@7I+Y}T}2R&BRvvof;h$}6@&OWtwq zN7eOZ+k0#+ml!ef<)T$uv^+=p^`PRfIfRVVI+Q9-6T$LU8B^9tM{Snn7&X^^?Jtx! ziE~Ph9CJ4*j6m$TPy)@SZxvrGSQ~XZQBmd0B4)Yj73~L(tSc;O$K(y5lJl<10hX*v z#g-*Vy{Waq+XV=|967DRhxd$;F?vhL8zCx{6$usclRX1xcKs5RU)@y>4{6o0lI&u)_`&`@tHD>e{C`!U?Z zdSkeS+r*oyof1(3@;28AJ`yOzjk)v=S{Fw5vw=yaL+O2wiO~*ad@4AygFaQ;#c+3U z7wLCM$UwX~9y<(eA*gJ>Rm6usKLY>jO0XNC3!Ui3G=Hf({LZ1bR$m_}J2A}oP%Ufj pNZGlDN)u2H5LGcF#BXF&sJ|e7GQWvfa#~s3 0 ? args[0] : "localhost"; + port = args.length > 1 ? Integer.parseInt(args[1]) : 63187; + } + + // Diese Methode stellt die Verbindung zum Server her und startet die + // Kommunikation mit dem Server. Die Methode wird von der main-Methode + // aufgerufen. + protected void run() { + try (Socket socket = new Socket()) { + socket.connect(new InetSocketAddress(host, port)); + OutputStream out = socket.getOutputStream(); + BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + View view = new View(); + while (true) { + view.read(in); + view.print(); + try { + char ch = nextMove(view); + out.write(ch); + } catch (Exception e) { + break; + } + } + socket.close(); + } catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + } + } + + // Diese Methode ermittelt den nächsten Zug des Bots. Sie wird von der + // run-Methode aufgerufen, nachdem der Server das Spielfeld gesendet hat. + // Subklassen müssen diese Methode implementieren. + abstract protected char nextMove(View view) throws Exception; + + // Diese Klasse repräsentiert das Spielfeld. Sie wird von der run-Methode + // verwendet, um das Spielfeld zu lesen und auszugeben. + // Subklassen können diese Klasse verwenden, um das Spielfeld zu analysieren. + public static class View { + protected String data; + protected int width; + + // Diese Methode liest das Spielfeld vom Server. + private void read(BufferedReader in) throws IOException { + StringBuilder sb = new StringBuilder(); + data = in.readLine(); + if (data == null) { + return; + } + sb.append(data); + width = data.length(); + for (int i = 1; i < width; ++i) { + sb.append(in.readLine()); + } + data = sb.toString(); + } + + // Diese Methode gibt das Spielfeld aus. + protected void print() { + if (data == null || width < 1) { + return; + } + for (int i = 0, len = data.length(); i < len; i += width) { + System.out.println(data.substring(i, i + width)); + } + } + } +} diff --git a/src/EscapeBot.java b/src/EscapeBot.java new file mode 100644 index 0000000..404441a --- /dev/null +++ b/src/EscapeBot.java @@ -0,0 +1,49 @@ +package src; + +public class EscapeBot extends Bot { + int stepCounter = 0; + int turnCount = 0; + int viewRange = 5; + int straightLength = 1; + + protected EscapeBot(String[] args) { + super(args); + } + + public static void main(String[] args) { + EscapeBot bot = new EscapeBot(args); + bot.run(); + } + + @Override + protected char nextMove(View view) throws Exception { + + if (!view.data.contains("o")) { + + if (turnCount == 2) { + turnCount = 0; + straightLength++; + } + if (stepCounter < straightLength * viewRange) { + stepCounter++; + return '^'; + } else { + stepCounter = 0; + turnCount++; + return '>'; + } + } else { + if (view.data.substring(0, 10).contains("o")) { + return '^'; + } else if (view.data.substring(10, 12).contains("o")) { + return '<'; + } else if (view.data.substring(13, 15).contains("o")) { + return '>'; + } else if (view.data.substring(15, 25).contains("o")) { + return 'v'; + } + } + + return 0; + } +} diff --git a/src/ManualBot.java b/src/ManualBot.java new file mode 100644 index 0000000..8482c58 --- /dev/null +++ b/src/ManualBot.java @@ -0,0 +1,34 @@ +package src; + +import java.util.Scanner; + +public class ManualBot extends Bot { + + Scanner scanner = new Scanner(System.in); + + protected ManualBot(String[] args) { + super(args); + } + + public static void main(String[] args) { + ManualBot bot = new ManualBot(args); + bot.run(); + } + + @Override + protected char nextMove(View view) throws Exception { + char ch = 0; + if (scanner.hasNextLine()) { + ch = scanner.nextLine().toCharArray()[0]; + } + + return switch (ch) { + case 'w' -> '^'; + case 's' -> 'v'; + case 'a' -> '<'; + case 'd' -> '>'; + case 'q' -> throw new Exception(); + default -> 'l'; + }; + } +} diff --git a/src/RumbleBot.java b/src/RumbleBot.java new file mode 100644 index 0000000..9a815d6 --- /dev/null +++ b/src/RumbleBot.java @@ -0,0 +1,92 @@ +package src; + +public class RumbleBot extends Bot{ + + + String[] playerChars = {"<",">","^","v"}; + int angle = 0; + int x = 0; + int y = 0; + boolean left = false; + boolean right = false; + boolean up = false; + boolean down = false; + int turnCounter = 0; + int waitTimer = 80; + + protected RumbleBot(String[] args) { + super(args); + } + + public static void main(String[] args) { + RumbleBot bot = new RumbleBot(args); + bot.run(); + } + + protected char nextMove(View view){ + + if(waitTimer > 0){ + waitTimer--; + return 0; + } + //back away if possible + if(playerAhead(view) && !view.data.substring(49,50).contains("X")){ + return 'v'; + } + //shoot target + if(playerAhead(view)){ + return 'f'; + } + + if(view.data.substring(39,40).contains("X") && view.data.substring(49,50).contains("X")){ + return '^'; + }else turnRight(); +// if (x <= 15 && !up){ +// x++; +// return '^'; +// }else if(angle != 180){ +// up = true; +// return turnRight(); +// }else if (x >= -15 && !down){ +// x--; +// return '^'; +// } else if (angle != 0) { +// down = true; +// return turnRight(); +// }else if (x < 0){ +// x++; +// return '^'; +// } else if (angle != 90 && x == 0) { +// return turnRight(); +// } else if (y <= 15 && !right) { +// y++; +// return '^'; +// } else if (angle != 270) { +// right = true; +// return turnRight(); +// } else if(y >= -15 && !left){ +// y--; +// return '^'; +// }else if(angle != 90){ +// turnRight(); +// }else if (y > 0){ +// y++; +// return '^'; +// } + return 0; + } + + private boolean playerAhead(View view){ + for (String s : playerChars){ + if(view.data.substring(4,5).contains(s) || view.data.substring(43,45).contains(s)){ + return true; + } + } + return false; + } + + private char turnRight(){ + angle = (angle + 90) % 360; + return '>'; + } +} diff --git a/src/SnakeBot.java b/src/SnakeBot.java new file mode 100644 index 0000000..87a043e --- /dev/null +++ b/src/SnakeBot.java @@ -0,0 +1,128 @@ +package src; + +public class SnakeBot extends Bot { + int straightLength = 1; //length of the straight the bot still needs to travel(in "FOV-Tiles") + int stepCounter = 0; //steps the bot has already taken on the straight + int turnCount = 2; //amount of times the bot needs to turn before increasing straightLength + final int VIEWRANGE = 5; //distance from one end to the bots FOV to the other (assumes square FOV) + int wagonCount = 0; //amount of wagons the rover is currently pulling + int angle = 0; //current angle of the rover, compared to its initial angle + boolean isOnPath = true; //if the bot is on its normal search path (not pathing to a mineral) + char[] clearSequence = {'<', '^', '<', '^', '^', '>', '^', '>', '^', '^', '^', '^', '>', '^', '>', '^', '<', '^', '^', '>', + '^', '^', '^', '<', '^', '<', '^', '^', '^', '^', '<', '^', '^', '>'}; + char[] cornerClearSequence = {'<', '^', '<', '^', '^', '>', '^', '>', '^', '^', '^', '^', '>', '^', '>', '^', '<', '^', + '<', '^', '>', '^', '^', '>', '^', '>', '^', '<', '^', '^', '^', '<', '^', '<', '^', '^', '>'}; + int clearSequenceCounter = 0; + boolean isClearing = false; + + protected SnakeBot(String[] args) { + super(args); + } + + public static void main(String[] args) { + SnakeBot bot = new SnakeBot(args); + bot.run(); + } + + @Override + protected char nextMove(View view) throws Exception { + +// if (!view.data.contains("@") && isOnPath) { +// +// if (turnCount <= 0) { +// turnCount = 2; +// straightLength++; +// } +// if (stepCounter < straightLength * viewRange) { +// stepCounter++; +// return '^'; +// } else { +// stepCounter = 0; +// turnCount--; +// angle = (angle + 90) % 360; +// return '>'; +// } +// } else if (!view.data.contains("@") && !isOnPath) { +// +// } else { +// isOnPath = false; +// //check for minerals to the left of the rover (high prio) +// for (int i = 0; i < view.data.length(); i += viewRange) { +// if (view.data.substring(i, i + 2).contains("@")) { +// angle = (angle + 270) % 360; +// return '<'; +// } +// } +// //check for minerals in front of the rover (mid prio) +// if (view.data.substring(0, view.data.length() / 2 - viewRange / 2).contains("@")) { +// return '^'; +// } +// //check for minerals to the right of the rover (low prio) +// for (int i = 3; i < view.data.length(); i += viewRange) { +// if (view.data.substring(i, i + 2).contains("@")) { +// angle = (angle + 90) % 360; +// return '>'; +// } +// } + +// if (view.data.substring(0, 10).contains("@")) { +// return '^'; +// } else if (view.data.substring(10, 12).contains("@")) { +// return '<'; +// } else if (view.data.substring(13, 15).contains("@")) { +// return '>'; +// } else if (view.data.substring(15, 25).contains("@")) { +// return 'v'; +// } +// } + + if (stepCounter % VIEWRANGE == 0 && !isClearing && view.data.contains("@")) { + isClearing = true; + } + if (isClearing) { + return clearFov(view); + } else { + if (turnCount <= 0) { + turnCount = 2; + straightLength++; + } + //if rover hasn't reached corner + if (stepCounter < straightLength * VIEWRANGE) { + stepCounter++; + return '^'; + } else { + stepCounter = 0; + turnCount--; + return '>'; + } + } + //return 0; + } + + protected char clearFov(View view) { + char move; + //check if rover is at a corner of its search path + if (stepCounter >= straightLength * VIEWRANGE) { + move = cornerClearSequence[clearSequenceCounter++]; + + //update rover state and reset sequence after its done + if (clearSequenceCounter >= cornerClearSequence.length) { + isClearing = false; + stepCounter = 2; + turnCount--; + clearSequenceCounter = 0; + } + } else { + move = clearSequence[clearSequenceCounter++]; + + //update rover state and reset sequence after its done + if (clearSequenceCounter >= clearSequence.length) { + isClearing = false; + stepCounter += 2; + clearSequenceCounter = 0; + } + } + + return move; + } +} diff --git a/src/test.java b/src/test.java new file mode 100644 index 0000000..8f9ca41 --- /dev/null +++ b/src/test.java @@ -0,0 +1,31 @@ +package src; + +public class test extends Bot{ + + String[] playerChars = {"<",">","^","v"}; + + protected test(String[] args) { + super(args); + } + + public static void main(String[] args) { + test bot = new test(args); + bot.run(); + } + + protected char nextMove(View view){ + if(playerAhead(view)){ + return 'f'; + } + return '>'; + } + + private boolean playerAhead(View view){ + for (String s : playerChars){ + if(view.data.substring(4,5).contains(s) || view.data.substring(13,14).contains(s)){ + return true; + } + } + return false; + } +}