/* * Verrückte Turing-Maschinen — A turing complete game * Copyright (C) 2016 Christian Fraß * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public 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 Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ module mod_vtm { export module mod_aufbau { export module mod_figur { /** * @author kcf */ export type typ_figur = { zustand : mod_zustand.typ_zustand; band : Array; stelle : mod_stelle.typ_stelle; } ; /** * @author kcf */ export function erstellen ( band : Array = [], stelle : mod_stelle.typ_stelle = mod_stelle.null_() ) : typ_figur { return { "zustand": mod_zustand.laufend, "band": band, "stelle": stelle, }; } /** * @author kcf */ export function zustand_lesen ( figur : typ_figur ) : mod_zustand.typ_zustand { return figur.zustand; } /** * @author kcf */ export function band_lesen ( figur : typ_figur ) : Array { return figur.band; } /** * @author kcf */ export function stelle_lesen ( figur : typ_figur ) : mod_stelle.typ_stelle { return figur.stelle; } /** * @author kcf */ export function bewegen ( figur : typ_figur, richtung : mod_richtung.typ_richtung ) : void { let summand : mod_stelle.typ_stelle = mod_stelle.von_richtung(richtung); figur.stelle = mod_stelle.addieren(figur.stelle, summand); } /** * @author kcf */ export function schreiben ( figur : typ_figur, symbol : mod_symbol.typ_symbol ) : void { figur.band.push(symbol); } /** * @author kcf */ export function lesen ( figur : typ_figur ) : lib_fehlermonade.typ_fehlermonade { if (figur.band.length <= 0) { return (lib_fehlermonade.erstellen_nichts()); } else { return (lib_fehlermonade.erstellen_schlicht(figur.band[0])); } } /** * @author kcf */ export function 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 */ export function annehmen ( figur : typ_figur ) : void { figur.zustand = mod_zustand.angenommen; } /** * @author kcf */ export function verwerfen ( figur : typ_figur ) : void { figur.zustand = mod_zustand.abgelehnt; } } } }