/* * Verrückte Turing-Maschinen — A turing complete game * Copyright (C) 2016-2018 kcf * * 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 . */ namespace mod_vtm { export namespace mod_model { export namespace mod_token { /** * @author kcf */ export type type_token = { state : mod_state.type_state; tape : Array; spot : mod_spot.type_spot; } ; /** * @author kcf */ export function create ( tape : Array = [], spot : mod_spot.type_spot = mod_spot.null_() ) : type_token { return { "state": mod_state.running, "tape": tape, "spot": spot, }; } /** * @author kcf */ export function state_read ( token : type_token ) : mod_state.type_state { return token.state; } /** * @author kcf */ export function tape_read ( token : type_token ) : Array { return token.tape; } /** * @author kcf */ export function spot_read ( token : type_token ) : mod_spot.type_spot { return token.spot; } /** * @author kcf */ export function move ( token : type_token, direction : mod_direction.type_direction ) : void { let summand : mod_spot.type_spot = mod_spot.from_direction(direction); token.spot = mod_spot.add(token.spot, summand); } /** * @author kcf */ export function write ( token : type_token, symbol : mod_symbol.type_symbol ) : void { token.tape.push(symbol); } /** * @author kcf */ export function read ( token : type_token ) : lib_errormonade.type_errormonade { if (token.tape.length <= 0) { return (lib_errormonade.create_nothing()); } else { return (lib_errormonade.create_just(token.tape[0])); } } /** * @author kcf */ export function shift ( token : type_token ) : void { if (token.tape.length <= 0) { let message : string = "Band ist leer"; throw (new Error(message)); } else { token.tape.shift(); } } /** * @author kcf */ export function accept ( token : type_token ) : void { token.state = mod_state.accepted; } /** * @author kcf */ export function reject ( token : type_token ) : void { token.state = mod_state.rejected; } } } }