From 94f5f2bceb5faa268908d835b2d8c5964b1a3616 Mon Sep 17 00:00:00 2001 From: Your Average Code <138674451+UrAvgCode@users.noreply.github.com> Date: Wed, 10 Jan 2024 19:00:38 +0100 Subject: [PATCH] SankeBot --- .idea/misc.xml | 2 +- src/AutomaticBot.java | 17 -------------- src/EscapeBot.java | 2 +- src/SnakeBot.java | 53 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 19 deletions(-) delete mode 100644 src/AutomaticBot.java create mode 100644 src/SnakeBot.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 8780e86..9c42d73 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/AutomaticBot.java b/src/AutomaticBot.java deleted file mode 100644 index 7028647..0000000 --- a/src/AutomaticBot.java +++ /dev/null @@ -1,17 +0,0 @@ -public class AutomaticBot extends Bot { - - public static void main(String[] args) { - Bot bot = new AutomaticBot(args); - bot.run(); - } - - protected AutomaticBot(String[] args) { - super(args); - } - - @Override - protected char nextMove(View view) throws Exception { - System.out.println("fagh"); - return '^'; - } -} diff --git a/src/EscapeBot.java b/src/EscapeBot.java index 67be7ae..69c1955 100644 --- a/src/EscapeBot.java +++ b/src/EscapeBot.java @@ -3,7 +3,7 @@ public class EscapeBot extends Bot { boolean foundShip = false; boolean offByOne = true; int currentStepCount = 0; - int steps = 10; + int steps = 0; public static void main(String[] args) { Bot bot = new EscapeBot(args); diff --git a/src/SnakeBot.java b/src/SnakeBot.java new file mode 100644 index 0000000..ede1736 --- /dev/null +++ b/src/SnakeBot.java @@ -0,0 +1,53 @@ +public class SnakeBot extends Bot { + + boolean foundShip = false; + boolean offByOne = true; + int currentStepCount = 0; + int steps = 0; + + public static void main(String[] args) { + Bot bot = new SnakeBot(args); + bot.run(); + } + + protected SnakeBot(String[] args) { + super(args); + } + + @Override + protected char nextMove(View view) throws Exception { + String data = view.data; + System.out.println(); + + if (data.contains("@")) { + int index = data.indexOf('@'); + if (index < view.width * 2 && !(index > view.width * 3)) { + return safeMove(data); + } else if (index % 5 < 2) { + return '<'; + } else if (index % 5 > 2) { + return '>'; + } + return ' '; + } else if (steps == 0) { + currentStepCount += 1; + if (offByOne) { + currentStepCount += 1; + } + offByOne = !offByOne; + steps = currentStepCount; + return '>'; + } else { + steps -= 1; + return safeMove(data); + } + } + + protected char safeMove(String data) { + if (data.charAt(7) == '*') { + return '>'; + } else { + return '^'; + } + } +}