def testWinsProcessor():
    """
    测试多个和牌的状态更新
    状态:
        0号位出牌,1号位2号位两个人可和牌,不能一炮多响
        
    操作:
        2号位先和牌
        1号位再和牌
        
    预期:
        2号位胡牌结果先不确认
        1号位胡牌的和牌结果确认
    """
    dp = MDropCardProcessor(4, MPlayMode.JIXI)
    player3 = MPlayer('3', 1, 10003, 0)
    player3.setSeatId(3)
    player2 = MPlayer('2', 1, 10002, 0)
    player2.setSeatId(2)
    player1 = MPlayer('1', 1, 10001, 0)
    player1.setSeatId(1)
    player0 = MPlayer('0', 1, 10000, 0)
    player0.setSeatId(0)
    
    dp.players.append(player0)
    dp.players.append(player1)
    dp.players.append(player2)
    dp.players.append(player3)
    dp.setCurSeatId(0)
    
    exInfoWin1 = MTableStateExtendInfo()
    winInfo1 = {}
    winInfo1['tile'] = 9
    exInfoWin1.appendInfo(MTableState.TABLE_STATE_HU, winInfo1)
    dp.initProcessor(19, 1, MTableState.TABLE_STATE_HU, exInfoWin1, 9)
    
    exInfoWin2 = MTableStateExtendInfo()
    winInfo2 = {}
    winInfo2['tile'] = 9
    exInfoWin2.appendInfo(MTableState.TABLE_STATE_HU, winInfo2)
    dp.initProcessor(19, 2, MTableState.TABLE_STATE_HU, exInfoWin2, 9)
    
    result2 = dp.updateProcessor(19, 2, MTableState.TABLE_STATE_HU, 9, None)
    print 'result2:', result2
    print dp.processors

    result1 = dp.updateProcessor(19, 1, MTableState.TABLE_STATE_HU, 9, None)  
    print 'result1:', result1
    print dp.processors
Beispiel #2
0
def testLouhuProcessor():
    """
    测试漏和牌的状态更新
    状态:
        0号位出牌,1号位漏胡2号位和牌
        
    操作:
        1号位漏和牌
        2号位和牌
        
    预期:
        1号位漏胡牌结果先不确认
        2号位胡牌的和牌结果确认
    """
    dp = MDropCardProcessor(4, MPlayMode.LUOSIHU)
    player3 = MPlayer('3', 1, 10003, 0)
    player3.setSeatId(3)
    player2 = MPlayer('2', 1, 10002, 0)
    player2.setSeatId(2)
    player1 = MPlayer('1', 1, 10001, 0)
    player1.setSeatId(1)
    player0 = MPlayer('0', 1, 10000, 0)
    player0.setSeatId(0)

    dp.players.append(player0)
    dp.players.append(player1)
    dp.players.append(player2)
    dp.players.append(player3)
    dp.setCurSeatId(0)

    exInfoWin1 = MTableStateExtendInfo()
    winInfo1 = {}
    exInfoWin1.appendInfo(MTableState.TABLE_STATE_PASS_HU, winInfo1)
    dp.initProcessor(19, 1, MTableState.TABLE_STATE_PASS_HU, exInfoWin1, 9)

    exInfoWin2 = MTableStateExtendInfo()
    winInfo2 = {}
    winInfo2['tile'] = 9
    exInfoWin2.appendInfo(MTableState.TABLE_STATE_HU, winInfo2)
    dp.initProcessor(19, 2, MTableState.TABLE_STATE_HU, exInfoWin2, 9)

    result1 = dp.updateProcessor(19, 1, MTableState.TABLE_STATE_PASS_HU, 9,
                                 None)
    print 'result1:', result1
    print dp.processors

    result2 = dp.updateProcessor(19, 2, MTableState.TABLE_STATE_HU, 9, None)
    print 'result2:', result2
    print dp.processors
