Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Koordinatensystem {
- public char[][] koordinaten;
- private Faltung f;
- private int currentX;
- private int currentY;
- private int connectionX;
- private int connectionY;
- private int currentDirection;
- public Koordinatensystem(Faltung f) {
- this.f = f;
- int dimension = f.getSaeuren().size()*2 + 1;
- koordinaten = new char[dimension][dimension];
- init();
- if(!fill())
- System.out.println("OVERLAP DETECTED ! ");
- else {
- print();
- System.out.println("Energy is: " + computeEnergy());
- }
- }
- private int computeEnergy() {
- int energy = 0;
- char c1;
- char c2;
- for(int i = 0; i < koordinaten.length; i++) {
- for(int j = 2; j < koordinaten[i].length; j+=2) {
- boolean validChar = koordinaten[i][j-2] != 'x' && koordinaten[i][j] != 'x';
- if(validChar) {
- c1 = koordinaten[i][j-2];
- c2 = koordinaten[i][j-2];
- if(c1 == c2 && koordinaten[i][j-1] == 'x') {
- System.out.println("Match in row " + i + " Column " + j);
- energy++;
- }
- }
- }
- }
- return energy;
- }
- private void init() {
- for(int i = 0; i < koordinaten.length; i++) {
- for(int j = 0; j < koordinaten[i].length; j++) {
- koordinaten[i][j] = 'x';
- }
- }
- }
- public void print() {
- for(int i = 0; i < koordinaten.length; i++) {
- for(int j = 0; j < koordinaten[i].length; j++) {
- System.out.print(koordinaten[i][j] + " ");
- }
- System.out.println("\n");
- }
- System.out.println("----- ENDE ----");
- }
- private boolean fill() {
- currentX = f.getSaeuren().size();
- currentY = currentX;
- currentDirection = Direction.RIGHT;
- boolean first = true;
- for(Aminosaeure s : f.getSaeuren()) {
- print();
- if(first) {
- koordinaten[currentY][currentX] = (char) (s.getColor() + 48);
- currentDirection = Direction.RIGHT;
- first = false;
- continue;
- }
- switch(currentDirection) {
- case Direction.DOWN:
- if(s.getDirection() == Direction.RIGHT) {
- currentX = currentX - 1;
- currentDirection = Direction.LEFT;
- }
- else if(s.getDirection() == Direction.LEFT) {
- currentX = currentX + 1;
- currentDirection = Direction.RIGHT;
- }
- else if(s.getDirection() == Direction.STRAIGHT) {
- currentY = currentY + 1;
- }
- break;
- case Direction.LEFT:
- if(s.getDirection() == Direction.RIGHT) {
- currentY = currentY - 1;
- currentDirection = Direction.UP;
- }
- else if(s.getDirection() == Direction.LEFT) {
- currentY = currentY + 1;
- currentDirection = Direction.DOWN;
- }
- else if(s.getDirection() == Direction.STRAIGHT) {
- currentX = currentX - 1;
- }
- break;
- case Direction.RIGHT:
- if(s.getDirection() == Direction.RIGHT) {
- currentY = currentY + 1;
- currentDirection = Direction.DOWN;
- }
- else if(s.getDirection() == Direction.LEFT) {
- currentY = currentY - 1;
- currentDirection = Direction.UP;
- }
- else if(s.getDirection() == Direction.STRAIGHT)
- currentX = currentX + 1;
- break;
- case Direction.UP:
- if(s.getDirection() == Direction.RIGHT) {
- currentX = currentX + 1;
- currentDirection = Direction.LEFT;
- }
- else if(s.getDirection() == Direction.LEFT) {
- currentX = currentX - 1;
- currentDirection = Direction.RIGHT;
- }
- else if(s.getDirection() == Direction.STRAIGHT) {
- currentY = currentY - 1;
- }
- break;
- }
- if(koordinaten[currentY][currentX] != 'x')
- return false;
- koordinaten[currentY][currentX] = (char) (s.getColor() + 48);
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment