RuleTransducer

io.github.memo33.metarules.meta.RuleTransducerSyntax.RuleTransducer

The main logic to translate meta code (Rule[Tile]) to proper RUL2 code (Rule[IdTile]). The crux of that is that a single meta rule can result in multiple RUL2 rules, based on the symmetries of the tiles involved. Exactly those rules and orientations will be generated that are necessary. Compare, for example:

scala> transduce( L1Rhw2~WE | (Dirtroad ~> L1Rhw2)~WE )
Rule( 0x57100000,1,0 | 0x57000000,1,0 | 0x57100000,1,0 | 0x57100000,1,0 )
Rule( 0x57100000,3,0 | 0x57000000,3,0 | 0x57100000,3,0 | 0x57100000,3,0 )

scala> transduce( L1Rhw3~WE | (Dirtroad ~> L1Rhw3)~WE )
Rule( 0x57110000,3,0 | 0x57000000,1,0 | 0x57110000,3,0 | 0x57110000,3,0 )
Rule( 0x57110000,3,0 | 0x57000000,3,0 | 0x57110000,3,0 | 0x57110000,3,0 )
Rule( 0x57110000,1,0 | 0x57000000,3,0 | 0x57110000,1,0 | 0x57110000,1,0 )
Rule( 0x57110000,1,0 | 0x57000000,1,0 | 0x57110000,1,0 | 0x57110000,1,0 )

scala> transduce( Mis~WE & Rail~NW | (Dirtroad ~> Mis)~WE & Dirtroad~ES )
Rule( 0x57024580,1,0 | 0x57004A00,3,0 | 0x57024580,1,0 | 0x57024A00,3,0 )

If in doubt, start up the sbt console and use the transduce function to check the output.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

case class Context(resolve: Tile => IdTile, tileOrientationCache: Map[Int, Set[RotFlip]], preprocess: Rule[SymTile] => Iterator[Rule[SymTile]])

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
class ResolutionFailed(val tile: SymTile, val rule: Option[Rule[SymTile]], val reason: Throwable, val frame: Option[StackTraceElement]) extends Exception

Attributes

Supertypes
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def apply(rule: Rule[SymTile])(implicit context: Context): Iterator[Rule[IdTile]]

Concrete fields

val LOGGER: Logger