BoulderDash and Tom using HashMap as topology
To create a gravity system using Tom rewriting system leeds to these basic rules (exprimed in Tom + Java):
public boolean gravity(HashMap newSpace, Bead b) {
%match(Bead b) {
beadRock[s=empty()] -> {
Bead newBead = `bead(getSouthPosition(b.getPos()),b.getValue());
marked.add(b);
putBead(newSpace,newBead);
return true;
}
beadRock[s=s@beadRock[e=empty()],e=empty()] -> {
Bead newBead = `bead(getEastPosition(getSouthPosition(b.getPos())),b.getValue());
putBead(newSpace,newBead);
putBead(newSpace,s);
marked.add(b);
marked.add(s);
return true;
}
beadRock[s=s@beadRock[w=empty()],w=empty()] -> {
Bead newBead = `bead(getWestPosition(getSouthPosition(b.getPos())),b.getValue());
putBead(newSpace,newBead);
putBead(newSpace,s);
marked.add(b);
marked.add(s);
return true;
}
bead[pos=p] -> {
newSpace.put(p,b);
return false;
}
}
return false;
}