commit e3db24dcab5830b4d283ad3fc6cd4b84c3b17a2b Author: Christian Fraß Date: Wed Nov 8 11:30:34 2017 +0100 erste Übergabe diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1418c59 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +erzeugnis diff --git a/makefile b/makefile new file mode 100644 index 0000000..6da96ff --- /dev/null +++ b/makefile @@ -0,0 +1,32 @@ +erzeugnis/vtm.js: \ + quelldatein/basis/typen.ts \ + quelldatein/basis/fehlermonade.ts \ + quelldatein/helfer/hashmap.ts \ + quelldatein/aufbau/richtung.ts \ + quelldatein/aufbau/symbol.ts \ + quelldatein/aufbau/position.ts \ + quelldatein/aufbau/figur.ts \ + quelldatein/aufbau/aktor.ts \ + quelldatein/aufbau/befoerderer.ts \ + quelldatein/aufbau/schreiber.ts \ + quelldatein/aufbau/verwerfer.ts \ + quelldatein/aufbau/welt.ts \ + quelldatein/test.ts + mkdir -p erzeugnis + tsc \ + --allowUnreachableCode \ + quelldatein/basis/typen.ts \ + quelldatein/basis/fehlermonade.ts \ + quelldatein/helfer/hashmap.ts \ + quelldatein/aufbau/richtung.ts \ + quelldatein/aufbau/symbol.ts \ + quelldatein/aufbau/position.ts \ + quelldatein/aufbau/figur.ts \ + quelldatein/aufbau/aktor.ts \ + quelldatein/aufbau/befoerderer.ts \ + quelldatein/aufbau/schreiber.ts \ + quelldatein/aufbau/verwerfer.ts \ + quelldatein/aufbau/welt.ts \ + quelldatein/test.ts \ + --outFile erzeugnis/vtm.js + diff --git a/quelldatein/aufbau/aktor.ts b/quelldatein/aufbau/aktor.ts new file mode 100644 index 0000000..289541a --- /dev/null +++ b/quelldatein/aufbau/aktor.ts @@ -0,0 +1,20 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export interface schnittstelle_aktor + { + + /** + * @author kcf + */ + verwenden(figur : klasse_figur) : void; + + } + + } + + diff --git a/quelldatein/aufbau/befoerderer.ts b/quelldatein/aufbau/befoerderer.ts new file mode 100644 index 0000000..df0f81f --- /dev/null +++ b/quelldatein/aufbau/befoerderer.ts @@ -0,0 +1,40 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export class klasse_befoerderer + implements schnittstelle_aktor + { + + /** + * @author kcf + */ + private richtung : typ_richtung; + + + /** + * @author kcf + */ + public constructor(richtung : typ_richtung = 0) + { + this.richtung = richtung; + } + + + /** + * @author kcf + * @implementation + */ + public verwenden(figur : klasse_figur) : void + { + figur.bewegen(this.richtung); + } + + } + + } + + diff --git a/quelldatein/aufbau/figur.ts b/quelldatein/aufbau/figur.ts new file mode 100644 index 0000000..b800a4c --- /dev/null +++ b/quelldatein/aufbau/figur.ts @@ -0,0 +1,119 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export class klasse_figur + { + + /** + * @author kcf + */ + private band : Array; + + + /** + * @author kcf + */ + private position : typ_position; + + + /** + * @author kcf + */ + public constructor(band : Array = [], position : typ_position = {"u": 0, "v": 0}) + { + this.band = band; + this.position = position; + } + + + /** + * @author kcf + */ + public position_lesen() : typ_position + { + return this.position; + } + + + /** + * @author kcf + */ + public bewegen(richtung : typ_richtung) : void + { + let summand : typ_position; + switch (richtung) + { + case 0: + { + summand = {"u": +1, "v": 0}; + break; + } + case 1: + { + summand = {"u": +1, "v": 0}; + break; + } + case 2: + { + summand = {"u": +1, "v": 0}; + break; + } + case 3: + { + summand = {"u": +1, "v": 0}; + break; + } + case 4: + { + summand = {"u": +1, "v": 0}; + break; + } + case 5: + { + summand = {"u": +1, "v": 0}; + break; + } + default: + { + let meldung : string = ("ungültige Richtung '" + String(richtung) + "'"); + throw (new Error(meldung)); + break; + } + } + this.position = {"u": (this.position.u + summand.u), "v": (this.position.v + summand.v)}; + } + + + /** + * @author kcf + */ + public band_schreiben(symbol : typ_symbol) : void + { + this.band.push(symbol); + } + + + /** + * @author kcf + */ + public band_lesen() : schnittstelle_fehlermonade + { + if (this.band.length <= 0) + { + return (new klasse_nichts()); + } + else + { + return (new klasse_schlicht(this.band[0])); + } + } + + } + + } + + diff --git a/quelldatein/aufbau/position.ts b/quelldatein/aufbau/position.ts new file mode 100644 index 0000000..e168ce5 --- /dev/null +++ b/quelldatein/aufbau/position.ts @@ -0,0 +1,20 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export type typ_position = {u : int; v : int;}; + + + /** + * @author kcf + */ + export function position_hash(position : typ_position) : string + { + return (position.u.toFixed(0) + "_" + position.v.toFixed(0)); + } + + } + diff --git a/quelldatein/aufbau/richtung.ts b/quelldatein/aufbau/richtung.ts new file mode 100644 index 0000000..ae35807 --- /dev/null +++ b/quelldatein/aufbau/richtung.ts @@ -0,0 +1,11 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export type typ_richtung = int; + + } + diff --git a/quelldatein/aufbau/schreiber.ts b/quelldatein/aufbau/schreiber.ts new file mode 100644 index 0000000..b0ecf70 --- /dev/null +++ b/quelldatein/aufbau/schreiber.ts @@ -0,0 +1,48 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export class klasse_schreiber + implements schnittstelle_aktor + { + + /** + * @author kcf + */ + private symbol : typ_symbol; + + + /** + * @author kcf + */ + private richtung : typ_richtung; + + + /** + * @author kcf + */ + public constructor(symbol : int = 0, richtung : int = 0) + { + this.symbol = symbol; + this.richtung = richtung; + } + + + /** + * @author kcf + * @implementation + */ + public verwenden(figur : klasse_figur) : void + { + figur.band_schreiben(this.symbol); + figur.bewegen(this.richtung); + } + + } + + } + + diff --git a/quelldatein/aufbau/symbol.ts b/quelldatein/aufbau/symbol.ts new file mode 100644 index 0000000..badcc53 --- /dev/null +++ b/quelldatein/aufbau/symbol.ts @@ -0,0 +1,11 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export type typ_symbol = int; + + } + diff --git a/quelldatein/aufbau/verwerfer.ts b/quelldatein/aufbau/verwerfer.ts new file mode 100644 index 0000000..75ed968 --- /dev/null +++ b/quelldatein/aufbau/verwerfer.ts @@ -0,0 +1,34 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export class klasse_verwerfer + implements schnittstelle_aktor + { + + /** + * @author kcf + */ + public constructor() + { + } + + + /** + * @author kcf + * @implementation + */ + public verwenden(figur : klasse_figur) : void + { + // TODO + console.warn("not implemented"); + } + + } + + } + + diff --git a/quelldatein/aufbau/welt.ts b/quelldatein/aufbau/welt.ts new file mode 100644 index 0000000..09d7c82 --- /dev/null +++ b/quelldatein/aufbau/welt.ts @@ -0,0 +1,64 @@ + +module mod_vtm_aufbau + { + + /** + * @author kcf + */ + export class klasse_welt + { + + /** + * @author kcf + */ + private felder : mod_vtm_helfer.klasse_hashmap; + + + /** + * @author kcf + */ + private figur : klasse_figur; + + + /** + * @author kcf + */ + public constructor + ( + felder : mod_vtm_helfer.klasse_hashmap = new mod_vtm_helfer.klasse_hashmap(position_hash), + figur : klasse_figur = new klasse_figur() + ) + { + this.felder = felder; + this.figur = figur; + } + + + /** + * @author kcf + */ + public feld_setzen(position : typ_position, aktor : schnittstelle_aktor) : void + { + this.felder.setzen(position, aktor); + } + + + /** + * @author kcf + */ + public fortfahren() : void + { + let position : typ_position = this.figur.position_lesen(); + let aktor_ : schnittstelle_fehlermonade = this.felder.holen(position); + let aktor : schnittstelle_aktor = (aktor_.ist_schlicht() ? aktor_.lesen() : (new klasse_verwerfer())); + let ergebnis : any = aktor.verwenden(this.figur); + // + let position_ : typ_position = this.figur.position_lesen(); + console.info(JSON.stringify(position) + " -> " + JSON.stringify(position_)); + } + + } + + } + + diff --git a/quelldatein/basis/fehlermonade.ts b/quelldatein/basis/fehlermonade.ts new file mode 100644 index 0000000..fc2454e --- /dev/null +++ b/quelldatein/basis/fehlermonade.ts @@ -0,0 +1,99 @@ + +/** + * @author kcf + */ +interface schnittstelle_fehlermonade + { + + /** + * @author kcf + */ + ist_schlicht() : boolean; + + + /** + * @author kcf + */ + lesen() : typ_wert; + + } + + +/** + * @author kcf + */ +class klasse_nichts + implements schnittstelle_fehlermonade + { + + /** + * @author kcf + */ + public constructor() + { + + } + + + /** + * @author kcf + */ + public ist_schlicht() : boolean + { + return false; + } + + + /** + * @author kcf + */ + public lesen() : typ_wert + { + let meldung : string = "ist nichts"; + throw (new Error(meldung)); + } + + } + + +/** + * @author kcf + */ +class klasse_schlicht + implements schnittstelle_fehlermonade + { + + /** + * @author kcf + */ + private wert : typ_wert; + + + /** + * @author kcf + */ + public constructor(wert : typ_wert) + { + this.wert = wert; + } + + + /** + * @author kcf + */ + public ist_schlicht() : boolean + { + return true; + } + + + /** + * @author kcf + */ + public lesen() : typ_wert + { + return this.wert; + } + + } + diff --git a/quelldatein/basis/typen.ts b/quelldatein/basis/typen.ts new file mode 100644 index 0000000..fb68235 --- /dev/null +++ b/quelldatein/basis/typen.ts @@ -0,0 +1,12 @@ + +/** + * @author kcf + */ +type int = number; + + +/** + * @author kcf + */ +type float = number; + diff --git a/quelldatein/helfer/hashmap.ts b/quelldatein/helfer/hashmap.ts new file mode 100644 index 0000000..2b42b67 --- /dev/null +++ b/quelldatein/helfer/hashmap.ts @@ -0,0 +1,63 @@ + +module mod_vtm_helfer + { + + /** + * @author kcf + */ + export class klasse_hashmap + { + + /** + * @author kcf + */ + private hashfunction : (schluessel : typ_schluessel)=>string; + + + /** + * @author kcf + */ + private speicher : {[hashwert : string] : typ_wert}; + + + /** + * @author kcf + */ + public constructor(hashfunction : (schluessel : typ_schluessel)=>string) + { + this.hashfunction = hashfunction; + this.speicher = {}; + } + + + /** + * @author kcf + */ + public setzen(schluessel : typ_schluessel, wert : typ_wert) : void + { + let hashwert : string = this.hashfunction(schluessel); + this.speicher[hashwert] = wert; + } + + + /** + * @author kcf + */ + public holen(schluessel : typ_schluessel) : schnittstelle_fehlermonade + { + let hashwert : string = this.hashfunction(schluessel); + if (hashwert in this.speicher) + { + let wert : typ_wert = this.speicher[hashwert]; + return (new klasse_schlicht(wert)); + } + else + { + return (new klasse_nichts()); + } + } + + } + + } + diff --git a/quelldatein/test.ts b/quelldatein/test.ts new file mode 100644 index 0000000..e128b35 --- /dev/null +++ b/quelldatein/test.ts @@ -0,0 +1,19 @@ + +module mod_vtm_test + { + + /** + * @author kcf + */ + function haupt() : void + { + let welt : mod_vtm_aufbau.klasse_welt = new mod_vtm_aufbau.klasse_welt(); + welt.feld_setzen({"u": 0, "v": 0}, new mod_vtm_aufbau.klasse_befoerderer(0)); + welt.fortfahren(); + } + + + haupt(); + + } +