emoflon / emoflon-ibex-examples Goto Github PK
View Code? Open in Web Editor NEWAll examples and artefacts used for the eMoflon::IBeX handbook.
All examples and artefacts used for the eMoflon::IBeX handbook.
I added some (often technical) ideas on how to improve the handbooks.
Below follows a suggestion for refactoring the handbook example using additional intermediate methods.
Maybe, it could be sensible to introduce a dedicated generated "MatchEventSink/Listener" interface that provides suitable unimplemented or default-implemented methods for appearing and disappearing matches (e.g. MoveSokobanUpMatchEventListener::matchAppeared(MoveSokobanUpMatch)
and MoveSokobanUpMatchEventListener::matchDisappeared(MoveSokobanUpMatch)
)
package org.moflon.tutorial.sokobangamegui.rules;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import SokobanLanguage.Board;
import SokobanLanguage.Field;
import SokobanLanguage.Figure;
import SokobanLanguage.Sokoban;
import SokobanRules.SokobanValidator;
import SokobanRules.api.SokobanRulesAPI;
import SokobanRules.api.matches.MoveSokobanUpMatch;
import SokobanRules.api.matches.PushBlockUpMatch;
public class SokobanRules
{
private String allsWell = "Everything seems to be ok...";
private SokobanRulesAPI api;
// Keep track of all currently possible moves
private Map<Field, Supplier<Result>> possibleMoves;
public SokobanRules(Board board)
{
this.api = new SokobanValidator(board).initAPI();
possibleMoves = new HashMap<>();
api.moveSokobanUp().subscribeAppearing(m -> registerMoveSokobanUpMatch(m));
api.moveSokobanUp().subscribeDisappearing(m -> unregisterSokobanMoveUpMatch(m));
api.pushBlockUp().subscribeAppearing(m -> registerPushBlockUpMatch(m));
api.pushBlockUp().subscribeDisappearing(m -> unregisterPushBlockUpMatch(m));
}
private void unregisterSokobanMoveUpMatch(MoveSokobanUpMatch m)
{
possibleMoves.remove(m.getTo());
}
private void registerMoveSokobanUpMatch(MoveSokobanUpMatch m)
{
Field targetField = m.getTo();
registerRuleApplication(targetField, targetField, () -> api.moveSokobanUp().apply());
}
private void registerPushBlockUpMatch(PushBlockUpMatch m)
{
registerRuleApplication(m.getTo(), m.getNext(), () -> api.pushBlockUp().apply());
}
private Supplier<Result> unregisterPushBlockUpMatch(PushBlockUpMatch m)
{
return possibleMoves.remove(m.getTo());
}
// If the required field ("emptyField") is indeed empty, add the potential rule application
private void registerRuleApplication(Field targetField, Field emptyField, Runnable applyRule)
{
if (!isEmpty(emptyField))
possibleMoves.put(targetField, () -> {
applyRule.run();
return new Result(true, "Go Sokoban!");
});
}
private boolean isEmpty(Field field)
{
return api.anOccupiedField().bindField(field).hasMatches();
}
public Result move(Figure figure, Field field)
{
// Refuse to do anything if the chosen figure is not Sokoban
if (!(figure instanceof Sokoban))
return new Result(false, "You can only move Sokoban!");
if (possibleMoves.containsKey(field))
return possibleMoves.get(field).get();
else
return new Result(false, "Sokoban can't move to " + "[" + field.getRow() + "," + field.getCol() + "]");
}
public Result validateBoard(Board board)
{
final int blockCount = api.oneBlock().countMatches();
final int endPositionFieldsCount = api.oneEndField().countMatches();
if (blockCount == 0)
return new Result(false, "You must have at least one Block!");
if (blockCount != endPositionFieldsCount)
return new Result(false, "Number of blocks needs to equal number of end-position fields.");
if (api.boulderOnEndField().countMatches() != 0)
return new Result(false, "An end position is blocked by a boulder.");
if (api.oneSokoban().countMatches() != 1)
return new Result(false, "You must have exactly one Sokoban!");
return new Result(true, allsWell);
}
}
Document optimisation flags and their effect on the handbook tgg.
Idea: Pattern findBlockNotOnEndPosition
matching a block not on an end position (can be used to introduce NACs?).
Subscribe to appearing/disappearing matches and maintain a set of blocks not on an end position. If the size of a set reaches 0, the game is over.
Please check version 1 to see what I mean (perhaps it is sufficient to just copy the documentation there). At the moment this is what you have: @genmodel(documentation="TODO: Add documentation for Blup")
Explain what each metamodel represents.
At the moment there are no working sets to organise the projects in the workspace.
Document what MA is and how to use it (perhaps a small example?)
Document how to use the OPT apps. Best after improving usage via automatic generation of registration helpers.
Document how to install and setup/use all ILP solvers.
Document how to add a new ILP solver (interface).
The error message produced by validateBoard remains visible even after fixing the problem in edit mode.
This could be confusing.
Maybe a more reactive validation would be helpful. At least, the validation errors should be removed as soon as the model is modified in edit mode.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.