def corrected_fens(self, fens: list[list[str]]) -> list[list[str]]: return Mappable(fens).replaced_with_disjoint( Mappable.indice_to_disjoint([ (self.last_color_indexed(fens, "w"), lambda i: fens[i] + [FEN.black_end()]), (self.last_color_indexed(fens, "b"), lambda i: fens[i] + [FEN.white_end()]), ]))
def corrected_results(self, results: list[list[float]]) -> list[list[float]]: return Mappable(results).replaced_with_disjoint( Mappable.indice_to_disjoint([ (self.conditional_indexed(lambda i: results[i][-1] == 1), lambda i: results[i][:-1] + [0.0, 1]), (self.conditional_indexed(lambda i: results[i][-1] == 0.5), lambda i: results[i] + [0.5]), ]))
def SAN_normalized(self) -> CorrectableTrace: return CorrectableTrace( self.fens, Mappable(Enumerable(self.fens).to_indice()).mapped( lambda i: self.sans[i][:-1] if len(self.fens[i]) != len( self.sans[i]) + 1 else self.sans[i]), self.results, )
def from_trace_with_color(cls, trace: Trace, color: str) -> NoneStepTrace: indice: Iterable[int] = IndexableTrace._make(trace).to_color_indice( color) return NoneStepTrace( Trace.from_FENs( Indexable(Mappable.concatenated(trace.fens)).indexed(indice)), indice)
def from_traces(cls, trace: Trace) -> Statistics: results: list[Score] = Mappable( trace.results).mapped(lambda x: Score.from_results(x)) return Statistics({ Score.white_win(): results.count(Score.white_win()), Score.black_win(): results.count(Score.black_win()), Score.draw(): results.count(Score.draw()), })
async def status(self, fens: list[str]) -> tuple[list[float], list[list[str]]]: if len(fens) == 0: return [], [] statuses, legal_moves = await RequestedFENStatus.from_url_with_FENs( self, fens) return Mappable(statuses).mapped( lambda x: MicroBoardStatus(x).to_result()), legal_moves
async def to_move(self, status: IStatus, movement: IMovement) -> tuple[Trace, Iterable[int]]: fens = Mappable.concatenated(self.fens) results, legal_moves = await status.status(fens) secondary_indice: list[int] = Enumerable( results).to_conditional_indice(lambda x: x == 0) next_fens, next_sans = await movement.movement( Indexable(fens).indexed(secondary_indice), legal_moves) return Trace.from_unwrapped(next_fens, next_sans, results), secondary_indice
+ Mappable.concatenated( Mappable( [ GeneratableParam( 0, Trace([[FEN.starting()]], [[]], []), Trace([[FEN.first()]], [[]], []), [[[1]], [[0.5]]] ), GeneratableParam( 2, Trace([[FEN.starting(), FEN.white_end()], [FEN.starting()]], [[SAN.first()], []], []), Trace([[FEN.first(), FEN.black_end()], [FEN.first()]], [[SAN.first()], []], []), [[[0, 1], [0]], [[0, 0.5], [0.5]]], ), GeneratableParam( 4, Trace( [[FEN.starting(), FEN.starting()], [FEN.starting(), FEN.white_end()]], [[SAN.first()], [SAN.first()]], [], ), Trace( [[FEN.first(), FEN.first()], [FEN.first(), FEN.black_end()]], [[SAN.first()], [SAN.first()]], [], ), [[[0, 0], [0, 1]], [[0, 0.5], [0, 0.5]]], ), GeneratableParam( 6, Trace( [[FEN.starting(), FEN.starting(), FEN.white_end()], [FEN.starting(), FEN.starting()]], [[SAN.first(), SAN.first()], [SAN.first()]], [], ), Trace( [[FEN.first(), FEN.first(), FEN.black_end()], [FEN.first(), FEN.first()]], [[SAN.first(), SAN.first()], [SAN.first()]], [], ), [[[0, 0, 1], [0, 0]], [[0, 0, 0.5], [0, 0.5]]], ), ] ).mapped(lambda x: x.generated()), ),
def from_unwrapped(cls, fens: list[str], sans: list[str], results: list[float]) -> Trace: return Trace( *map(lambda x: Mappable(x).wrapped(), [fens, sans, results]))
def from_FENs(cls, fens: list[str]) -> Trace: return Trace( Mappable(fens).wrapped(), Enumerable.filled([], len(fens)), Enumerable.filled([], len(fens)), )
async def to_last_update(self, status: IStatus) -> Trace: results, _ = await status.status(Mappable.concatenated(self.fens)) return Trace.from_unwrapped([], [], results)
def color_unioned(cls, length: int, white_trace: OneStepTrace, black_trace: OneStepTrace) -> Trace: return Trace(*map( lambda p: Mappable.disjoint_unioned([], length, p), zip(white_trace.to_disjoint(), black_trace.to_disjoint()), ))
def inner_concatenated(self, other: Trace) -> MappableTrace: return self.mapped_with( other, lambda z: Mappable.mapped_with_others(z, lambda x, y: x + y))
def inner_mapped(self, mapper: Callable) -> MappableTrace: return self.mapped(lambda y: Mappable(y).mapped(mapper))