Beispiel #3
0
def testHighPriority():
    dp = MDropCardProcessor(4)
    exInfo = MTableStateExtendInfo()
    #exInfo.setExtend( {'peng': [[18, 18, 18]], 'pengTing': [{'tile': 18, 'ting': [{'winNo       des': [{'winTile': 17, 'pattern': [[17, 18, 19], [11, 11]], 'winTileCount': 3}], 'dropTile': 28}], 'pattern': [18, 18, 18]}], 'gang': [{'tile': 18, 'pattern': [18, 18, 18, 18], 'style': 1}], 'gangTing': [{'ti       le': 18, 'ting': [{'winNodes': [{'winTile': 26, 'pattern': [[26, 27, 28], [11, 11]], 'winTileCount': 2}, {'winTile': 29, 'pattern': [[27, 28, 29], [11, 11]], 'winTileCount': 2}], 'dropTile': 19}], 'style': 1,        'pattern': [18, 18, 18, 18]}]})
    exInfo.setExtend({
        'peng': [[18, 18, 18]],
        'pengTing': [{
            'tile':
            18,
            'ting': [{
                'winNodes': [{
                    'winTile': 17,
                    'pattern': [[17, 18, 19], [11, 11]],
                    'winTileCount': 3
                }],
                'dropTile':
                28
            }],
            'pattern': [18, 18, 18]
        }]
    })
    dp.initProcessor(10, 0, 28, exInfo, 9)
    dp.getMyselfHighPriority(0, -1)
Beispiel #4
0
def testNormalUpdateProcessor():
    """
    测试吃碰杠的状态更新
    状态:
        同时可吃可碰
    操作:
        吃先同意
        碰后取消
    
    预期结果:
        自动响应吃
    
    """
    dp = MDropCardProcessor(4)
    player3 = MPlayer('3', 1, 10003, 0)
    player3.setSeatId(3)
    player2 = MPlayer('2', 1, 10002, 0)
    player2.setSeatId(2)
    player1 = MPlayer('1', 1, 10001, 0)
    player1.setSeatId(1)
    player0 = MPlayer('0', 1, 10000, 0)
    player0.setSeatId(0)

    dp.players.append(player0)
    dp.players.append(player1)
    dp.players.append(player2)
    dp.players.append(player3)
    dp.setCurSeatId(1)

    exInfoChi = MTableStateExtendInfo()
    exInfoChi.setExtend({"chi": [[1, 2, 3]]})
    dp.initProcessor(19, 2, MTableState.TABLE_STATE_CHI, exInfoChi, 9)

    exInfoPeng = MTableStateExtendInfo()
    exInfoPeng.setExtend({"peng": [[3, 3, 3]]})
    dp.initProcessor(19, 3, MTableState.TABLE_STATE_PENG, exInfoPeng, 9)

    dp.updateProcessor(19, 2, MTableState.TABLE_STATE_CHI, 3, [1, 2, 3])
    print dp.processors
    dp.resetSeatId(3)

    print dp.hasAutoDecideAction(1, -1)
def testDuoWinsProcessor():
    """
    测试一炮多响时,多个和牌的状态更新
    状态:
        0号位出牌,1号位2号位两个人可和牌,能一炮多响

    操作:
        2号位先和牌
        1号位再和牌

    预期:
        2号位胡牌结果先不确认
        1号位胡牌的和牌结果确认
        1/2号位同时胡牌
    """
    from majiang2.player.player import MPlayer
    from majiang2.table_tile.table_tile_factory import MTableTileFactory
    from majiang2.ai.play_mode import MPlayMode
    from majiang2.table.run_mode import MRunMode

    dp = MQiangGangHuProcessor(4)
    player3 = MPlayer('3', 1, 10003, 0)
    player3.setSeatId(3)
    player2 = MPlayer('2', 1, 10002, 0)
    player2.setSeatId(2)
    player1 = MPlayer('1', 1, 10001, 0)
    player1.setSeatId(1)
    player0 = MPlayer('0', 1, 10000, 0)
    player0.setSeatId(0)

    dp.players.append(player0)
    dp.players.append(player1)
    dp.players.append(player2)
    dp.players.append(player3)

    tableTileMgr = MTableTileFactory.getTableTileMgr(4, MPlayMode.PINGDU258,
                                                     MRunMode.CONSOLE)
    dp.setTableTileMgr(tableTileMgr)

    exInfoWin1 = MTableStateExtendInfo()
    winInfo1 = {'tile': 9, 'qiangGang': 1, 'gangSeatId': 0}
    exInfoWin1.appendInfo(MTableState.TABLE_STATE_QIANGGANG, winInfo1)
    dp.initProcessor(19, 1, MTableState.TABLE_STATE_QIANGGANG, exInfoWin1, 9)

    exInfoWin2 = MTableStateExtendInfo()
    winInfo2 = {'tile': 9, 'qiangGang': 1, 'gangSeatId': 0}
    exInfoWin2.appendInfo(MTableState.TABLE_STATE_QIANGGANG, winInfo2)
    dp.initProcessor(19, 2, MTableState.TABLE_STATE_QIANGGANG, exInfoWin2, 9)

    result2 = dp.updateProcessor(19, 2, MTableState.TABLE_STATE_QIANGGANG, 9,
                                 None)
    print 'result2:', result2
    print dp.processors

    autoSeatId = dp.hasAutoDecideAction(0, -1)
    print 'autoSeatId2:', autoSeatId

    result1 = dp.updateProcessor(19, 1, MTableState.TABLE_STATE_QIANGGANG, 9,
                                 None)
    print 'result1:', result1

    autoSeatId = dp.hasAutoDecideAction(0, -1)
    print 'autoSeatId1:', autoSeatId

    wins = [1, 2]
    result3 = dp.updateDuoHu(19, wins, MTableState.TABLE_STATE_QIANGGANG)
    print 'result3:', result3

    print dp.processors
