/* * 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_model { export module mod_task { /** * @author kcf */ export type type_task = lib_call.type_complex; /** * @author kcf */ var _liste : Array = []; /** * @author kcf */ export function id ( task : type_task ) : string { return ( lib_call.distinguish ( task, { "acceptortask": (data) => mod_acceptortask.id(data), "transductortask": (data) => mod_transductortask.id(data), } ) ); } /** * @author kcf */ export function titel ( task : type_task ) : string { return ( lib_call.distinguish ( task, { "acceptortask": (data) => mod_acceptortask.titel(data), "transductortask": (data) => mod_transductortask.titel(data), } ) ); } /** * @author kcf */ export function text ( task : type_task ) : string { return ( lib_call.distinguish ( task, { "acceptortask": (data) => mod_acceptortask.text(data), "transductortask": (data) => mod_transductortask.text(data), } ) ); } /** * @author kcf */ export function tests ( task : type_task ) : Array { return ( lib_call.distinguish> ( task, { "acceptortask": (data) => ( mod_acceptortask.tests(data) .map(data_ => ({"kind": "acceptortest", "data": data_})) ), "transductortask": (data) => ( mod_transductortask.tests(data) .map(data_ => ({"kind": "transductortest", "data": data_})) ), } ) ); } /** * @author kcf */ export function import_(task_raw : any) : type_task { switch (task_raw["kind"]) { case "acceptor": { return { "kind": "acceptortask", "data": ( mod_acceptortask.create ( task_raw["id"], task_raw["parameter"]["titel"], task_raw["parameter"]["text"], task_raw["parameter"]["tests"].map ( test_raw => ( mod_acceptortest.create ( test_raw["input"], test_raw["accept"] ) ) ) ) ) }; break; } case "transductor": { return { "kind": "transductortask", "data": ( mod_transductortask.create ( task_raw["id"], task_raw["parameter"]["titel"], task_raw["parameter"]["text"], task_raw["parameter"]["tests"].map ( test_raw => ( mod_transductortest.create ( test_raw["input"], test_raw["output"] ) ) ) ) ) }; break; } default: { let message : string = "unbehandelte Art '" + task_raw["kind"] + "'"; throw (new Error(message)); break; } } } /** * @author kcf */ export function registrieren(task : type_task) : void { _liste.push(task); } /** * @author kcf */ export function get(index : int) : type_task { return _liste[index]; } } } }