import { QTransition } from "./qtransition" ; import { QAction } from "./qaction" ; export interface QStateData { [ key ] : any ; } export class QState { private transitions : Map < QAction , QTransition > ; private final : boolean ; private readonly id : number ; private static stateId : number = 0 ; constructor ( private readonly data , private reward ) { this . transitions = new Map < QAction , QTransition > ( ) ; this . final = false ; this . id = QState . stateId ++ ; } setTransition ( action , transition ) { if ( ! this . transitions . has ( action ) || this . transitions . get ( action ) === null ) return this . transitions . set ( action , transition ) . get ( action ) ; return null ; } takeAction ( action ) { return this . transitions . get ( action ) ; } get Data ( ) : QStateData { return this . data ; } get Reward ( ) : number { return this . reward ; } set Reward ( reward ) { this . reward = reward ; } get Transitions ( ) : QTransition [ ] { return Array . from ( this . transitions . values ( ) ) ; } setFinal ( ) { this . final = true ; return this ; } set Final ( final ) { this . final = final ; } get Final ( ) { return this . final ; } get Id ( ) : number { return this . id ; } }