Beispiel #6
0
def testChiTingWinsProcessor():
    """
    测试多个和牌的状态更新
    状态:
        0号位出牌,1号位2号位两个人可和牌,不能一炮多响
        
    操作:
        2号位先和牌
        1号位再和牌
        
    预期:
        2号位胡牌结果先不确认
        1号位胡牌的和牌结果确认
    """
    dp = MDropCardProcessor(4)
    player3 = MPlayer('3', 1, 10003, 0)
    player3.setSeatId(3)
    player2 = MPlayer('2', 1, 10002, 0)
    player2.setSeatId(2)
    player1 = MPlayer('1', 1, 10001, 0)
    player1.setSeatId(1)
    player0 = MPlayer('0', 1, 10000, 0)
    player0.setSeatId(0)

    dp.players.append(player0)
    dp.players.append(player1)
    dp.players.append(player2)
    dp.players.append(player3)
    dp.setCurSeatId(1)

    exInfoWin0 = MTableStateExtendInfo()
    exInfoWin0.appendInfo(
        MTableState.TABLE_STATE_CHI & MTableState.TABLE_STATE_GRABTING, {
            "tile": 14,
            "pattern": [12, 13, 14],
            "ting": {}
        })
    dp.initProcessor(
        19, 0, MTableState.TABLE_STATE_CHI & MTableState.TABLE_STATE_GRABTING,
        exInfoWin0, 9)

    exInfoWin2 = MTableStateExtendInfo()
    exInfoWin2.appendInfo(MTableState.TABLE_STATE_HU, {"tile": 14})
    dp.initProcessor(19, 2, MTableState.TABLE_STATE_HU, exInfoWin2, 9)

    exInfoChi3 = MTableStateExtendInfo()
    exInfoChi3.appendInfo(MTableState.TABLE_STATE_CHI, {
        "tile": 14,
        " pattern": [12, 13, 14]
    })
    dp.initProcessor(19, 3, MTableState.TABLE_STATE_CHI, exInfoChi3, 9)

    result3 = dp.updateProcessor(19, 2, MTableState.TABLE_STATE_CHI, 9,
                                 [12, 13, 14])
    print 'result3:', result3
    print dp.processors

    result0 = dp.updateProcessor(
        19, 0, MTableState.TABLE_STATE_CHI & MTableState.TABLE_STATE_GRABTING,
        9, [12, 13, 14])
    print 'result0:', result0

    dp.resetSeatId(2)
    print dp.processors

    print dp.hasAutoDecideAction(1, -1)
