erste Übergabe
This commit is contained in:
commit
e3db24dcab
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
erzeugnis
|
||||
32
makefile
Normal file
32
makefile
Normal file
|
|
@ -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
|
||||
|
||||
20
quelldatein/aufbau/aktor.ts
Normal file
20
quelldatein/aufbau/aktor.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export interface schnittstelle_aktor
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
verwenden(figur : klasse_figur) : void;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
40
quelldatein/aufbau/befoerderer.ts
Normal file
40
quelldatein/aufbau/befoerderer.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export class klasse_befoerderer
|
||||
implements schnittstelle_aktor
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private richtung : typ_richtung;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor(richtung : typ_richtung = 0)
|
||||
{
|
||||
this.richtung = richtung;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
* @implementation
|
||||
*/
|
||||
public verwenden(figur : klasse_figur) : void
|
||||
{
|
||||
figur.bewegen(this.richtung);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
119
quelldatein/aufbau/figur.ts
Normal file
119
quelldatein/aufbau/figur.ts
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export class klasse_figur
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private band : Array<typ_symbol>;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private position : typ_position;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor(band : Array<typ_symbol> = [], position : typ_position = {"u": 0, "v": 0})
|
||||
{
|
||||
this.band = band;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public position_lesen() : typ_position
|
||||
{
|
||||
return this.position;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
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 <vidofnir@folksprak.org>
|
||||
*/
|
||||
public band_schreiben(symbol : typ_symbol) : void
|
||||
{
|
||||
this.band.push(symbol);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public band_lesen() : schnittstelle_fehlermonade<typ_symbol>
|
||||
{
|
||||
if (this.band.length <= 0)
|
||||
{
|
||||
return (new klasse_nichts<typ_symbol>());
|
||||
}
|
||||
else
|
||||
{
|
||||
return (new klasse_schlicht<typ_symbol>(this.band[0]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
20
quelldatein/aufbau/position.ts
Normal file
20
quelldatein/aufbau/position.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export type typ_position = {u : int; v : int;};
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export function position_hash(position : typ_position) : string
|
||||
{
|
||||
return (position.u.toFixed(0) + "_" + position.v.toFixed(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
11
quelldatein/aufbau/richtung.ts
Normal file
11
quelldatein/aufbau/richtung.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export type typ_richtung = int;
|
||||
|
||||
}
|
||||
|
||||
48
quelldatein/aufbau/schreiber.ts
Normal file
48
quelldatein/aufbau/schreiber.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export class klasse_schreiber
|
||||
implements schnittstelle_aktor
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private symbol : typ_symbol;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private richtung : typ_richtung;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor(symbol : int = 0, richtung : int = 0)
|
||||
{
|
||||
this.symbol = symbol;
|
||||
this.richtung = richtung;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
* @implementation
|
||||
*/
|
||||
public verwenden(figur : klasse_figur) : void
|
||||
{
|
||||
figur.band_schreiben(this.symbol);
|
||||
figur.bewegen(this.richtung);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
11
quelldatein/aufbau/symbol.ts
Normal file
11
quelldatein/aufbau/symbol.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export type typ_symbol = int;
|
||||
|
||||
}
|
||||
|
||||
34
quelldatein/aufbau/verwerfer.ts
Normal file
34
quelldatein/aufbau/verwerfer.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export class klasse_verwerfer
|
||||
implements schnittstelle_aktor
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
* @implementation
|
||||
*/
|
||||
public verwenden(figur : klasse_figur) : void
|
||||
{
|
||||
// TODO
|
||||
console.warn("not implemented");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
64
quelldatein/aufbau/welt.ts
Normal file
64
quelldatein/aufbau/welt.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
module mod_vtm_aufbau
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export class klasse_welt
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private felder : mod_vtm_helfer.klasse_hashmap<typ_position, schnittstelle_aktor>;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private figur : klasse_figur;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor
|
||||
(
|
||||
felder : mod_vtm_helfer.klasse_hashmap<typ_position, schnittstelle_aktor> = new mod_vtm_helfer.klasse_hashmap<typ_position, schnittstelle_aktor>(position_hash),
|
||||
figur : klasse_figur = new klasse_figur()
|
||||
)
|
||||
{
|
||||
this.felder = felder;
|
||||
this.figur = figur;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public feld_setzen(position : typ_position, aktor : schnittstelle_aktor) : void
|
||||
{
|
||||
this.felder.setzen(position, aktor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public fortfahren() : void
|
||||
{
|
||||
let position : typ_position = this.figur.position_lesen();
|
||||
let aktor_ : schnittstelle_fehlermonade<schnittstelle_aktor> = 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_));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
99
quelldatein/basis/fehlermonade.ts
Normal file
99
quelldatein/basis/fehlermonade.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
interface schnittstelle_fehlermonade<typ_wert>
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
ist_schlicht() : boolean;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
lesen() : typ_wert;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
class klasse_nichts<typ_wert>
|
||||
implements schnittstelle_fehlermonade<typ_wert>
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public ist_schlicht() : boolean
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public lesen() : typ_wert
|
||||
{
|
||||
let meldung : string = "ist nichts";
|
||||
throw (new Error(meldung));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
class klasse_schlicht<typ_wert>
|
||||
implements schnittstelle_fehlermonade<typ_wert>
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private wert : typ_wert;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor(wert : typ_wert)
|
||||
{
|
||||
this.wert = wert;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public ist_schlicht() : boolean
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public lesen() : typ_wert
|
||||
{
|
||||
return this.wert;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
quelldatein/basis/typen.ts
Normal file
12
quelldatein/basis/typen.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
type int = number;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
type float = number;
|
||||
|
||||
63
quelldatein/helfer/hashmap.ts
Normal file
63
quelldatein/helfer/hashmap.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
module mod_vtm_helfer
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
export class klasse_hashmap<typ_schluessel, typ_wert>
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private hashfunction : (schluessel : typ_schluessel)=>string;
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
private speicher : {[hashwert : string] : typ_wert};
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public constructor(hashfunction : (schluessel : typ_schluessel)=>string)
|
||||
{
|
||||
this.hashfunction = hashfunction;
|
||||
this.speicher = {};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public setzen(schluessel : typ_schluessel, wert : typ_wert) : void
|
||||
{
|
||||
let hashwert : string = this.hashfunction(schluessel);
|
||||
this.speicher[hashwert] = wert;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
public holen(schluessel : typ_schluessel) : schnittstelle_fehlermonade<typ_wert>
|
||||
{
|
||||
let hashwert : string = this.hashfunction(schluessel);
|
||||
if (hashwert in this.speicher)
|
||||
{
|
||||
let wert : typ_wert = this.speicher[hashwert];
|
||||
return (new klasse_schlicht<typ_wert>(wert));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (new klasse_nichts<typ_wert>());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
19
quelldatein/test.ts
Normal file
19
quelldatein/test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
module mod_vtm_test
|
||||
{
|
||||
|
||||
/**
|
||||
* @author kcf <vidofnir@folksprak.org>
|
||||
*/
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue