/* * Verrückte Turing-Maschinen — A turing complete game * Copyright (C) 2016-2018 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_spot { /** * @author kcf */ export type type_spot = {u : int; v : int;}; /** * @author kcf */ export function hash(spot : type_spot) : string { return (spot.u.toFixed(0) + "_" + spot.v.toFixed(0)); } /** * @author kcf */ export function from_hash(hash : string) : type_spot { let teile : Array = hash.split("_"); return {"u": parseInt(teile[0]), "v": parseInt(teile[1])}; } /** * @author kcf */ export function null_() : type_spot { return {"u": 0, "v": 0}; } /** * @author kcf */ export function from_direction(direction : mod_direction.type_direction) : type_spot { switch (direction) { case 0: {return {"u": +1, "v": 0}; break;} case 1: {return {"u": +1, "v": +1}; break;} case 2: {return {"u": 0, "v": +1}; break;} case 3: {return {"u": -1, "v": 0}; break;} case 4: {return {"u": -1, "v": -1}; break;} case 5: {return {"u": 0, "v": -1}; break;} default: {throw (new Error("ungültige Richtung '" + String(direction) + "'")); break;} } } /** * @author kcf */ export function add(spot1 : type_spot, spot2 : type_spot) : type_spot { return {"u": (spot1.u + spot2.u), "v": (spot1.v + spot2.v)}; } /** * @author kcf */ export function export_(spot : type_spot) : string { return hash(spot); } /** * @author kcf */ export function import_(spot_ : string) : type_spot { return from_hash(spot_); } } } }