tsp.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:travelling_sales_person_AI 作者: jana-uoft 项目源码 文件源码
def draw_canvas(state):
    '''Draw all the cities in the current state in a canvas. Indicate the start
       city with a description and the current city by the turtle pointer head
    '''
    turtle.clear()
    turtle.hideturtle()
    turtle.up()
    turtle.pencolor("blue")
    current_city = state.current_city
    for city in state.cities:
        x = city.position[0]
        y = city.position[1]
        turtle.goto(x, y)

        if city.is_start:
            turtle.write('{}, Start'.format(city.name), align="center", font=("Arial", 12, "bold"))
        elif city == current_city:
            turtle.write('{}, Current'.format(city.name), align="center", font=("Arial", 12, "bold"))            
        else:
            turtle.write('{}'.format(city.name), align="center", font=("Arial", 12, "bold"))

    turtle.goto(current_city.position[0], current_city.position[1])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号