码迷,mamicode.com
首页 > 编程语言 > 详细

python 八皇后

时间:2015-07-19 00:09:17      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:

def eight_queen(): 
    def if_inline(point1, point2):
        if(point1[0] == point2[0] or\
           abs(point1[0] - point2[0]) == abs(point1[1] - point2[1])):
            return True
        return False
    
    def judge_point(point, point_list):
        for item in point_list:
            if(if_inline(point, item)):
                return False
        else:
            return True
        
    def sub_func(height, width, cloumn, point_list):
        for i in range(height):
            point = (i, cloumn)
            if(judge_point(point, point_list)):
                point_list_new = copy.deepcopy(point_list)  
                point_list_new.append(point)
                if(cloumn < height-1):
                    sub_func(height, width, cloumn+1, point_list_new)
                else:
                    print point_list_new
        return  

 

python 八皇后

标签:

原文地址:http://www.cnblogs.com/wingor/p/4657892.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!