Anonymous user
Sokoban: Difference between revisions
Safer second D entry
(→{{header|Perl}}: Totally rewrote the perl solution.) |
(Safer second D entry) |
||
Line 923:
enum Cell : ubyte { space, wall, player, box }
alias CellIndex = ushort;
alias
Line 931 ⟶ 930:
/// indices of player and boxes.
struct State { // Variable length struct.
State* prev, next, qNext;
CellIndex[0] c_;
return
}
void set(in size_t i, in CellIndex v) pure nothrow {
c_.ptr[i] = v;
}
CellIndex[] slice(in size_t i, in size_t j) pure nothrow {
return
}
}
Line 950 ⟶ 953:
__gshared State* blockRoot, blockHead, nextLevel, done;
__gshared State*[] buckets;
__gshared
Line 1,058 ⟶ 1,061:
i.markLive;
if (s[i] == '$' || s[i] == '*')
state.
else if (s[i] == '@' || s[i] == '+')
state.
}
Line 1,070 ⟶ 1,073:
void hash(State* s, in size_t nBoxes) pure nothrow {
if (!s.h) {
foreach (immutable i; 0 .. nBoxes + 1)
ha = s.
s.h = ha;
}
Line 1,097 ⟶ 1,100:
buckets[oldSize .. hashSize] = null;
immutable
foreach (immutable i; 0 .. oldSize) {
auto head = buckets[i];
Line 1,133 ⟶ 1,136:
extendTable;
immutable
s.next = buckets[i];
Line 1,143 ⟶ 1,146:
bool success(in State* s) nothrow {
foreach (immutable i; 1 .. nBoxes + 1)
if (!goals[s.
return false;
return true;
Line 1,150 ⟶ 1,153:
State* moveMe(State* s, in int dy, in int dx) nothrow {
immutable int y = s.
immutable int x = s.
immutable int y1 = y + dy;
immutable int x1 = x + dx;
Line 1,161 ⟶ 1,164:
int atBox = 0;
foreach (immutable i; 1 .. nBoxes + 1)
if (s.
atBox = i;
break;
Line 1,172 ⟶ 1,175:
return null;
foreach (immutable i; 1 .. nBoxes + 1)
if (s.
return null;
}
Line 1,179 ⟶ 1,182:
n.slice(1, nBoxes + 1)[] = s.slice(1, nBoxes + 1);
n.
if (atBox)
n.
// Bubble sort.
Line 1,188 ⟶ 1,191:
CellIndex t = 0;
foreach (immutable j; 1 .. i) {
if (n.
t = n.
n.
n.
}
}
Line 1,235 ⟶ 1,238:
b[] = cast(typeof(b))board[];
b[s.
foreach (immutable i; 1 .. nBoxes + 1)
b[s.
foreach (immutable i, immutable bi; b) {
|