Added pacman model to test resources

parent 1526e3f5
Pipeline #95862 passed with stages
in 12 minutes and 12 seconds
package de.rwth.pacman;
import de.rwth.pacman.basicLibrary.Fallback;
// UP = 0
// DOWN = 1
// LEFT = 2
// RIGHT = 3
component PacManControllerSimple {
ports
in Q(0m: 18m) ghostX[4],
in Q(0m: 21m) ghostY[4],
in Z(0 : 1 : 3) ghostDirection[4],
in B ghostEatable[4],
in B ghostEaten[4],
in Q(0m: 18m) pacManX,
in Q(0m: 21m) pacManY,
in B pacManEaten,
in Z(1:oo) pacManLives,
in Z(0:oo) pacManScore,
in Z^{22,19} map,
out Z(0 : 1 : 3) newPacManDirection;
instance Fallback fallback;
connect fallback.out1 -> newPacManDirection;
}
\ No newline at end of file
package de.rwth.pacman;
import de.rwth.pacman.heithoff2.Controller;
import de.rwth.pacman.structs.Ghost;
// UP = 0
// DOWN = 1
// LEFT = 2
// RIGHT = 3
// Pacman.WALL = 0;
// Pacman.BISCUIT = 1;
// Pacman.EMPTY = 2;
// Pacman.BLOCK = 3;
// Pacman.PILL = 4;
component PacManWrapper {
ports
in Q(-1m: 19m) ghostX[4], // x-position of all ghosts, can be -1 and 19 when exiting and reentering the map
in Q(0m: 21m) ghostY[4], // y-position of all ghosts
in Z(0 : 1 : 3) ghostDirection[4], // the directions of all ghosts encoded in the pattern above
in B ghostEatable[4], // ghosts are eatable when pacman collects a coin
in B ghostEaten[4], // ghosts enter a non-eatable state after this one
in Q(-1m: 19m) pacManX, // x-position of pacman, can be -1 and 19 when exiting and reenting the map
in Q(0m: 21m) pacManY, // y-position of pacman
in B pacManEaten,
in Z(0:oo) pacManLives,
in Z(0:oo) pacManScore,
in Z^{22,19} map, // the map encoded in the pattern above. x raises to the right, y raises to the bottom
out Z(0 : 1 : 3) newPacManDirection;
//Replace this with your own custom controller
instance Controller controller;
connect ghostX[:] -> controller.ghostX[:];
connect ghostY[:] -> controller.ghostY[:];
connect ghostDirection[:] -> controller.ghostDirection[:];
connect ghostEatable[:] -> controller.ghostEatable[:];
connect ghostEaten[:] -> controller.ghostEaten[:];
connect pacManX -> controller.pacManX;
connect pacManY -> controller.pacManY;
connect pacManEaten -> controller.pacManEaten;
connect pacManLives -> controller.pacManLives;
connect pacManScore -> controller.pacManScore;
connect map -> controller.map;
connect controller.newPacManDirection -> newPacManDirection;
}
\ No newline at end of file
package de.rwth.pacman.basicLibrary;
// UP = 0
// DOWN = 1
// LEFT = 2
// RIGHT = 3
component Fallback{
port
out Z out1;
implementation Math{
out1=3;
}
}
package de.rwth.pacman.heithoff2.BFS;
import de.rwth.pacman.heithoff2.BFS.single.*;
// Pacman.WALL = 0;
// Pacman.BISCUIT = 1;
// Pacman.EMPTY = 2;
// Pacman.BLOCK = 3;
// Pacman.PILL = 4;
// check whether the current tile is safe and then calculate the next tile position
component BFSSingle {
ports
in Q(0m: 20m) ghostX[4],
in Q(1m: 23m) ghostY[4],
in Z(0 : 1 : 3) ghostDirection[4],
in B ghostEatable[4],
in Z^{22,19} map,
in Q(0m: 20m) currentX,
in Q(1m: 23m) currentY,
in Q(0m: 20m) oldX,
in Q(1m: 23m) oldY,
in B oldSafe,
in B oldSafeFound,
in Z oldDirection,
out Q(0m: 20m) newX,
out Q(1m: 23m) newY,
out B safeFound,
out B safe,
out Z newDirection;
// sadly this doesnt work, due to some bugs in emam2wasm. Concept is still correct
// should get fixed, soon
// instance ControlFlow control;
// instance ReenterMap reenterMap;
// instance SearchFinished searchFinished;
// instance SafePosition safePosition;
// instance CalcNewPosition calcNewPosition;
// connect currentX -> reenterMap.currentX;
// connect currentY -> reenterMap.currentY;
// connect oldX -> reenterMap.oldX;
// connect oldY -> reenterMap.oldY;
// connect reenterMap.newCurrentX -> searchFinished.currentX, safePosition.currentX, calcNewPosition.currentX, control.currentX;
// connect reenterMap.newCurrentY -> searchFinished.currentY, safePosition.currentY, calcNewPosition.currentY, control.currentY;
// connect map -> searchFinished.map, calcNewPosition.map;
// connect oldSafe -> searchFinished.oldSafe;
// connect oldSafeFound -> searchFinished.oldSafeFound;
// connect ghostX[:] -> safePosition.ghostX[:];
// connect ghostY[:] -> safePosition.ghostY[:];
// connect ghostDirection[:] -> safePosition.ghostDirection[:];
// connect ghostEatable[:] -> safePosition.ghostEatable[:];
// connect oldDirection -> safePosition.oldDirection, control.oldDirection;
// connect reenterMap.newOldX -> calcNewPosition.oldX;
// connect reenterMap.newOldY -> calcNewPosition.oldY;
// connect searchFinished.finished -> calcNewPosition.searchFinished;
// connect safePosition.safe -> calcNewPosition.positionIsSafe;
// connect searchFinished.finished -> control.searchFinished;
// connect searchFinished.safe -> control.safeFromSearchFinished;
// connect searchFinished.safeFound -> control.safeFoundFromSearchFinished;
// connect safePosition.safe -> control.positionIsSafe;
// connect calcNewPosition.safeFound -> control.safeFoundFromNewPosition;
// connect calcNewPosition.newX -> control.newXFromNewPosition;
// connect calcNewPosition.newY -> control.newYFromNewPosition;
// connect calcNewPosition.newDirection -> control.newDirectionFromNewPosition;
// connect control.newX -> newX;
// connect control.newY -> newY;
// connect control.safeFound -> safeFound;
// connect control.safe -> safe;
// connect control.newDirection -> newDirection;
implementation Math {
// reenter the map
if currentX < 2
currentX = 18;
oldX = 19;
elseif currentX > 18
currentX = 2;
oldX = 1;
end
newDirection = oldDirection;
newX = currentX;
newY = currentY;
Z currentTile = map(currentY, currentX);
if (currentTile == 0) || (currentTile == 3) // begin within a wall-tile, nothing to check
safeFound = 1;
safe = 1;
elseif (oldSafeFound == 1) || (oldSafe == 0) // already at an intersection or a ghost was found
safeFound = oldSafeFound;
safe = oldSafe;
else
safe = 1;
safeFound = 0;
// check whether the current tile is safe
for i = 1:4
Z xG = round(ghostX(i));
Z yG = round(ghostY(i));
if (abs(xG - currentX) < 1) && (abs(yG - currentY) < 1) && (ghostEatable(i) == 0) && (ghostDirection(i) != oldDirection)
safe = 0;
end
end
if (safe == 1)
// check for intersection or calculate the next tile
Z^{1,4} xOffSet = [0,0,-1,1];
Z^{1,4} yOffSet = [-1,1,0,0];
Z newPathsFound = 0;
for i = 0:3
Z indexY = 0;
Z indexX = i;
Z xOff = xOffSet(indexY, indexX);
Z yOff = yOffSet(indexY, indexX);
Q xT = currentX + xOff;
Q yT = currentY + yOff;
if (abs(xT - (oldX)) >= 1) || (abs(yT - (oldY)) >= 1)
Z nextTile = map(yT, xT);
if (nextTile != 0) && (nextTile != 3) // a non-blocking tile was found
newPathsFound = newPathsFound + 1;
newX = xT;
newY = yT;
newDirection = i;
if newPathsFound > 1
safeFound = 1;
newX = currentX;
newY = currentY;
end
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.BFS;
import de.rwth.pacman.heithoff2.BFS.start.StartValues;
// search along the current path whether there are ghosts facing to pacman
// bfssingle1 is given the start values which then calculates the next coordinates
// for bffsingle2
// the path ends when an intersection is reached
// then check again whether the surrounding tiles are safe
component BFSearch{
ports
in Q(0m: 20m) ghostX[4],
in Q(1m: 23m) ghostY[4],
in Q(0m: 20m) pacManX,
in Q(1m: 23m) pacManY,
in Z(0 : 1 : 3) ghostDirection[4],
in B ghostEatable[4],
in Z^{22,19} map,
in Q(0m: 20m) startX,
in Q(1m: 23m) startY,
in Z startDirection,
// out B safeFound,
// out Q newX,
// out Q newY,
// out B oldSafe,
out B safe;
instance StartValues start;
instance BFSSingle bfssingle1;
instance BFSSingle bfssingle2;
instance BFSSingle bfssingle3;
instance BFSSingle bfssingle4;
instance BFSSingle bfssingle5;
instance BFSSingle bfssingle6;
instance BFSSingle bfssingle7;
instance BFSSingle bfssingle8;
instance BFSSingle bfssingle9;
instance BFSSingle bfssingl9;
instance EndSafe endSafe;
connect pacManX -> bfssingle1.oldX;
connect pacManY -> bfssingle1.oldY;
connect startX -> bfssingle1.currentX, bfssingle2.oldX;
connect startY -> bfssingle1.currentY, bfssingle2.oldY;
connect start.startSafe -> bfssingle1.oldSafe;
connect start.startSafeFound -> bfssingle1.oldSafeFound;
connect startDirection -> bfssingle1.oldDirection;
// connect bfssingl9.newX -> newX;
// connect bfssingl9.newY -> newY;
// connect bfssingl9.safe -> oldSafe;
// connect bfssingl9.safeFound -> safeFound;
connect bfssingle1.newX -> bfssingle2.currentX, bfssingle3.oldX;
connect bfssingle1.newY -> bfssingle2.currentY, bfssingle3.oldY;
connect bfssingle1.safe -> bfssingle2.oldSafe;
connect bfssingle1.safeFound -> bfssingle2.oldSafeFound;
connect bfssingle1.newDirection -> bfssingle2.oldDirection;
connect bfssingle2.newX -> bfssingle3.currentX, bfssingle4.oldX;
connect bfssingle2.newY -> bfssingle3.currentY, bfssingle4.oldY;
connect bfssingle2.safe -> bfssingle3.oldSafe;
connect bfssingle2.safeFound -> bfssingle3.oldSafeFound;
connect bfssingle2.newDirection -> bfssingle3.oldDirection;
connect bfssingle3.newX -> bfssingle4.currentX, bfssingle5.oldX;
connect bfssingle3.newY -> bfssingle4.currentY, bfssingle5.oldY;
connect bfssingle3.safe -> bfssingle4.oldSafe;
connect bfssingle3.safeFound -> bfssingle4.oldSafeFound;
connect bfssingle3.newDirection -> bfssingle4.oldDirection;
connect bfssingle4.newX -> bfssingle5.currentX, bfssingle6.oldX;
connect bfssingle4.newY -> bfssingle5.currentY, bfssingle6.oldY;
connect bfssingle4.safe -> bfssingle5.oldSafe;
connect bfssingle4.safeFound -> bfssingle5.oldSafeFound;
connect bfssingle4.newDirection -> bfssingle5.oldDirection;
connect bfssingle5.newX -> bfssingle6.currentX, bfssingle7.oldX;
connect bfssingle5.newY -> bfssingle6.currentY, bfssingle7.oldY;
connect bfssingle5.safe -> bfssingle6.oldSafe;
connect bfssingle5.safeFound -> bfssingle6.oldSafeFound;
connect bfssingle5.newDirection -> bfssingle6.oldDirection;
connect bfssingle6.newX -> bfssingle7.currentX, bfssingle8.oldX;
connect bfssingle6.newY -> bfssingle7.currentY, bfssingle8.oldY;
connect bfssingle6.safe -> bfssingle7.oldSafe;
connect bfssingle6.safeFound -> bfssingle7.oldSafeFound;
connect bfssingle6.newDirection -> bfssingle7.oldDirection;
connect bfssingle7.newX -> bfssingle8.currentX, bfssingle9.oldX;
connect bfssingle7.newY -> bfssingle8.currentY, bfssingle9.oldY;
connect bfssingle7.safe -> bfssingle8.oldSafe;
connect bfssingle7.safeFound -> bfssingle8.oldSafeFound;
connect bfssingle7.newDirection -> bfssingle8.oldDirection;
connect bfssingle8.newX -> bfssingle9.currentX, bfssingl9.oldX;
connect bfssingle8.newY -> bfssingle9.currentY, bfssingl9.oldY;
connect bfssingle8.safe -> bfssingle9.oldSafe;
connect bfssingle8.safeFound -> bfssingle9.oldSafeFound;
connect bfssingle8.newDirection -> bfssingle9.oldDirection;
connect bfssingle9.newX -> bfssingl9.currentX;
connect bfssingle9.newY -> bfssingl9.currentY;
connect bfssingle9.safe -> bfssingl9.oldSafe;
connect bfssingle9.safeFound -> bfssingl9.oldSafeFound;
connect bfssingle9.newDirection -> bfssingl9.oldDirection;
connect bfssingl9.newX -> endSafe.currentX;
connect bfssingl9.newY -> endSafe.currentY;
connect bfssingl9.safe -> endSafe.oldSafe;
connect bfssingl9.safeFound -> endSafe.oldSafeFound;
connect bfssingl9.newDirection -> endSafe.oldDirection;
connect endSafe.safe -> safe;
connect ghostX[:] -> bfssingle1.ghostX[:];
connect ghostX[:] -> bfssingle2.ghostX[:];
connect ghostX[:] -> bfssingle3.ghostX[:];
connect ghostX[:] -> bfssingle4.ghostX[:];
connect ghostX[:] -> bfssingle5.ghostX[:];
connect ghostX[:] -> bfssingle6.ghostX[:];
connect ghostX[:] -> bfssingle7.ghostX[:];
connect ghostX[:] -> bfssingle8.ghostX[:];
connect ghostX[:] -> bfssingle9.ghostX[:];
connect ghostX[:] -> bfssingl9.ghostX[:];
connect ghostX[:] -> endSafe.ghostX[:];
connect ghostY[:] -> bfssingle1.ghostY[:];
connect ghostY[:] -> bfssingle2.ghostY[:];
connect ghostY[:] -> bfssingle3.ghostY[:];
connect ghostY[:] -> bfssingle4.ghostY[:];
connect ghostY[:] -> bfssingle5.ghostY[:];
connect ghostY[:] -> bfssingle6.ghostY[:];
connect ghostY[:] -> bfssingle7.ghostY[:];
connect ghostY[:] -> bfssingle8.ghostY[:];
connect ghostY[:] -> bfssingle9.ghostY[:];
connect ghostY[:] -> bfssingl9.ghostY[:];
connect ghostY[:] -> endSafe.ghostY[:];
connect ghostDirection[:] -> bfssingle1.ghostDirection[:];
connect ghostDirection[:] -> bfssingle2.ghostDirection[:];
connect ghostDirection[:] -> bfssingle3.ghostDirection[:];
connect ghostDirection[:] -> bfssingle4.ghostDirection[:];
connect ghostDirection[:] -> bfssingle5.ghostDirection[:];
connect ghostDirection[:] -> bfssingle6.ghostDirection[:];
connect ghostDirection[:] -> bfssingle7.ghostDirection[:];
connect ghostDirection[:] -> bfssingle8.ghostDirection[:];
connect ghostDirection[:] -> bfssingle9.ghostDirection[:];
connect ghostDirection[:] -> bfssingl9.ghostDirection[:];
connect ghostDirection[:] -> endSafe.ghostDirection[:];
connect ghostEatable[:] -> bfssingle1.ghostEatable[:];
connect ghostEatable[:] -> bfssingle2.ghostEatable[:];
connect ghostEatable[:] -> bfssingle3.ghostEatable[:];
connect ghostEatable[:] -> bfssingle4.ghostEatable[:];
connect ghostEatable[:] -> bfssingle5.ghostEatable[:];
connect ghostEatable[:] -> bfssingle6.ghostEatable[:];
connect ghostEatable[:] -> bfssingle7.ghostEatable[:];
connect ghostEatable[:] -> bfssingle8.ghostEatable[:];
connect ghostEatable[:] -> bfssingle9.ghostEatable[:];
connect ghostEatable[:] -> bfssingl9.ghostEatable[:];
connect ghostEatable[:] -> endSafe.ghostEatable[:];
connect map -> bfssingle1.map;
connect map -> bfssingle2.map;
connect map -> bfssingle3.map;
connect map -> bfssingle4.map;
connect map -> bfssingle5.map;
connect map -> bfssingle6.map;
connect map -> bfssingle7.map;
connect map -> bfssingle8.map;
connect map -> bfssingle9.map;
connect map -> bfssingl9.map;
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.BFS;
// check whether the surrounding tiles are safe
component EndSafe {
ports
in Q(0m: 20m) currentX,
in Q(1m: 23m) currentY,
in Q(0m: 20m) ghostX[4],
in Q(1m: 23m) ghostY[4],
in Z(0 : 1 : 3) ghostDirection[4],
in B ghostEatable[4],
in B oldSafe,
in B oldSafeFound,
in Z oldDirection,
out B safe;
implementation Math {
Z^{1,4} xOffSet = [0,0,-1,1];
Z^{1,4} yOffSet = [-1,1,0,0];
safe = 1;
if oldSafe
for i = 1:4
if (ghostEatable(i) == 0)
Z xG = round(ghostX(i));
Z yG = round(ghostY(i));
Z xC = currentX;
Z yC = currentY;
if (xG == xC) && (yG == yC)
safe = 0;
end
for j = 0:3
xC = currentX + xOffSet(0,j);
yC = currentY + yOffSet(0,j);
if (xG == xC) && (yG == yC) && (ghostEatable(i) == 0) && (ghostDirection(i) != j)
safe = 0;
end
end
end
end
else
safe = 0;
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.BFS;
import de.rwth.pacman.heithoff2.BFS.start.*;
// check whether the four directions are safe to go
// a directions is not safe to go if there is a ghost on its path
component Paths {
ports
in Q(0m: 20m) ghostX[4],
in Q(1m: 23m) ghostY[4],
in Z(0 : 1 : 3) ghostDirection[4],
in B ghostEatable[4],
in Q(0m: 20m) pacManX,
in Q(1m: 23m) pacManY,
in Z^{22,19} map,
out B topSafe,
out B bottomSafe,
out B leftSafe,
out B rightSafe;
instance BFSearch searchLeft;
instance BFSearch searchRight;
instance BFSearch searchTop;
instance BFSearch searchBottom;
instance StartLeft startLeft;
instance StartRight startRight;
instance StartTop startTop;
instance StartBottom startBottom;
connect pacManX -> startLeft.pacManX, startRight.pacManX, startTop.pacManX, startBottom.pacManX;
connect pacManY -> startLeft.pacManY, startRight.pacManY, startTop.pacManY, startBottom.pacManY;
connect ghostX[:] -> searchLeft.ghostX[:], searchRight.ghostX[:], searchTop.ghostX[:], searchBottom.ghostX[:];
connect ghostY[:] -> searchLeft.ghostY[:], searchRight.ghostY[:], searchTop.ghostY[:], searchBottom.ghostY[:];
connect ghostDirection[:] -> searchLeft.ghostDirection[:], searchRight.ghostDirection[:], searchTop.ghostDirection[:], searchBottom.ghostDirection[:];
connect ghostEatable[:] -> searchLeft.ghostEatable[:], searchRight.ghostEatable[:], searchTop.ghostEatable[:], searchBottom.ghostEatable[:];
connect map -> searchLeft.map, searchRight.map, searchTop.map, searchBottom.map;
connect pacManX -> searchLeft.pacManX, searchRight.pacManX, searchTop.pacManX, searchBottom.pacManX;
connect pacManY -> searchLeft.pacManY, searchRight.pacManY, searchTop.pacManY, searchBottom.pacManY;
connect startLeft.startX -> searchLeft.startX;
connect startLeft.startY -> searchLeft.startY;
connect startLeft.startD -> searchLeft.startDirection;
connect startRight.startX -> searchRight.startX;
connect startRight.startY -> searchRight.startY;
connect startRight.startD -> searchRight.startDirection;
connect startTop.startX -> searchTop.startX;
connect startTop.startY -> searchTop.startY;
connect startTop.startD -> searchTop.startDirection;
connect startBottom.startX -> searchBottom.startX;
connect startBottom.startY -> searchBottom.startY;
connect startBottom.startD -> searchBottom.startDirection;
connect searchLeft.safe -> leftSafe;
connect searchRight.safe -> rightSafe;
connect searchTop.safe -> topSafe;
connect searchBottom.safe -> bottomSafe;
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.BFS.single;
component CalcNewPosition {
ports
in Q(0m: 20m) currentX,
in Q(1m: 23m) currentY,
in Q(0m: 20m) oldX,
in Q(1m: 23m) oldY,
in Z^{22,19} map,
in B searchFinished,
in B positionIsSafe,
out Q(0m: 20m) newX,
out Q(1m: 23m) newY,
out Z newDirection,
out B safeFound;
implementation Math {
newX = currentX;
newY = currentY;
newDirection = 0;
safeFound = 0;
if (searchFinished == 0) && (positionIsSafe == 1)
// check for intersection or calculate the next tile
Z^{1,4} xOffSet = [0,0,-1,1];
Z^{1,4} yOffSet = [-1,1,0,0];
safeFound = 0;
Z newPathsFound = 0;
for i = 0:3
Z indexY = 0;
Z indexX = i;
Z xOff = xOffSet(indexY, indexX);
Z yOff = yOffSet(indexY, indexX);
Q xT = currentX + xOff;
Q yT = currentY + yOff;
if (abs(xT - oldX) >= 1) || (abs(yT - oldY) >= 1)
Z nextTile = map(yT, xT);
// if (yT < 23) && (yT > 0) && (xT < 20) && (xT > 0)
// nextTile = map(yT, xT);
// end
if (nextTile != 0) && (nextTile != 3) // a non-blocking tile was found
newPathsFound = newPathsFound + 1;
newX = xT;
newY = yT;
newDirection = i;
if newPathsFound > 1
safeFound = 1;
newX = currentX;
newY = currentY;
end
end
end
end
end
}
}
\ No newline at end of file
package de.rwth.pacman.heithoff2.BFS.single;
component ControlFlow {
ports
in Q(0m: 20m) currentX,
in Q(1m: 23m) currentY,
in B searchFinished,
in B safeFromSearchFinished,
in B safeFoundFromSearchFinished,
in Z oldDirection,