vtm/quelldatein/aufbau/partie.ts

212 lines
5.6 KiB
TypeScript
Raw Normal View History

2017-11-09 14:06:35 +01:00
/*
* Verrückte Turing-Maschinen A turing complete game
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
*
* 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/>.
*/
module mod_vtm_aufbau
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type typ_modus = int;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export const modus_initial = 0;
export const modus_ungewiss = 1;
export const modus_fehlerhaft = 2;
export const modus_korrekt = 3;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export class klasse_partie
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
private welt : klasse_welt;
/**
* @author kcf <vidofnir@folksprak.org>
*/
private figur : schnittstelle_fehlermonade<klasse_figur>;
/**
* @author kcf <vidofnir@folksprak.org>
*/
private aufgabe : schnittstelle_aufgabe;
/**
* @author kcf <vidofnir@folksprak.org>
*/
private testindex : schnittstelle_fehlermonade<int>;
/**
* @author kcf <vidofnir@folksprak.org>
*/
private modus : typ_modus;
/**
* @author kcf <vidofnir@folksprak.org>
*/
public constructor
(
aufgabe : schnittstelle_aufgabe,
welt : klasse_welt = klasse_welt.blanko(),
figur : schnittstelle_fehlermonade<klasse_figur> = new klasse_nichts<klasse_figur>()
)
{
this.aufgabe = aufgabe;
this.welt = welt;
this.figur = figur;
this.testindex = (new klasse_nichts<int>());
this.modus = modus_initial;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public welt_lesen() : klasse_welt
{
return this.welt;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public figur_lesen() : schnittstelle_fehlermonade<klasse_figur>
{
return this.figur;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public modus_lesen() : typ_modus
{
return this.modus;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public fortfahren() : void
{
switch (this.modus)
{
case modus_initial:
{
this.modus = modus_ungewiss;
this.testindex = (new klasse_schlicht<int>(0));
break;
}
case modus_ungewiss:
{
if (! this.figur.ist_schlicht())
{
let tests : Array<schnittstelle_test> = this.aufgabe.tests();
let testindex : int = this.testindex.lesen();
let test : schnittstelle_test = tests[testindex];
let stelle : typ_stelle = this.welt.erzeuger_finden();
this.figur = (new klasse_schlicht<klasse_figur>(new klasse_figur(test.eingabe(), stelle)));
}
else
{
let figur : klasse_figur = this.figur.lesen();
let stelle : typ_stelle = figur.stelle_lesen();
let aktor_ : schnittstelle_fehlermonade<schnittstelle_aktor> = this.welt.feld_holen(stelle);
let aktor : schnittstelle_aktor = (aktor_.ist_schlicht() ? aktor_.lesen() : (new klasse_verwerfer()));
aktor.verwenden(figur);
let zustand : typ_zustand = figur.zustand_lesen();
if (zustand === zustand_laufend)
{
// nichts tun
}
else if ((zustand === zustand_angenommen) || (zustand === zustand_abgelehnt))
{
let angenommen : boolean = (zustand === zustand_angenommen);
let ausgabe : Array<typ_symbol> = figur.band_lesen();
this.figur = (new klasse_nichts<klasse_figur>());
let tests : Array<schnittstelle_test> = this.aufgabe.tests();
let testindex : int = this.testindex.lesen();
let test : schnittstelle_test = tests[testindex];
if (! test.pruefen(angenommen, ausgabe))
{
this.modus = modus_fehlerhaft;
}
else
{
testindex += 1;
if (testindex >= tests.length)
{
// auf Modus "korrekt" wechseln
this.testindex = (new klasse_nichts<int>());
this.modus = modus_korrekt;
}
else
{
// nächsten Test auswählen
this.testindex = (new klasse_schlicht<int>(testindex));
}
}
}
else
{
let meldung : string = "unbehandelter Zustand";
throw (new Error(meldung));
}
}
break;
}
case modus_fehlerhaft:
{
// nichts tun
break;
}
case modus_korrekt:
{
// nichts tun
break;
}
default:
{
let meldung : string = "unbehandelter Modus";
throw (new Error(meldung));
break;
}
}
}
}
}