vtm/source/model/tasks/task.ts

224 lines
5.4 KiB
TypeScript
Raw Normal View History

2017-11-09 14:06:35 +01:00
/*
* Verrückte Turing-Maschinen A turing complete game
2018-03-29 01:13:39 +02:00
* Copyright (C) 2016-2018 Christian Fraß <vidofnir@folksprak.org>
2017-11-09 14:06:35 +01:00
*
* 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 <https://www.gnu.org/licenses/>.
*/
2018-03-26 14:22:20 +02:00
module mod_vtm
2017-11-09 14:06:35 +01:00
{
2018-03-28 13:59:29 +02:00
export module mod_model
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
2018-03-28 13:59:29 +02:00
export module mod_task
2018-03-26 14:22:20 +02:00
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export type type_task = lib_call.type_complex<Object>;
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
var _liste : Array<type_task> = [];
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function id
(
2018-03-28 13:59:29 +02:00
task : type_task
2018-03-26 14:22:20 +02:00
)
: string
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
return (
2018-03-28 13:59:29 +02:00
lib_call.distinguish<string>
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
task,
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
"acceptortask": (data) => mod_acceptortask.id(data),
2018-03-29 01:13:39 +02:00
"transducertask": (data) => mod_transducertask.id(data),
2018-03-26 14:22:20 +02:00
}
)
);
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-29 01:13:39 +02:00
export function title
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
task : type_task
2018-03-26 14:22:20 +02:00
)
: string
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
return (
2018-03-28 13:59:29 +02:00
lib_call.distinguish<string>
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
task,
2018-03-26 14:22:20 +02:00
{
2018-03-29 01:13:39 +02:00
"acceptortask": (data) => mod_acceptortask.title(data),
"transducertask": (data) => mod_transducertask.title(data),
2018-03-26 14:22:20 +02:00
}
)
);
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function text
(
2018-03-28 13:59:29 +02:00
task : type_task
2018-03-26 14:22:20 +02:00
)
: string
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
return (
2018-03-28 13:59:29 +02:00
lib_call.distinguish<string>
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
task,
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
"acceptortask": (data) => mod_acceptortask.text(data),
2018-03-29 01:13:39 +02:00
"transducertask": (data) => mod_transducertask.text(data),
2018-03-26 14:22:20 +02:00
}
)
);
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function tests
(
2018-03-28 13:59:29 +02:00
task : type_task
2018-03-26 14:22:20 +02:00
)
2018-03-28 13:59:29 +02:00
: Array<mod_test.type_test>
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
return (
2018-03-28 13:59:29 +02:00
lib_call.distinguish<Array<mod_test.type_test>>
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
task,
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
"acceptortask": (data) => (
mod_acceptortask.tests(data)
.map(data_ => ({"kind": "acceptortest", "data": data_}))
2018-03-26 14:22:20 +02:00
),
2018-03-29 01:13:39 +02:00
"transducertask": (data) => (
mod_transducertask.tests(data)
.map(data_ => ({"kind": "transducertest", "data": data_}))
2018-03-26 14:22:20 +02:00
),
}
)
);
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function import_(task_raw : any) : type_task
2018-03-26 00:41:10 +02:00
{
2018-03-28 13:59:29 +02:00
switch (task_raw["kind"])
2018-03-26 14:22:20 +02:00
{
2018-03-28 13:59:29 +02:00
case "acceptor":
2018-03-26 14:22:20 +02:00
{
return {
2018-03-28 13:59:29 +02:00
"kind": "acceptortask",
"data": (
mod_acceptortask.create
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
task_raw["id"],
2018-03-29 01:13:39 +02:00
lib_translate.get(["tasks", task_raw["id"], "title"].join(".")),
lib_translate.get(["tasks", task_raw["id"], "text"].join(".")),
2018-03-28 13:59:29 +02:00
task_raw["parameter"]["tests"].map
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
test_raw => (
mod_acceptortest.create
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
test_raw["input"],
test_raw["accept"]
2018-03-26 14:22:20 +02:00
)
)
)
)
2018-03-26 00:41:10 +02:00
)
2018-03-26 14:22:20 +02:00
};
break;
}
2018-03-29 01:13:39 +02:00
case "transducer":
2018-03-26 14:22:20 +02:00
{
return {
2018-03-29 01:13:39 +02:00
"kind": "transducertask",
2018-03-28 13:59:29 +02:00
"data": (
2018-03-29 01:13:39 +02:00
mod_transducertask.create
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
task_raw["id"],
2018-03-29 01:13:39 +02:00
lib_translate.get(["tasks", task_raw["id"], "title"].join(".")),
lib_translate.get(["tasks", task_raw["id"], "text"].join(".")),
2018-03-28 13:59:29 +02:00
task_raw["parameter"]["tests"].map
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
test_raw => (
2018-03-29 01:13:39 +02:00
mod_transducertest.create
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
test_raw["input"],
test_raw["output"]
2018-03-26 14:22:20 +02:00
)
)
)
)
)
};
break;
}
default:
{
2018-03-28 13:59:29 +02:00
let message : string = "unbehandelte Art '" + task_raw["kind"] + "'";
throw (new Error(message));
2018-03-26 14:22:20 +02:00
break;
}
}
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function registrieren(task : type_task) : void
2018-03-26 00:41:10 +02:00
{
2018-03-28 13:59:29 +02:00
_liste.push(task);
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function get(index : int) : type_task
2018-03-26 00:41:10 +02:00
{
2018-03-26 14:22:20 +02:00
return _liste[index];
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
2018-03-26 00:41:10 +02:00
}
2018-03-26 14:22:20 +02:00
2017-11-09 14:06:35 +01:00
}
}