Commit 7f41f2e7 authored by Malte Heithoff's avatar Malte Heithoff
Browse files

Bug with test

parent 7bfc64ed
Pipeline #117631 failed with stages
in 9 minutes and 44 seconds
package de.rwth.pacman.heithoff2.coneSearch.coinSearch;
component CoinWeights {
ports
out Z buiscuitWeight,
out Z coinWeight;
implementation Math {
buiscuitWeight = 50;
coinWeight = 200;
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.coinSearch;
component SearchCoinsBottom {
ports
in Z^{22,19} map,
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Z buiscuitWeight,
in Z coinWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:21
Z indexY = round(currentY + 1) + i + 1;
if indexY < 22
for j = (-i):i
Z indexX = round(currentX + 1) + j + 1;
if (indexX > 0) && (indexX < 19)
Z nextTile = map(indexY, indexX);
if (nextTile == 1) || (nextTile == 4)
Z multBy = 1;
if nextTile == 1
multBy = buiscuitWeight;
elseif nextTile == 4
multBy = coinWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multBy/(dist*dist));
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.coinSearch;
component SearchCoinsLeft {
ports
in Z^{22,19} map,
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Z buiscuitWeight,
in Z coinWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:18
Z indexX = round(currentX + 1) - i + 1;
if indexX > 0
for j = (-i):i
Z indexY = round(currentY + 1) + j + 1;
if (indexY > 0) && (indexY < 22)
Z nextTile = map(indexY, indexX);
if (nextTile == 1) || (nextTile == 4)
Z multBy = 1;
if nextTile == 1
multBy = buiscuitWeight;
elseif nextTile == 4
multBy = coinWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multBy/(dist*dist));
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.coinSearch;
component SearchCoinsRight {
ports
in Z^{22,19} map,
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Z buiscuitWeight,
in Z coinWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:18
Z indexX = round(currentX + 1) + i + 1;
if indexX < 19
for j = (-i):i
Z indexY = round(currentY + 1) + j + 1;
if (indexY > 0) && (indexY < 22)
Z nextTile = map(indexY, indexX);
if (nextTile == 1) || (nextTile == 4)
Z multBy = 1;
if nextTile == 1
multBy = buiscuitWeight;
elseif nextTile == 4
multBy = coinWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multBy/(dist*dist));
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.coinSearch;
component SearchCoinsTop {
ports
in Z^{22,19} map,
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Z buiscuitWeight,
in Z coinWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:21
Z indexY = round(currentY + 1) - i + 1;
if indexY > 0
for j = (-i):i
Z indexX = round(currentX + 1) + j + 1;
if (indexX > 0) && (indexX < 19)
Z nextTile = map(indexY, indexX);
if (nextTile == 1) || (nextTile == 4)
Z multBy = 1;
if nextTile == 1
multBy = buiscuitWeight;
elseif nextTile == 4
multBy = coinWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multBy/(dist*dist));
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.enemySearch;
component EnemyWeights {
ports
out Z normal,
out Z towardsPacMan,
out Z eatable;
implementation Math {
normal = -4;
towardsPacMan = -10;
eatable = 5000;
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.enemySearch;
component SearchEnemiesBottom {
ports
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Q(-1m: 19m) ghostX[4],
in Q(0m: 22m) ghostY[4],
in Z ghostDirection[4],
in B ghostEatable[4],
in Z ghostNormalWeight,
in Z ghostFacingPacManWight,
in Z ghostEatableWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:8
Z indexY = round(currentY + 1) + i;
if indexY < 22
for j = (-i):i
Z indexX = round(currentX + 1) + j;
if (indexX > 0) && (indexX < 19)
for i = 1:4
Z xG = round(ghostX(i) + 1);
Z yG = round(ghostY(i) + 1);
if (abs (xG - indexX) < 0.1) && (abs(yG - indexY) < 0.1)
Z multiplyer = ghostNormalWeight;
if ghostDirection(i) == 0 // Facing towards PacMan
multiplyer = ghostFacingPacManWight;
end
if ghostEatable(i)
multiplyer = ghostEatableWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multiplyer/dist);
end
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.enemySearch;
component SearchEnemiesLeft {
ports
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Q(-1m: 19m) ghostX[4],
in Q(0m: 22m) ghostY[4],
in Z ghostDirection[4],
in B ghostEatable[4],
in Z ghostNormalWeight,
in Z ghostFacingPacManWight,
in Z ghostEatableWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:8
Z indexX = round(currentX + 1) - i;
if indexX > 0
for j = (-i):i
Z indexY = round(currentY + 1) + j;
if (indexY > 0) && (indexY < 22)
for i = 1:4
Z xG = round(ghostX(i) + 1);
Z yG = round(ghostY(i) + 1);
if (abs (xG - indexX) < 0.1) && (abs(yG - indexY) < 0.1)
Z multiplyer = ghostNormalWeight;
if ghostDirection(i) == 3 // Facing towards PacMan
multiplyer = ghostFacingPacManWight;
end
if ghostEatable(i)
multiplyer = ghostEatableWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multiplyer/dist);
end
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.enemySearch;
component SearchEnemiesRight {
ports
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Q(-1m: 19m) ghostX[4],
in Q(0m: 22m) ghostY[4],
in Z ghostDirection[4],
in B ghostEatable[4],
in Z ghostNormalWeight,
in Z ghostFacingPacManWight,
in Z ghostEatableWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:8
Z indexX = round(currentX + 1) + i;
if indexX < 19
for j = (-i):i
Z indexY = round(currentY + 1) + j;
if (indexY > 0) && (indexY < 22)
for i = 1:4
Z xG = round(ghostX(i) + 1);
Z yG = round(ghostY(i) + 1);
if (abs (xG - indexX) < 0.1) && (abs(yG - indexY) < 0.1)
Z multiplyer = ghostNormalWeight;
if ghostDirection(i) == 2 // Facing towards PacMan
multiplyer = ghostFacingPacManWight;
end
if ghostEatable(i)
multiplyer = ghostEatableWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multiplyer/dist);
end
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.coneSearch.enemySearch;
component SearchEnemiesTop {
ports
in Q(-1m: 19m) ghostX[4],
in Q(0m: 22m) ghostY[4],
in Q(-1m: 19m) currentX,
in Q(0m: 22m) currentY,
in Z ghostDirection[4],
in B ghostEatable[4],
in Z ghostNormalWeight,
in Z ghostFacingPacManWight,
in Z ghostEatableWeight,
out Z value;
implementation Math {
value = 0;
for i = 1:8
Z indexY = round(currentY + 1) - i;
if indexY > 0
for j = (-i):i
Z indexX = round(currentX + 1) + j;
if (indexX > 0) && (indexX < 19)
for i = 1:4
Z xG = round(ghostX(i) + 1);
Z yG = round(ghostY(i) + 1);
if (abs (xG - indexX) < 0.1) && (abs(yG - indexY) < 0.1)
Z multiplyer = ghostNormalWeight;
if ghostDirection(i) == 1 // Facing towards PacMan
multiplyer = ghostFacingPacManWight;
end
if ghostEatable(i)
multiplyer = ghostEatableWeight;
end
Q dist = sqrt(i*i + j*j);
value = value + (multiplyer/dist);
end
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.decision;
// compares all values of the safe directions and takes the maximum
// if the desired direction is blocked (not possible) it tries a direction orthogonal to it
// if those directions are not safe or blocked too, it tries to go the opposite direction
// left is prefered over right and up is prefered over down
component CompareValues {
ports
in B topSafe,
in B bottomSafe,
in B leftSafe,
in B rightSafe,
in Z topValue,
in Z bottomValue,
in Z leftValue,
in Z rightValue,
in B topPossible,
in B bottomPossible,
in B leftPossible,
in B rightPossible,
out Z newPacManDirection;
implementation Math {
// search maximum
Z maxValue = -1;
Z newDirection = 0;
if topSafe && (topValue > maxValue)
maxValue = topValue;
end
if bottomSafe && (bottomValue > maxValue)
maxValue = bottomValue;
newDirection = 1;
end
if leftSafe && (leftValue > maxValue)
maxValue = leftValue;
newDirection = 2;
end
if rightSafe && (rightValue > maxValue)
newDirection = 3;
end
// check whether the desired direction is blocked
if ((newDirection == 0) && (topPossible == 0)) || ((newDirection == 1) && (bottomPossible == 0))
// pick a direction orthogonal to up/down
if leftPossible && leftSafe && ((leftValue >= rightValue) || (rightPossible == 0) || (rightSafe == 0))
newDirection = 2;
elseif rightPossible && rightSafe
newDirection = 3;
// pick the direction opposite to the original direction
elseif topPossible && topSafe && ((topValue >= bottomValue) || (bottomPossible == 0) || (bottomSafe == 0))
newDirection = 0;
else
newDirection = 1;
end
elseif ((newDirection == 2) && (leftPossible == 0)) || ((newDirection == 3) && (rightPossible == 0))
if topPossible && topSafe && ((topValue >= bottomValue) || (bottomPossible == 0) || (bottomSafe == 0))
newDirection = 0;
elseif bottomPossible && bottomSafe
newDirection = 1;
elseif leftPossible && leftSafe && ((leftValue >= rightValue) || (rightPossible == 0) || (rightSafe == 0))
newDirection = 2;
else
newDirection = 3;
end
end
newPacManDirection = newDirection;
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.decision;
// Main strategy
component Decision {
ports
in B topSafe,
in B bottomSafe,
in B leftSafe,
in B rightSafe,
in Z topValue,
in Z bottomValue,
in Z leftValue,
in Z rightValue,
in Q(-1m: 19m) pacManX,
in Q(0m: 22m) pacManY,
in Z^{22,19} map,
out Z newPacManDirection;
// instance CompareValues compareValues; // gives back the desired direction
// instance PossibleWays possibleWays; // gives back whether certain directions are blocked
// instance VerifyDirection verifyDirection; // prevent stuttering
// instance NextIntersection intersection; // gives back whether an intersection (more than 3 non-blocked paths) is reached
//
// connect pacManX -> possibleWays.pacManX, intersection.pacManX;
// connect pacManY -> possibleWays.pacManY, intersection.pacManY;
// connect map -> possibleWays.map, intersection.map;
//
// connect topSafe -> compareValues.topSafe, verifyDirection.topSafe;
// connect bottomSafe -> compareValues.bottomSafe, verifyDirection.bottomSafe;
// connect leftSafe -> compareValues.leftSafe, verifyDirection.leftSafe;
// connect rightSafe -> compareValues.rightSafe, verifyDirection.rightSafe;
// connect topValue -> compareValues.topValue;
// connect bottomValue -> compareValues.bottomValue;
// connect leftValue -> compareValues.leftValue;
// connect rightValue -> compareValues.rightValue;
// connect possibleWays.topPossible -> compareValues.topPossible, verifyDirection.topPossible;
// connect possibleWays.bottomPossible -> compareValues.bottomPossible, verifyDirection.bottomPossible;
// connect possibleWays.leftPossible -> compareValues.leftPossible, verifyDirection.leftPossible;
// connect possibleWays.rightPossible -> compareValues.rightPossible, verifyDirection.rightPossible;
//
// connect intersection.interSectionReached -> verifyDirection.interSection;
// connect compareValues.newPacManDirection -> verifyDirection.tryDirection;
// connect verifyDirection.newPacManDirection -> newPacManDirection;
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.decision;
// check whether an intersection (3 or more non-blocked paths) is reached
component NextIntersection {
ports
in Q(-1m: 19m) pacManX,
in Q(0m: 22m) pacManY,
in Z^{22,19} map,
out B interSectionReached;
implementation Math {
Z pacX = round(pacManX + 1);
Z pacY = round(pacManY + 1);
interSectionReached = 0;
if (abs(pacManX - pacX) < 0.01) && (abs(pacManY - pacY) < 0.01)
Z^{1,4} xOffSet = [0,0,-1,1];
Z^{1,4} yOffSet = [1,-1,0,0];
Z newPathsFound = 0;
for i = 1:4
Z indexY = 1;
Z indexX = i;
Z xOff = xOffSet(indexY, indexX);
Z yOff = yOffSet(indexY, indexX);
Q xT = pacX + xOff + 1;
Q yT = pacY + yOff + 1;
Z nextTile = map(yT, xT);
if (nextTile == 0) || (nextTile == 3)
newPathsFound = newPathsFound;
else
newPathsFound = newPathsFound + 1;
if newPathsFound > 2
interSectionReached = 1;
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.decision;
// check which directions are not blocked
component PossibleWays {
ports
in Q(-1m: 19m) pacManX,
in Q(0m: 22m) pacManY,
in Z^{22,19} map,
out B topPossible,
out B bottomPossible,
out B leftPossible,
out B rightPossible;
implementation Math {
Q^{1,4} xOffSet = [0,0