Beispiel #7
0
def testDuoWinsProcessor():
    """
    测试一炮多响时,多个和牌的状态更新
    状态:
        0号位出牌,1号位2号位两个人可和牌,能一炮多响

    操作:
        2号位先和牌
        1号位再和牌

    预期:
        2号位胡牌结果先不确认
        1号位胡牌的和牌结果确认
        1/2号位同时胡牌
    """
    dp = MDropCardProcessor(4, MPlayMode.LUOSIHU)
    player3 = MPlayer('3', 1, 10003, 0)
    player3.setSeatId(3)
    player2 = MPlayer('2', 1, 10002, 0)
    player2.setSeatId(2)
    player1 = MPlayer('1', 1, 10001, 0)
    player1.setSeatId(1)
    player0 = MPlayer('0', 1, 10000, 0)
    player0.setSeatId(0)

    dp.players.append(player0)
    dp.players.append(player1)
    dp.players.append(player2)
    dp.players.append(player3)
    dp.setCurSeatId(0)

    tableTileMgr = MTableTileFactory.getTableTileMgr(4, MPlayMode.LUOSIHU,
                                                     MRunMode.CONSOLE)
    dp.setTableTileMgr(tableTileMgr)

    exInfoWin1 = MTableStateExtendInfo()
    winInfo1 = {}
    winInfo1['tile'] = 9
    exInfoWin1.appendInfo(MTableState.TABLE_STATE_HU, winInfo1)
    dp.initProcessor(19, 1, MTableState.TABLE_STATE_HU, exInfoWin1, 9)

    exInfoWin2 = MTableStateExtendInfo()
    winInfo2 = {}
    winInfo2['tile'] = 9
    exInfoWin2.appendInfo(MTableState.TABLE_STATE_HU, winInfo2)
    dp.initProcessor(19, 2, MTableState.TABLE_STATE_HU, exInfoWin2, 9)

    result2 = dp.updateProcessor(19, 2, MTableState.TABLE_STATE_HU, 9, None)
    print 'result2:', result2
    print dp.processors

    autoSeatId = dp.hasAutoDecideAction(0, -1)
    print 'autoSeatId2:', autoSeatId

    result1 = dp.updateProcessor(19, 1, MTableState.TABLE_STATE_HU, 9, None)
    print 'result1:', result1

    autoSeatId = dp.hasAutoDecideAction(0, -1)
    print 'autoSeatId1:', autoSeatId

    wins = [1, 2]
    result3 = dp.updateDuoHu(19, wins, MTableState.TABLE_STATE_HU)
    print 'result3:', result3

    print dp.processors
Beispiel #8
0
        if actionSeatId in seatIds:
            huCurIndex = seatIds.index(actionSeatId)
            for seatindex in range(huCurIndex):
                realSeat = seatIds[seatindex]
                if self.__processors[realSeat][
                        'state'] == MTableState.TABLE_STATE_QIANG_EXMAO_HU:
                    return False
            return True

        return False


