Preventing tower-building

This commit is contained in:
Malte Tammena 2017-10-27 10:35:48 +02:00
parent 74320a091a
commit f8067ecc18
2 changed files with 34 additions and 34 deletions

View file

@ -64,7 +64,6 @@ public class MalteAI implements Player{
for (double d: weights) { for (double d: weights) {
max = max > d ? max: d; max = max > d ? max: d;
} }
System.out.println(Arrays.toString(weights));
for (int i = 0; i < weights.length; i++) { for (int i = 0; i < weights.length; i++) {
if (Math.abs(max - weights[i]) < 0.000001) { if (Math.abs(max - weights[i]) < 0.000001) {
return i; return i;
@ -77,8 +76,6 @@ public class MalteAI implements Player{
double W_ILLEGAL = Double.MIN_VALUE; double W_ILLEGAL = Double.MIN_VALUE;
double W_DONT = 0.01; double W_DONT = 0.01;
double weight = 1.0; double weight = 1.0;
// Prever a place in the center;
weight *= 1.0 - Math.abs(3.0 - column) / (3.0 * 100.0);
// Relative positions like (-1, -1), (0, -1), etc. // Relative positions like (-1, -1), (0, -1), etc.
Position[] relAround = Position.getRelCirclePositions(); Position[] relAround = Position.getRelCirclePositions();
// The position we're looking at // The position we're looking at
@ -88,6 +85,9 @@ public class MalteAI implements Player{
weight *= W_ILLEGAL; weight *= W_ILLEGAL;
return weight; return weight;
} }
// Prever a place in the center;
weight *= 1.0 - Math.abs(3.0 - thisPos.getPosX()) / (3.0 * 100.0);
weight *= 1.0 - Math.abs(5.0 - thisPos.getPosY()) / (5.0 * 100.0);
// Setup Sequences // Setup Sequences
Sequence[] sequences = new Sequence[8]; Sequence[] sequences = new Sequence[8];
Sequence[] sequencesAbove = new Sequence[8]; Sequence[] sequencesAbove = new Sequence[8];
@ -111,32 +111,32 @@ public class MalteAI implements Player{
for (int i = 0; i < sequences.length / 2; i++) { for (int i = 0; i < sequences.length / 2; i++) {
Sequence x = sequences[i]; Sequence x = sequences[i];
Sequence y = sequences[i + 4]; Sequence y = sequences[i + 4];
weight *= getBaseWeightForSequences(x, y); weight *= getBaseWeightForSequences(x, y, false);
Sequence xA = sequencesAbove[i]; Sequence xA = sequencesAbove[i];
Sequence yA = sequencesAbove[i + 4]; Sequence yA = sequencesAbove[i + 4];
// weight *= getBaseWeightForSequences(xA, yA); weight *= Math.sqrt(getBaseWeightForSequences(xA, yA, true));
if ((xA.matches("EEE") ||
yA.matches("EEE")) ||
((xA.matches("E") &&
yA.matches("EE")) ||
(xA.matches("EE") &&
yA.matches("E")))) {
// TODO: Do this right!
weight /= 2<<6;
}
} }
return weight; return weight;
} }
private double getBaseWeightForSequences(Sequence x, Sequence y) { /**
double W_PRIORITY_1 = 2 << 8; *
double W_PRIORITY_2 = 2 << 6; * @param altWeight Weights enemy advances negativ.
double W_PRIORITY_3 = 2 << 4; */
double W_PRIORITY_4 = 2 << 2; private double getBaseWeightForSequences(Sequence x, Sequence y, boolean altWeight) {
double W_PRIORITY_5 = 2 << 0; double W_PRIORITY_1 = 1 << 8;
double W_PRIORITY_2 = 1 << 6;
double W_PRIORITY_3 = 1 << 4;
double W_PRIORITY_4 = 1 << 2;
double W_PRIORITY_5 = 1 << 0;
double W_PRIORITY_6 = 1.0; double W_PRIORITY_6 = 1.0;
double W_START = 1.0; double W_START = 1.0;
double weight = W_START; double weight = W_START;
if (altWeight) {
W_PRIORITY_2 = 1 / 4;
W_PRIORITY_4 = 1 / 3;
W_PRIORITY_6 = 1 / 2;
}
if (x.matches("MMM") || if (x.matches("MMM") ||
y.matches("MMM")) { y.matches("MMM")) {
weight *= W_PRIORITY_1; weight *= W_PRIORITY_1;

View file

@ -1,14 +1,14 @@
1 XMMM // Vierter in der Reihe + 1 XMMM // Vierter in der Reihe
1 MXMM + 1 MXMM
2 XEEE // Vierter beim Gegner - 2 XEEE // Vierter beim Gegner
2 EXEE - 2 EXEE
3 _XMM_ // Sicherer Sieg nächste Runde + 3 _XMM_ // Sicherer Sieg nächste Runde
3 _MXM_ + 3 _MXM_
4 _XEE_ // Sicherer Sieg des Gegners nächste Runde - 4 _XEE_ // Sicherer Sieg des Gegners nächste Runde
4 _EXE_ - 4 _EXE_
5 XMM_ // Möglicher Sieg nächste Runde + 5 XMM_ // Möglicher Sieg nächste Runde
5 _XMM + 5 _XMM
5 MXM_ + 5 MXM_
6 XEE_ // Möglicher Sieg des Gegners in der nächsten Runde - 6 XEE_ // Möglicher Sieg des Gegners in der nächsten Runde
6 _XEE - 6 _XEE
6 EXE_ - 6 EXE_