def testLuosihu(): tileMgr = MTableTileFactory.getTableTileMgr(3, MPlayMode.LUOSIHU, MRunMode.CONSOLE) player = MPlayer('name', 0, 10000, 0) # [0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0] player.actionBegin([5, 6, 8, 18, 18, 18, 35, 18]) player.actionPeng(18, [18, 18, 18], 2) gangRuler = MGangRule() gangRuler.setTableTileMgr(tileMgr) tiles = player.copyTiles() result = gangRuler.hasGang(tiles, 5, MTableState.TABLE_STATE_NEXT) print result
def testHaerbin(): tileMgr = MTableTileFactory.getTableTileMgr(4, MPlayMode.HAERBIN, MRunMode.CONSOLE) player = MPlayer('name', 0, 10000, 0) #pengObj = MPlayerTilePeng(7, [7, 7, 21], 10) #player.pengTiles.append(pengObj) # [0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0] player.actionBegin([5, 6, 8, 18, 18, 18, 35, 18]) player.actionPeng(18, [18, 18, 18], 2) gangRuler = MGangRule() gangRuler.setTableTileMgr(tileMgr) tiles = player.copyTiles() result = gangRuler.hasGang(tiles, 5, MTableState.TABLE_STATE_NEXT, {"seatId": player.curSeatId}) print result
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
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 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)
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
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
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
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