if __name__ == "__main__":
    dp = MQiangExmaoHuProcessor(4)
    exInfo = MTableStateExtendInfo()
    #exInfo.setExtend( {'peng': [[18, 18, 18]], 'pengTing': [{'tile': 18, 'ting': [{'winNo       des': [{'winTile': 17, 'pattern': [[17, 18, 19], [11, 11]], 'winTileCount': 3}], 'dropTile': 28}], 'pattern': [18, 18, 18]}], 'gang': [{'tile': 18, 'pattern': [18, 18, 18, 18], 'style': 1}], 'gangTing': [{'ti       le': 18, 'ting': [{'winNodes': [{'winTile': 26, 'pattern': [[26, 27, 28], [11, 11]], 'winTileCount': 2}, {'winTile': 29, 'pattern': [[27, 28, 29], [11, 11]], 'winTileCount': 2}], 'dropTile': 19}], 'style': 1,        'pattern': [18, 18, 18, 18]}]})
    exInfo.setExtend({
        'peng': [[18, 18, 18]],
        'pengTing': [{
            'tile':
            18,
            'ting': [{
                'winNodes': [{
                    'winTile': 17,
                    'pattern': [[17, 18, 19], [11, 11]],
                    'winTileCount': 3
                }],
                'dropTile':
                28
            }],
            self.setMaoState(0)
    
    def updateProcessor(self, actionID, seatId, state, tile, pattern = None):
        """
        用户做出了选择,state为0,表示放弃
        用户的选择集合明确
        """
        if actionID != self.actionID:
            # 不是本轮处理的牌
            ftlog.debug('not this round actionId...' )
            return False
        
        if seatId != self.exmaoSeatId:
            ftlog.debug('Not this round qiangPeng/Gang user... right seatId:', self.exmaoSeatId
                        , ' wrong seatId:', seatId)
            return False
        
        if not (state & self.maoState):
            ftlog.debug('Right user, but wrong action. state:', self.maoState
                        , ' now action:', state)
            return False
        
        self.setMaoState(0)
        return True
    
if __name__ == "__main__":
    dp = MQiangExmaoPengProcessor(4)
    exInfo = MTableStateExtendInfo()
    #exInfo.setExtend( {'peng': [[18, 18, 18]], 'pengTing': [{'tile': 18, 'ting': [{'winNo       des': [{'winTile': 17, 'pattern': [[17, 18, 19], [11, 11]], 'winTileCount': 3}], 'dropTile': 28}], 'pattern': [18, 18, 18]}], 'gang': [{'tile': 18, 'pattern': [18, 18, 18, 18], 'style': 1}], 'gangTing': [{'ti       le': 18, 'ting': [{'winNodes': [{'winTile': 26, 'pattern': [[26, 27, 28], [11, 11]], 'winTileCount': 2}, {'winTile': 29, 'pattern': [[27, 28, 29], [11, 11]], 'winTileCount': 2}], 'dropTile': 19}], 'style': 1,        'pattern': [18, 18, 18, 18]}]})
    exInfo.setExtend( {'peng': [[18, 18, 18]], 'pengTing': [{'tile': 18, 'ting': [{'winNodes': [{'winTile': 17, 'pattern': [[17, 18, 19], [11, 11]], 'winTileCount': 3}], 'dropTile': 28}], 'pattern': [18, 18, 18]}]})
    dp.initProcessor(10, 0, 28, exInfo, 9)
def testDuoWinsProcessor():
    """
    测试一炮多响时,多个和牌的状态更新
    状态:
        0号位出牌,1号位2号位两个人可和牌,能一炮多响

    操作:
        2号位先和牌
        1号位再和牌

    预期:
        2号位胡牌结果先不确认
        1号位胡牌的和牌结果确认
        1/2号位同时胡牌
    """
    from majiang2.player.player import MPlayer
    from majiang2.table_tile.table_tile_factory import MTableTileFactory
    from majiang2.ai.play_mode import MPlayMode
    from majiang2.table.run_mode import MRunMode

    dp = MQiangGangHuProcessor(4)
    player3 = MPlayer('3', 1, 10003, 0)
    player3.setSeatId(3)
    player2 = MPlayer('2', 1, 10002, 0)
    player2.setSeatId(2)
    player1 = MPlayer('1', 1, 10001, 0)
    player1.setSeatId(1)
    player0 = MPlayer('0', 1, 10000, 0)
    player0.setSeatId(0)

    dp.players.append(player0)
    dp.players.append(player1)
    dp.players.append(player2)
    dp.players.append(player3)

    tableTileMgr = MTableTileFactory.getTableTileMgr(4, MPlayMode.LUOSIHU, MRunMode.CONSOLE)
    dp.setTableTileMgr(tableTileMgr)

    exInfoWin1 = MTableStateExtendInfo()
    winInfo1 = {'tile': 9, 'qiangGang': 1, 'gangSeatId': 0}
    exInfoWin1.appendInfo(MTableState.TABLE_STATE_QIANGGANG, winInfo1)
    dp.initProcessor(19, 1, MTableState.TABLE_STATE_QIANGGANG, exInfoWin1, 9)

    exInfoWin2 = MTableStateExtendInfo()
    winInfo2 = {'tile': 9, 'qiangGang': 1, 'gangSeatId': 0}
    exInfoWin2.appendInfo(MTableState.TABLE_STATE_QIANGGANG, winInfo2)
    dp.initProcessor(19, 2, MTableState.TABLE_STATE_QIANGGANG, exInfoWin2, 9)

    result2 = dp.updateProcessor(19, 2, MTableState.TABLE_STATE_QIANGGANG, 9, None)
    print 'result2:', result2
    print dp.processors

    autoSeatId = dp.hasAutoDecideAction(0, -1)
    print 'autoSeatId2:', autoSeatId

    result1 = dp.updateProcessor(19, 1, MTableState.TABLE_STATE_QIANGGANG, 9, None)
    print 'result1:', result1

    autoSeatId = dp.hasAutoDecideAction(0, -1)
    print 'autoSeatId1:', autoSeatId

    wins = [1, 2]
    result3 = dp.updateDuoHu(19, wins, MTableState.TABLE_STATE_QIANGGANG)
    print 'result3:', result3

    print dp.processors