Exemplo n.º 1
0
def createPlayer2(autPlay2, autEnabled):
    '''createPlayer2(autPlay2, autEnabled) -> Automaton

Encode enabledness into the transducer autPlay2 for transitions of Player 2
using autEnabled defining enabledness.
'''
    #############################################################################
    def matchDelimChosenToEnDis(lhs, rhs):                                      #
        if lhs == SYMBOL_DELIM and rhs in {SYMBOL_ENABLED, SYMBOL_DISABLED}:    #
            return True                                                         #
        elif lhs == SYMBOL_CHOSEN and rhs == SYMBOL_ENABLED:                    #
            return True                                                         #
        else:                                                                   #
            return lhs == rhs                                                   #
    #############################################################################

    #############################################################################
    def matchDelimEnDis(lhs, rhs):                                              #
        if lhs == SYMBOL_DELIM and rhs in {SYMBOL_ENABLED, SYMBOL_DISABLED}:    #
            return True                                                         #
        else:                                                                   #
            return lhs == rhs                                                   #
    #############################################################################

    #####################################
    def pickChosenOrRight(lhs, rhs):    #
        if lhs == SYMBOL_CHOSEN:        #
            return lhs                  #
        else:                           #
            return rhs                  #
    #####################################

    result = Automaton.transdAutAutProd(
            autPlay2,
            autEnabled, matchDelimChosenToEnDis, pickChosenOrRight,
            autEnabled, matchDelimEnDis, lambda x, y: y
        )

    return result