Compare commits
9
Commits
49b307b680
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
828a767003 | ||
|
|
7698381620 | ||
|
|
f67726a7cf | ||
|
|
af06d99bbe | ||
|
|
4332f7d10a | ||
|
|
9de3f327e5 | ||
|
|
00796bed61 | ||
|
|
b9fb2db2a2 | ||
|
|
7fef449863 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,36 +0,0 @@
|
|||||||
package Prog3.src.DiningPhilosophers;
|
|
||||||
|
|
||||||
public class Fork {
|
|
||||||
|
|
||||||
private boolean inUse = false;
|
|
||||||
private final int id;
|
|
||||||
|
|
||||||
public Fork(int id){
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId(){
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean take(){
|
|
||||||
synchronized (this){
|
|
||||||
if (inUse){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
inUse = true;
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}catch (InterruptedException e){
|
|
||||||
System.out.println("Gabel mit ID: " + id + " hat nicht funktioniert");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(){
|
|
||||||
synchronized(this){
|
|
||||||
inUse = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package Prog3.src.DiningPhilosophers;
|
|
||||||
|
|
||||||
public class Philosopher implements Runnable{
|
|
||||||
protected int id;
|
|
||||||
protected final Fork left;
|
|
||||||
protected final Fork right;
|
|
||||||
|
|
||||||
public Philosopher(int id, Fork left, Fork right) {
|
|
||||||
this.id = id;
|
|
||||||
this.left = left;
|
|
||||||
this.right = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(){
|
|
||||||
while(true) {
|
|
||||||
allocateForks();
|
|
||||||
System.out.println("Philosopher " + id + " is eating");
|
|
||||||
try{
|
|
||||||
Thread.sleep(2000);
|
|
||||||
}catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
left.put();
|
|
||||||
right.put();
|
|
||||||
System.out.println("Philosopher " + id + " finished eating");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void allocateForks() {
|
|
||||||
Fork firstFork, secondFork;
|
|
||||||
|
|
||||||
if (left.getId() < right.getId()){
|
|
||||||
firstFork = left;
|
|
||||||
secondFork = right;
|
|
||||||
} else {
|
|
||||||
firstFork = right;
|
|
||||||
secondFork = left;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Philosopher " + id + " is trying to take Fork " + firstFork.getId());
|
|
||||||
while (!firstFork.take())
|
|
||||||
Thread.yield();
|
|
||||||
System.out.println("Philosopher " + id + " got Fork " + firstFork.getId());
|
|
||||||
System.out.println("Philosopher " + id + " is trying to take Fork " + secondFork.getId());
|
|
||||||
while (!secondFork.take())
|
|
||||||
Thread.yield();
|
|
||||||
System.out.println("Philosopher " + id + " got Fork " + secondFork.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package Prog3.src.DiningPhilosophers;
|
|
||||||
|
|
||||||
public class Table {
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
Fork[] forks = { new Fork(0), new Fork(1), new Fork(2),
|
|
||||||
new Fork(3), new Fork(4)};
|
|
||||||
|
|
||||||
Philosopher[] philosophers = {
|
|
||||||
new Philosopher(0, forks[0], forks[1]),
|
|
||||||
new Philosopher(1, forks[1], forks[2]),
|
|
||||||
new Philosopher(2, forks[2], forks[3]),
|
|
||||||
new Philosopher(3, forks[3], forks[4]),
|
|
||||||
new Philosopher(4, forks[4], forks[0])
|
|
||||||
};
|
|
||||||
|
|
||||||
for (Philosopher philosopher : philosophers) {
|
|
||||||
|
|
||||||
Thread t = new Thread(philosopher);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package DistributedSorter;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class SorterClient implements Runnable{
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SorterClient client = new SorterClient();
|
|
||||||
client.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendLine(Socket socket, String line) throws IOException {
|
|
||||||
OutputStream out = socket.getOutputStream();
|
|
||||||
PrintWriter writer = new PrintWriter(out);
|
|
||||||
writer.println(line);
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String receiveLine(Socket socket) throws IOException {
|
|
||||||
InputStream in = socket.getInputStream();
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
|
||||||
return reader.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine();
|
|
||||||
if(line.isEmpty())
|
|
||||||
break;
|
|
||||||
line = sort(line);
|
|
||||||
System.out.println(line);
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String sort(String line) {
|
|
||||||
try (Socket socket = new Socket("localhost", 12345)) {
|
|
||||||
|
|
||||||
sendLine(socket, line);
|
|
||||||
return receiveLine(socket);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "Error connecting to the server.";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
package DistributedSorter;
|
|
||||||
|
|
||||||
import jdk.jshell.spi.ExecutionControl;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class SorterServer implements Runnable {
|
|
||||||
|
|
||||||
Socket client;
|
|
||||||
public SorterServer(Socket client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
final int port = 12345;
|
|
||||||
try (ServerSocket socket = new ServerSocket(port)) {
|
|
||||||
|
|
||||||
while (true){
|
|
||||||
Socket client = socket.accept();
|
|
||||||
Thread thread = new Thread(new SorterServer(client));
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.err.println("Error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendLine(Socket socket, String line) throws IOException {
|
|
||||||
OutputStream out = socket.getOutputStream();
|
|
||||||
PrintWriter writer = new PrintWriter(out);
|
|
||||||
writer.println(line);
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String receiveLine(Socket socket) throws IOException {
|
|
||||||
InputStream in = socket.getInputStream();
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
|
||||||
return reader.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private String sort(String line){
|
|
||||||
char[] chars = line.toCharArray();
|
|
||||||
Arrays.sort(chars);
|
|
||||||
return new String(chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try{
|
|
||||||
String line = receiveLine(client);
|
|
||||||
String answer = sort(line);
|
|
||||||
sendLine(client, answer);
|
|
||||||
System.out.println(line + "-->"+ answer);
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("Fehler");
|
|
||||||
}
|
|
||||||
finally{
|
|
||||||
try{client.close();} catch(Exception e)
|
|
||||||
{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package Praktikum01;
|
|
||||||
|
|
||||||
|
|
||||||
public class Zahlenfilter {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int upper_limit = 200;
|
|
||||||
if (args.length > 0){
|
|
||||||
upper_limit = Integer.parseInt(args[0]);
|
|
||||||
}else{
|
|
||||||
System.out.println("Keine Zahl eingegeben. Es wird mit 200 weitergearbeitet.");
|
|
||||||
}
|
|
||||||
int count = 1;
|
|
||||||
Zahlenfilter z = new Zahlenfilter(upper_limit);
|
|
||||||
z.run(count);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
private Zahlenfilter(int limit){
|
|
||||||
|
|
||||||
this.limit = limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void run(int c){
|
|
||||||
for(int i = 0; i < this.limit; i++){
|
|
||||||
int preC = c-1;
|
|
||||||
int ergebnis = c + preC;
|
|
||||||
int ergebnis2 = preC + c;
|
|
||||||
|
|
||||||
if (c % 5 == 0){
|
|
||||||
System.out.println(c + " ist durch 5 teilbar");
|
|
||||||
c++;
|
|
||||||
}else if(c % 10 == 9){
|
|
||||||
System.out.println(c + " endet auf 9");
|
|
||||||
c++;
|
|
||||||
}else if(ergebnis % 3 == 0 && ergebnis2 % 3 == 0){
|
|
||||||
System.out.println(c + " und " + preC + " addiert ergeben " + ergebnis + " und " + ergebnis2 + " ist durch 3 teilbar." );
|
|
||||||
c++;
|
|
||||||
}else{
|
|
||||||
System.out.println(c);
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
package Praktikum03;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class TriangleChecker {
|
|
||||||
|
|
||||||
public enum TriangleType {
|
|
||||||
NONE,
|
|
||||||
NORMAL,
|
|
||||||
ISOSCELES, // Gleichschenklig
|
|
||||||
EQUILATERAL // Gleichseitig
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Scanner s = new Scanner(System.in);
|
|
||||||
System.out.println("Geben Sie die Seitenlängen ein.");
|
|
||||||
float a = enterFloat(s, "a: ");
|
|
||||||
float b = enterFloat(s, "b: ");
|
|
||||||
float c = enterFloat(s, "c: ");
|
|
||||||
s.close();
|
|
||||||
printAnalysis(a, b, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Eingabe einer Seitenlänge
|
|
||||||
private static float enterFloat(Scanner s, String prompt) {
|
|
||||||
System.out.print(prompt);
|
|
||||||
return s.nextFloat();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ausgabe der ermittelten Dreiecksart
|
|
||||||
private static void printAnalysis(float a, float b, float c) {
|
|
||||||
TriangleType type = checkTriangle(a, b, c);
|
|
||||||
switch (type) {
|
|
||||||
case NONE -> System.out.println("Kein Dreieck");
|
|
||||||
case NORMAL -> System.out.println("Dreieck");
|
|
||||||
case ISOSCELES -> System.out.println("Gleichschenkliges Dreieck");
|
|
||||||
case EQUILATERAL -> System.out.println("Gleichseitiges Dreieck");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Analyse der Dreiecksart
|
|
||||||
public static TriangleType checkTriangle(float a, float b, float c) {
|
|
||||||
|
|
||||||
|
|
||||||
if(a == b && b == c)
|
|
||||||
return TriangleType.EQUILATERAL;
|
|
||||||
if(a == b || b == c || a == c)
|
|
||||||
return TriangleType.ISOSCELES;
|
|
||||||
if(a + b < c || a + c < b || b + c < a)
|
|
||||||
return TriangleType.NONE;
|
|
||||||
if(a < 0 || b < 0 || c < 0)
|
|
||||||
return TriangleType.NONE;
|
|
||||||
|
|
||||||
return TriangleType.NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package Praktikum03;
|
|
||||||
|
|
||||||
|
|
||||||
public class Zahlenfilter {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int upper_limit = 200;
|
|
||||||
if (args.length > 0)
|
|
||||||
upper_limit = Integer.parseInt(args[0]);
|
|
||||||
Zahlenfilter z = new Zahlenfilter(upper_limit);
|
|
||||||
z.printNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int boundary;
|
|
||||||
|
|
||||||
private Zahlenfilter(int limit){
|
|
||||||
boundary = limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printNumber(){
|
|
||||||
for(int i = 1; i <=boundary; i++){
|
|
||||||
if(filter(i))
|
|
||||||
System.out.println(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean filter(int i){
|
|
||||||
return !(checkDivisibleBy5(i) || checkEndsWith9(i) || checkSumDivisibleBy3(i, i-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkDivisibleBy5(int i) {
|
|
||||||
return(i % 5 == 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkEndsWith9(int i){
|
|
||||||
return(i % 10 == 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkSumDivisibleBy3(int i, int j){
|
|
||||||
return((i+j) % 3 == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public class ErrorWriter implements IHelloWorldWriter{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeHelloWorld(){
|
|
||||||
System.err.println("Hello World");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public class Executor{
|
|
||||||
public static void printHelloWorld(IHelloWorldWriter writer1, IHelloWorldWriter writer2, boolean second){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public interface IHelloWorldWriter {
|
|
||||||
|
|
||||||
void writeHelloWorld();
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package Praktikum03.helloworld;
|
|
||||||
|
|
||||||
public class OutWriter implements IHelloWorldWriter{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeHelloWorld(){
|
|
||||||
System.out.println("Hello World");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package Prog3.src.Praktikum05;
|
package Praktikum05;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|||||||
@@ -1,11 +1,39 @@
|
|||||||
package Prog3.src.Praktikum05;
|
package Praktikum05;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class EscapeBot extends Bot{
|
public class EscapeBot extends Bot{
|
||||||
protected EscapeBot(String args[]){
|
protected EscapeBot(String args[]){
|
||||||
super(args);
|
super(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected char
|
|
||||||
|
private Random schritte = new Random();
|
||||||
|
|
||||||
|
private int s = 5;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected char nextMove(View view) throws Exception {
|
||||||
|
boolean exit = false;
|
||||||
|
while(!exit){
|
||||||
|
/*if(view.data.contains("o")){
|
||||||
|
|
||||||
|
}*/
|
||||||
|
if(s == 5){
|
||||||
|
for(int i = 1; i == s; i++ ){
|
||||||
|
return '^';
|
||||||
|
}
|
||||||
|
boolean turn = schritte.nextBoolean();
|
||||||
|
if(turn == true){
|
||||||
|
return '<';
|
||||||
|
}else{
|
||||||
|
return '>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception("Quit");
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String args[]){
|
public static void main(String args[]){
|
||||||
Bot ebot = new EscapeBot(args);
|
Bot ebot = new EscapeBot(args);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package Prog3.src.Praktikum05;
|
package Praktikum05;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ public class ManualBot extends Bot {
|
|||||||
case "d":
|
case "d":
|
||||||
return '>';
|
return '>';
|
||||||
case "q":
|
case "q":
|
||||||
exit = true;
|
command = null;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Kommando nicht verfügbar bitte einen anderes Kommando eingeben");
|
System.out.println("Kommando nicht verfügbar bitte einen anderes Kommando eingeben");
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package Praktikum05;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class RumbleBot extends Bot {
|
||||||
|
protected RumbleBot(String[] args) {
|
||||||
|
super(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Scanner input = new Scanner(System.in);
|
||||||
|
private int counter = 0;
|
||||||
|
private Random leftOrRight = new Random();
|
||||||
|
@Override
|
||||||
|
protected char nextMove(View view) throws Exception {
|
||||||
|
char roverKennung = view.data.charAt(40);
|
||||||
|
boolean exit = false;
|
||||||
|
while (!exit) {
|
||||||
|
|
||||||
|
if(counter <= 8){
|
||||||
|
counter++;
|
||||||
|
return '^';
|
||||||
|
}else if(counter > 8){
|
||||||
|
counter = 0;
|
||||||
|
if(leftOrRight.nextBoolean()){
|
||||||
|
return '>';
|
||||||
|
}else{
|
||||||
|
return '<';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
throw new Exception("Beendet");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String args[]){
|
||||||
|
Bot bot = new RumbleBot(args);
|
||||||
|
bot.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package Praktikum05;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class SnakeBot extends Bot {
|
||||||
|
|
||||||
|
|
||||||
|
protected SnakeBot(String[] args) {
|
||||||
|
super(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int counter = 0;
|
||||||
|
private Random leftOrRight = new Random();
|
||||||
|
@Override
|
||||||
|
protected char nextMove(View view) throws Exception {
|
||||||
|
boolean exit = false;
|
||||||
|
while (!exit) {
|
||||||
|
int rockPosition = findNextRock(view);
|
||||||
|
if (rockPosition != -1) {
|
||||||
|
System.out.println(counter + "| RockPosition: " + rockPosition);
|
||||||
|
return testForWagon(view, rockPosition);
|
||||||
|
} else {
|
||||||
|
++counter;
|
||||||
|
if (counter < 8)
|
||||||
|
return testForWagon(view, rockPosition);
|
||||||
|
else {
|
||||||
|
if (view.data.charAt(10) == '*' || view.data.charAt(11) == '*') {
|
||||||
|
counter = 0;
|
||||||
|
return '>';
|
||||||
|
} else if (view.data.charAt(13) == '*' || view.data.charAt(14) == '*') {
|
||||||
|
counter = 0;
|
||||||
|
return '<';
|
||||||
|
}else{
|
||||||
|
if(leftOrRight.nextBoolean() == true) {
|
||||||
|
counter = 0;
|
||||||
|
return '<';
|
||||||
|
}else {
|
||||||
|
counter = 0;
|
||||||
|
return '>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exception("Quit");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private char determineNextStep(int rockPosition,View view) {
|
||||||
|
if (rockPosition < 10)
|
||||||
|
return '^';
|
||||||
|
else if(rockPosition == 13 || rockPosition == 14 || rockPosition == 18 || rockPosition == 19 || rockPosition == 23 || rockPosition == 24 && !(view.data.charAt(13) != '*' && view.data.charAt(14) != '*'))
|
||||||
|
return '>';
|
||||||
|
else if((rockPosition == 10 || rockPosition == 11 || rockPosition == 15 || rockPosition == 16 || rockPosition == 20 || rockPosition == 21) && !(view.data.charAt(10) != '*' && view.data.charAt(11) != '*'))
|
||||||
|
return '<';
|
||||||
|
else return '^';
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findNextRock(View view) {
|
||||||
|
return view.data.indexOf('@');
|
||||||
|
}
|
||||||
|
|
||||||
|
private char testForWagon(View view, int rP){
|
||||||
|
char move = ' ';
|
||||||
|
if (view.data.charAt(7) == '*'){
|
||||||
|
if(view.data.charAt(11) == '*' || view.data.charAt(13) == '*'){
|
||||||
|
if(view.data.charAt(11) == '*' || view.data.charAt(10) == '*'){
|
||||||
|
return '>';
|
||||||
|
}else if(view.data.charAt(13) == '*' || view.data.charAt(14) == '*'){
|
||||||
|
return '<';
|
||||||
|
}
|
||||||
|
}else if(view.data.charAt(11) != '*' && view.data.charAt(13) != '*'){
|
||||||
|
if(view.data.charAt(8) == '*' || view.data.charAt(9) == '*'){
|
||||||
|
if(view.data.charAt(10) == '*'){
|
||||||
|
return '>';
|
||||||
|
}else if(view.data.charAt(14) == '*'){
|
||||||
|
return '<';
|
||||||
|
}
|
||||||
|
}else if(view.data.charAt(5) == '+' || view.data.charAt(6) == '*'){
|
||||||
|
if(view.data.charAt(10) == '*'){
|
||||||
|
return '>';
|
||||||
|
}else if(view.data.charAt(14) == '*'){
|
||||||
|
return '<';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
move = determineNextStep(rP, view);
|
||||||
|
}
|
||||||
|
System.out.println(move);
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]){
|
||||||
|
Bot sbot = new SnakeBot(args);
|
||||||
|
sbot.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package Praktikum03;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class TriangleCheckerTest {
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkNormalTriangle() {
|
|
||||||
|
|
||||||
float a = 3.0f;
|
|
||||||
float b = 4.0f;
|
|
||||||
float c = 2.0f;
|
|
||||||
|
|
||||||
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,b,c);
|
|
||||||
|
|
||||||
assertEquals(TriangleChecker.TriangleType.NORMAL, type);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkEquilateralTriangle() {
|
|
||||||
|
|
||||||
float a = 3.0f;
|
|
||||||
|
|
||||||
|
|
||||||
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,a,a);
|
|
||||||
|
|
||||||
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, type);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkIsoscelesTriangle() {
|
|
||||||
|
|
||||||
float a = 3.0f;
|
|
||||||
float b = 4.0f;
|
|
||||||
|
|
||||||
|
|
||||||
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,b,a);
|
|
||||||
|
|
||||||
assertEquals(TriangleChecker.TriangleType.ISOSCELES, type);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkNumbersNegative(){
|
|
||||||
float a = 5.0f;
|
|
||||||
float b = -20.0f;
|
|
||||||
float c = 4.0f;
|
|
||||||
|
|
||||||
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,b,c);
|
|
||||||
|
|
||||||
assertEquals(TriangleChecker.TriangleType.NONE, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkIfSideToLong(){
|
|
||||||
float a = 3.0f;
|
|
||||||
float b = 20.0f;
|
|
||||||
float c = 5.0f;
|
|
||||||
|
|
||||||
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,b,c);
|
|
||||||
|
|
||||||
assertEquals(TriangleChecker.TriangleType.NONE, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package Praktikum03;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class ZahlenfilterTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void filter() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkDivisibleBy5() {
|
|
||||||
int i = 15;
|
|
||||||
|
|
||||||
boolean result = Zahlenfilter.checkDivisibleBy5(i);
|
|
||||||
|
|
||||||
assertTrue(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkNotDivisibleBy5() {
|
|
||||||
int i = 12;
|
|
||||||
|
|
||||||
boolean result = Zahlenfilter.checkDivisibleBy5(i);
|
|
||||||
|
|
||||||
assertFalse(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkEndsWith9() {
|
|
||||||
int i = 29;
|
|
||||||
|
|
||||||
boolean result = Zahlenfilter.checkEndsWith9(i);
|
|
||||||
|
|
||||||
assertTrue(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkEndsNotWith9() {
|
|
||||||
int i = 28;
|
|
||||||
|
|
||||||
boolean result = Zahlenfilter.checkEndsWith9(i);
|
|
||||||
|
|
||||||
assertFalse(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkSumDivisibleBy3() {
|
|
||||||
int i = 5;
|
|
||||||
|
|
||||||
boolean result = Zahlenfilter.checkSumDivisibleBy3(i, i-1);
|
|
||||||
|
|
||||||
assertTrue(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void checkSumNotDivisibleBy3() {
|
|
||||||
int i = 3;
|
|
||||||
|
|
||||||
boolean result = Zahlenfilter.checkSumDivisibleBy3(i, i-1);
|
|
||||||
|
|
||||||
assertFalse(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user