small changes
This commit is contained in:
@@ -1,35 +0,0 @@
|
|||||||
import worms.facade.Facade;
|
|
||||||
import worms.facade.IFacade;
|
|
||||||
import worms.model.Team;
|
|
||||||
import worms.model.World;
|
|
||||||
import worms.model.Worm;
|
|
||||||
import worms.programs.BinaryExpression;
|
|
||||||
import worms.programs.Expression;
|
|
||||||
import worms.programs.UnaryExpression;
|
|
||||||
import worms.util.Coordinate;
|
|
||||||
|
|
||||||
import java.io.Console;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import java.util.function.BinaryOperator;
|
|
||||||
import java.util.function.DoubleBinaryOperator;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
private static final double EPS = 1e-4;
|
|
||||||
private static boolean[][] passableMap = new boolean[][] { //
|
|
||||||
{ false, false, false, false }, //
|
|
||||||
{ true, true, true, true }, //
|
|
||||||
{ true, true, true, true }, //
|
|
||||||
{ false, false, false, false } };
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
|
|
||||||
int x =ThreadLocalRandom.current().nextInt(0, 15) / 2;
|
|
||||||
x += (x % 2 == 0 ? 1:0);
|
|
||||||
System.out.println(x);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -481,7 +481,7 @@ public class World {
|
|||||||
obj.setWorld(null);
|
obj.setWorld(null);
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
else if(Worm.class.isInstance(obj) && (!obj.isValidLocation(obj.getLocation()) || !isAdjacent(obj.getLocation(), obj.getRadius()) )) {
|
else if(obj instanceof Worm && (!obj.isValidLocation(obj.getLocation()) || !isAdjacent(obj.getLocation(), obj.getRadius()) )) {
|
||||||
obj.setWorld(null);
|
obj.setWorld(null);
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
/**
|
/**
|
||||||
* A class with the specifications of the worm
|
* A class with the specifications of the worm
|
||||||
*
|
*
|
||||||
* @authors Arthur Bols and Leen Dereu (1ste bachelor informatica)
|
* @Authors Arthur Bols and Leen Dereu (1ste bachelor informatica)
|
||||||
*
|
*
|
||||||
* URL: https://github.com/KUL-ogp/ogp1718-project-bols-dereu
|
* URL: https://github.com/KUL-ogp/ogp1718-project-bols-dereu
|
||||||
*
|
*
|
||||||
@@ -663,7 +663,7 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
double maxLocDirection = minDirection;
|
double maxLocDirection = minDirection;
|
||||||
Coordinate maxLoc = location;
|
Coordinate maxLoc = location;
|
||||||
|
|
||||||
for (; minDirection <= maxDirection; minDirection += 0.0175) {
|
for (; minDirection <= maxDirection && minDirection <= 2 * PI; minDirection += 0.0175) {
|
||||||
if (minDirection < 0) minDirection = 0.0;
|
if (minDirection < 0) minDirection = 0.0;
|
||||||
Coordinate tempLoc = getFurthestLocationInDirection(minDirection, this.radius);
|
Coordinate tempLoc = getFurthestLocationInDirection(minDirection, this.radius);
|
||||||
if (!this.world.isAdjacent(tempLoc, this.radius)) tempLoc = location;
|
if (!this.world.isAdjacent(tempLoc, this.radius)) tempLoc = location;
|
||||||
@@ -672,11 +672,16 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
maxLocDirection = minDirection;
|
maxLocDirection = minDirection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maxDirection <= 2 * PI) {
|
||||||
|
|
||||||
Coordinate tempLoc = getFurthestLocationInDirection(maxDirection, this.radius);
|
Coordinate tempLoc = getFurthestLocationInDirection(maxDirection, this.radius);
|
||||||
if (this.world.isAdjacent(tempLoc, this.radius) && getDistance(location, tempLoc) / Math.abs(direction - minDirection) > getDistance(location, maxLoc) / Math.abs(direction - maxLocDirection)) {
|
if (this.world.isAdjacent(tempLoc, this.radius) && getDistance(location, tempLoc) /
|
||||||
|
Math.abs(direction - minDirection) > getDistance(location, maxLoc) / Math.abs(direction - maxLocDirection)) {
|
||||||
maxLoc = tempLoc;
|
maxLoc = tempLoc;
|
||||||
maxLocDirection = maxDirection;
|
maxLocDirection = maxDirection;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (maxLoc.getX() == location.getX() && maxLoc.getY() == location.getY()) return direction;
|
if (maxLoc.getX() == location.getX() && maxLoc.getY() == location.getY()) return direction;
|
||||||
return maxLocDirection;
|
return maxLocDirection;
|
||||||
|
@@ -63,7 +63,7 @@ public class Coordinate extends Tuple<Double, Double> {
|
|||||||
* |result == new double[]{getX(), getY()}
|
* |result == new double[]{getX(), getY()}
|
||||||
*/
|
*/
|
||||||
public double[] toArray() {
|
public double[] toArray() {
|
||||||
return new double[]{getX(), getY()};
|
return new double[]{this.item1, this.item2};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,94 +1,94 @@
|
|||||||
//package worms.model;
|
package worms.model;
|
||||||
//
|
|
||||||
//import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
//import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
//import org.junit.jupiter.api.RepeatedTest;
|
import org.junit.jupiter.api.RepeatedTest;
|
||||||
//import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
//import worms.util.Coordinate;
|
import static java.lang.Math.*;
|
||||||
//
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
//import java.util.Random;
|
import worms.util.Coordinate;
|
||||||
//
|
|
||||||
//class WormTest {
|
import java.util.Random;
|
||||||
//
|
|
||||||
// private static Worm worm;
|
class WormTest {
|
||||||
// private static Random r = new Random();
|
|
||||||
//
|
|
||||||
// @BeforeAll
|
private static boolean[][] map = new boolean[][] { { false, false, false, false, false, false, false, false, false, false },
|
||||||
// static void setUp() {
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
// worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
// }
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
//
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
// @RepeatedTest(5000)
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
// void move() {
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
// worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
// int steps = r.nextInt(5101) - 100;
|
{ true, true, true, true, true, true, true, true, true, false },
|
||||||
// double maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
|
{ true, true, true, true, true, true, true, true, true, false }, };
|
||||||
// double minAngle = worm.getOrientation();
|
private static World world;
|
||||||
// double combAngle = maxAngle + minAngle;
|
|
||||||
// double angle = r.nextDouble() * combAngle - minAngle;
|
private static Worm worm;
|
||||||
// worm.turn(angle);
|
private static Random r = new Random();
|
||||||
// long cost = (long) Math.ceil(Math.abs(Math.cos(worm.getOrientation())) + Math.abs(4 * Math.sin(worm.getOrientation()))) * steps;
|
|
||||||
// if (steps < 0 || cost > worm.getActionPoints()) {
|
@BeforeAll
|
||||||
// assertThrows(IllegalArgumentException.class, () -> worm.move(steps));
|
static void setUp() {
|
||||||
// }
|
worm = new Worm(world, new double[]{1, 1}, 0, 0.5, "Test", null);
|
||||||
// else {
|
world = new World(10.0, 10.0, map);
|
||||||
//
|
}
|
||||||
// double newLocX = worm.getLocation().item1 + steps * worm.getRadius() * Math.cos(worm.getOrientation());
|
|
||||||
// double newLocY = worm.getLocation().item2 + steps * worm.getRadius() * Math.sin(worm.getOrientation());
|
@RepeatedTest(500)
|
||||||
// worm.move(steps);
|
void move() {
|
||||||
// assertEquals(Coordinate.create(newLocX, newLocY), worm.getLocation());
|
worm = new Worm(world, new double[] { 8.375, 3.0 }, 0, 0.6, "Test", null);
|
||||||
// }
|
|
||||||
// }
|
double maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
|
||||||
//
|
double minAngle = worm.getOrientation();
|
||||||
// @RepeatedTest(5000)
|
double combAngle = maxAngle + minAngle;
|
||||||
// void turn() {
|
double angle = r.nextDouble() * combAngle - minAngle;
|
||||||
// double angle = r.nextDouble() * 4 * Math.PI - 2 * Math.PI;
|
worm.turn(angle);
|
||||||
// double oldAngle = worm.getOrientation();
|
double direction = worm.getFurthestLocationDirection();
|
||||||
//
|
|
||||||
// if (!Worm.isValidOrientation(oldAngle + angle) || worm.getActionPoints() - (long) Math.ceil(Math.toDegrees(angle) / 6) < 0) {
|
long cost = (long) Math.ceil(abs(direction * cos(worm.getOrientation())) + abs(4 * direction * sin(worm.getOrientation())));
|
||||||
// assertThrows(AssertionError.class, () -> worm.turn(angle));
|
if (direction < 0 || direction > 2 * Math.PI || Double.isNaN(direction) || worm.getRadius() < 0 ||
|
||||||
// worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
|
Double.isNaN(worm.getRadius()) || Double.isInfinite(worm.getRadius()) || cost > worm.getActionPoints()) {
|
||||||
// }
|
try {
|
||||||
// else {
|
Coordinate newLoc = worm.getFurthestLocationInDirection(direction, worm.getRadius());
|
||||||
// worm.turn(angle);
|
worm.move();
|
||||||
// assertEquals(oldAngle + angle, worm.getOrientation());
|
assertEquals(newLoc, worm.getLocation());
|
||||||
// }
|
} catch (IllegalArgumentException e) {
|
||||||
//
|
return;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
} else {
|
||||||
// void turnInvalidValue() {
|
Coordinate newLoc = worm.getFurthestLocationInDirection(direction, worm.getRadius());
|
||||||
// assertThrows(AssertionError.class, () -> worm.turn(Double.NaN));
|
worm.move();
|
||||||
// }
|
assertEquals(newLoc, worm.getLocation());
|
||||||
//
|
}
|
||||||
// @RepeatedTest(5000)
|
}
|
||||||
// void jump() {
|
|
||||||
//
|
@RepeatedTest(5000)
|
||||||
// worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
|
void turn() {
|
||||||
// double maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
|
double angle = r.nextDouble() * 4 * Math.PI - 2 * Math.PI;
|
||||||
// double minAngle = worm.getOrientation();
|
double oldAngle = worm.getOrientation();
|
||||||
// double combAngle = maxAngle + minAngle;
|
|
||||||
// double angle = r.nextDouble() * combAngle - minAngle;
|
if (!Worm.isValidOrientation(oldAngle + angle) || worm.getActionPoints() - (long) Math.ceil(Math.toDegrees(angle) / 6) < 0) {
|
||||||
// worm.turn(angle);
|
assertThrows(AssertionError.class, () -> worm.turn(angle));
|
||||||
// int steps = r.nextInt(100);
|
worm = new Worm(world, new double[] { 8.375, 3.0 }, 0, 0.6, "Test", null);
|
||||||
// worm.move(steps);
|
}
|
||||||
//
|
else {
|
||||||
// if (worm.getOrientation() >= Math.PI || worm.getActionPoints() == 0){
|
worm.turn(angle);
|
||||||
// assertThrows(IllegalStateException.class, () -> worm.jump());
|
assertEquals(oldAngle + angle, worm.getOrientation());
|
||||||
// }
|
}
|
||||||
// else {
|
|
||||||
// double orient = worm.getOrientation();
|
}
|
||||||
// double force = 5 * worm.getActionPoints() + worm.getMass() * Worm.G;
|
|
||||||
// double v = force / worm.getMass() * Worm.FORCE_TIME;
|
@Test
|
||||||
// double newLocX = worm.getLocation().item1 + Math.pow(v, 2) * Math.sin(2 * orient) / Worm.G;
|
void turnInvalidValue() {
|
||||||
// worm.jump();
|
assertThrows(AssertionError.class, () -> worm.turn(Double.NaN));
|
||||||
// assertEquals(Coordinate.create(newLocX, worm.getLocation().getY()), worm.getLocation());
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// @Test
|
@Test
|
||||||
// void doubleJump() {
|
void doubleJump() {
|
||||||
// worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
|
worm = new Worm(world, new double[] { 8.375, 3.0 }, Math.PI / 2.0, 0.6, "Test", null);
|
||||||
// worm.jump();
|
worm.jump(0.01);
|
||||||
// assertThrows(IllegalStateException.class, () -> worm.jump());
|
assertThrows(IllegalStateException.class, () -> worm.jump(0.01));
|
||||||
// }
|
}
|
||||||
//}
|
}
|
Reference in New Issue
Block a user