def generateGame(rawGameMat, row, col, mine): zengguang = [] zengguang.append([0] * row * col + [mine]) gameList = MatUtil.mat2list(rawGameMat) for ri in range(len(gameList)): # 丑陋 # 每个非0num有一方程。这个num值,应该改成减完flag的。。。 if 1 <= gameList[ri] <= 8: equ = [0] * len(gameList) # 初始化 mines = gameList[ri] ind8 = MatUtil.circumIjIndexList(MatUtil.ijIndex(col, ri)[0], MatUtil.ijIndex(col, ri)[1], row, col) for ind in ind8: if gameList[MatUtil.realIndex(col, ind[0], ind[1])] == 12: # c equ[MatUtil.realIndex(col, ind[0], ind[1])] = 1 if gameList[MatUtil.realIndex(col, ind[0], ind[1])] == 15: # f mines -= 1 equ.append(mines) # 增广阵的b值 zengguang.append(equ) elif gameList[ri] == 12: # c zengguang[0][ri] = 1 return zengguang
def filt(rawGameMat, soluPool): """简直不能更重要了。返回sage筛选后的soluPool """ gamelist = MatUtil.mat2list(rawGameMat) for i in range(len(gamelist)): # print 'i=',i,'solupool len=',len(soluPool) if not gamelist[i] == 12: # 非sage留0 soluPool = filter(lambda x: x[i] == 0, soluPool) # print 'filt',i,'after, solupool len=',len(soluPool) return soluPool
def filt(rawGameMat, soluPool): '''简直不能更重要了。返回sage筛选后的soluPool ''' gamelist = MatUtil.mat2list(rawGameMat) for i in range(len(gamelist)): # print 'i=',i,'solupool len=',len(soluPool) if not gamelist[i] == 12: # 非sage留0 soluPool = filter(lambda x:x[i] == 0, soluPool) # print 'filt',i,'after, solupool len=',len(soluPool) return soluPool
# filt(readGame(), mat) def cmd(rawcmd): sp = rawcmd.split(" ") if len(sp) != 3: print "command var1 var2 not fit!" return # 0~8 for num, C(12) for sage, F(15) for flag, 为了: 都用1个空格分隔,而且至少原始文件排版整齐 if __name__ == "__main__": mines, row, col, rawGameMat = readGame() MatUtil.printMatrix(rawGameMat, "rawGameMat") print "mines = ", mines gameMat = generateGame(rawGameMat, row, col, mines) MatUtil.printMatrix(gameMat, "gameMat") # 这个全产生再筛选太蠢。。。可以砍掉好多大树杈 soluPool = dicOrder(row * col, [0, 1]) # num与flag者,尽筛成0 ###################flag不应0...而且flag表现在()上还是在本身=1上?? soluPool = filt(rawGameMat, soluPool) # 正确性 right = 0 newSoluPool = [] for solu in soluPool:
sp=rawcmd.split(' ') if len(sp)!=3: print 'command var1 var2 not fit!' return # 0~8 for num, C(12) for sage, F(15) for flag, 为了: 都用1个空格分隔,而且至少原始文件排版整齐 if __name__ == '__main__': mines, row, col, rawGameMat = readGame() MatUtil.printMatrix(rawGameMat, 'rawGameMat') print 'mines = ', mines gameMat = generateGame(rawGameMat, row, col, mines) MatUtil.printMatrix(gameMat, 'gameMat') # 这个全产生再筛选太蠢。。。可以砍掉好多大树杈 soluPool = dicOrder(row * col, [0, 1]) # num与flag者,尽筛成0 ###################flag不应0...而且flag表现在()上还是在本身=1上?? soluPool = filt(rawGameMat, soluPool) # 正确性 right = 0 newSoluPool = []