Jump to content

Sokoban: Difference between revisions

Updated first D entry
(Updated timings first D entry)
(Updated first D entry)
Line 758:
private immutable int playerx, playery;
 
this(in string[] board) immutable pure nothrow const @safe
in {
foreach (const row; board) {
Line 795:
in int dy, ref CTable data)
const pure nothrow /*@safe*/ {
if (sData[(y + dy) * ncols + x + dx] == El.wall ||
data[(y + dy) * ncols + x + dx] != El.floor)
return false;
 
Line 809:
in int dy, ref CTable data)
const pure nothrow /*@safe*/ {
if (sData[(y + 2 * dy) * ncols + x + 2 * dx] == El.wall ||
data[(y + 2 * dy) * ncols + x + 2 * dx] != El.floor)
return false;
 
Line 816:
data2[y * ncols + x] = El.floor;
data2[(y + dy) * ncols + x + dx] = El.player;
data2[(y + 2 * dy) * ncols + x + 2*dx] = El.boxOnGoal;
data = data2.assumeUnique; // Not enforced.
return true;
Line 836:
open.push(Four(dData, "", playerx, playery));
 
static immutable dirs = [tuple( 0, -1, 'u', 'U'),
tuple( 1, 0, 'r', 'R'),
tuple( 0, 1, 'd', 'D'),
tuple(-1, 0, 'l', 'L')];
 
while (!open.empty) {
Line 859:
if (isSolved(temp))
return cSol ~ di[3];
open.push(Four(temp, cSol ~ di[3], x + dx, y + dy));
visitedSet[temp] = true;
}
} else if (move(x, y, dx, dy, temp) && temp !in visitedSet) {
temp !in visitedSet) {
if (isSolved(temp))
return cSol ~ di[2];
open.push(Four(temp, cSol ~ di[2], x + dx, y + dy));
visitedSet[temp] = true;
}
Line 878 ⟶ 877:
void main() {
import std.stdio, core.memory;
GC.disable; // Uses about twice the memory.
 
immutable level =
Line 890 ⟶ 889:
#######";
 
constimmutable b = constimmutable(Board)(level.splitLines);
writeln(level, "\n\n", b.solve);
}</lang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.