189 lines
3.3 KiB
TypeScript
189 lines
3.3 KiB
TypeScript
/*
|
|
* Verrückte Turing-Maschinen — A turing complete game
|
|
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General export function figur_License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General export function figur_License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General export function figur_License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
module mod_vtm_aufbau
|
|
{
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export type typ_figur =
|
|
{
|
|
zustand : typ_zustand;
|
|
band : Array<typ_symbol>;
|
|
stelle : typ_stelle;
|
|
}
|
|
;
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_erstellen
|
|
(
|
|
band : Array<typ_symbol> = [],
|
|
stelle : typ_stelle = stelle_null()
|
|
)
|
|
: typ_figur
|
|
{
|
|
return {
|
|
"zustand": zustand_laufend,
|
|
"band": band,
|
|
"stelle": stelle,
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_zustand_lesen
|
|
(
|
|
figur : typ_figur
|
|
)
|
|
: typ_zustand
|
|
{
|
|
return figur.zustand;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_band_lesen
|
|
(
|
|
figur : typ_figur
|
|
)
|
|
: Array<typ_symbol>
|
|
{
|
|
return figur.band;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_stelle_lesen
|
|
(
|
|
figur : typ_figur
|
|
)
|
|
: typ_stelle
|
|
{
|
|
return figur.stelle;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_bewegen
|
|
(
|
|
figur : typ_figur,
|
|
richtung : typ_richtung
|
|
)
|
|
: void
|
|
{
|
|
let summand : typ_stelle = stelle_von_richtung(richtung);
|
|
figur.stelle = stelle_addieren(figur.stelle, summand);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_schreiben
|
|
(
|
|
figur : typ_figur,
|
|
symbol : typ_symbol
|
|
)
|
|
: void
|
|
{
|
|
figur.band.push(symbol);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_lesen
|
|
(
|
|
figur : typ_figur
|
|
)
|
|
: schnittstelle_fehlermonade<typ_symbol>
|
|
{
|
|
if (figur.band.length <= 0)
|
|
{
|
|
return (new klasse_nichts<typ_symbol>());
|
|
}
|
|
else
|
|
{
|
|
return (new klasse_schlicht<typ_symbol>(figur.band[0]));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_schieben
|
|
(
|
|
figur : typ_figur
|
|
)
|
|
: void
|
|
{
|
|
if (figur.band.length <= 0)
|
|
{
|
|
let meldung : string = "Band ist leer";
|
|
throw (new Error(meldung));
|
|
}
|
|
else
|
|
{
|
|
figur.band.shift();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_annehmen
|
|
(
|
|
figur : typ_figur
|
|
)
|
|
: void
|
|
{
|
|
figur.zustand = zustand_angenommen;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function figur_verwerfen
|
|
(
|
|
figur : typ_figur
|
|
)
|
|
: void
|
|
{
|
|
figur.zustand = zustand_abgelehnt;
|
|
}
|
|
|
|
}
|
|
|
|
|