... | @@ -126,7 +126,64 @@ We quickly realized that the shovel in front of the car was too poorly attached |
... | @@ -126,7 +126,64 @@ We quickly realized that the shovel in front of the car was too poorly attached |
|
|
|
|
|
### Added randomness
|
|
### Added randomness
|
|
|
|
|
|
[INDSÆT BESKRIVELSE]
|
|
Before adding randomness to the search for the opponent(s), the robot sumo wrestler would drive straight forward until the edge was detected, the backup, turn in a deterministic manner, and then drive forward again. In order to increase the chance of finding the opponent(s), randomness was added to this search. The algorith used for the random search can was as follows:
|
|
|
|
|
|
|
|
```java
|
|
|
|
@Override
|
|
|
|
public void action() {
|
|
|
|
super.action();
|
|
|
|
|
|
|
|
boolean doRotation = rnd.nextBoolean();
|
|
|
|
|
|
|
|
if(doRotation)
|
|
|
|
{
|
|
|
|
boolean turnRight = rnd.nextBoolean();
|
|
|
|
int angle = rnd.nextInt(MAXANGLE);
|
|
|
|
|
|
|
|
if(turnRight)
|
|
|
|
{
|
|
|
|
//turn right
|
|
|
|
Motor.A.rotate(-angle, true);
|
|
|
|
Motor.C.rotate(angle, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//turn left
|
|
|
|
Motor.A.rotate(angle, true);
|
|
|
|
Motor.C.rotate(-angle, true);
|
|
|
|
}
|
|
|
|
waitForACMovement();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Motor.A.forward();
|
|
|
|
Motor.C.forward();
|
|
|
|
wait(rnd.nextInt(MAXFORWARDTIME));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
We first determine whether to rotate, or drive forward. I case of the rotation, a direction(left or right) and an angle is determined. On the other hand, when driving forward a duration to drive for is determined.
|
|
|
|
|
|
|
|
#### About the LejOS implementation of `util.Random`
|
|
|
|
|
|
|
|
The algorithm for used generating pseudorandom numbers in the LejOS implementation of `util.Random` generates only odd numbers. This is not a problem for our usage of the function `Random.nextInt()`. But it *is* a problem when using `Random.nextBoolean()` because the default implementation relies on an 50/50 chance of even and odd numbers:
|
|
|
|
|
|
|
|
```java
|
|
|
|
return this.next(1) != 0;
|
|
|
|
```
|
|
|
|
|
|
|
|
We fixed this by subclassing `util.Random` and overriding `Random.nextBoolean()`:
|
|
|
|
|
|
|
|
```java
|
|
|
|
@Override
|
|
|
|
public boolean nextBoolean()
|
|
|
|
{
|
|
|
|
//since nextInt(int n) always returns an uneven number, nextBoolean will currently always return true. This fixes that.
|
|
|
|
int unevenNumber = nextInt(101);
|
|
|
|
return unevenNumber > 50;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
### Added weight
|
|
### Added weight
|
|
|
|
|
... | | ... | |