python tic-tac 改进输出版本,pythontic-tac,def print_bo
文章由Byrx.net分享于2019-03-23 09:03:23
python tic-tac 改进输出版本,pythontic-tac,def print_bo
def print_board(): print print print '*'*50 for i in range(0,3): for j in range(0,3): if map[i][j] != " ": print map[i][j], else: print "%d" %(i*3+j+1), if j != 2: print "|", print "" print '*'*50def check_done(): for i in range(0,3): if map[i][0] == map[i][1] == map[i][2] != " " \\ or map[0][i] == map[1][i] == map[2][i] != " ": print turn, "won!!!" return True if map[0][0] == map[1][1] == map[2][2] != " " \\ or map[0][2] == map[1][1] == map[2][0] != " ": print turn, "won!!!" return True if " " not in map[0] and " " not in map[1] and " " not in map[2]: print "Draw" return True return Falsedef help(): print "*" *76 print "*" *76 print "** Welcome to the tic-tac world,it's modified by me(hunter xue). **" print "** the origin source is here: **" print "** \\"http://jiabin.tk/2013/07/22/tic-tac-toe-in-python/\\" **" print "** Hope you enjoy this simple game **" print "*" *76 print "*" *76turn = "X"map = [[" "," "," "], [" "," "," "], [" "," "," "]]done = Falsehelp()while done != True: print_board() print print turn, "'s turn=>", moved = False while moved != True: try: pos = input("Select: ") if pos <=9 and pos >=1: Y = pos/3 X = pos%3 if X != 0: X -=1 else: X = 2 Y -=1 if map[Y][X] == " ": map[Y][X] = turn moved = True done = check_done() if done == False: if turn == "X": turn = "O" else: turn = "X" else: print "The position is occupied by ",turn else: print "You need to add a numeric value between 1-9" except: print "You need to add a numeric value between 1-9"#该片段来自于http://byrx.net
相关内容
- 产生a-z的字符串,产生a-z字符串,# method 1pr
- 初学爬虫-抓网页新闻——代码容易理解,初学爬虫,抓
- 我也来个下美女图片的脚本,也来美女图片脚本,#!/us
- 查询百度中关键词排名,百度关键词排名,就是一个简单
- 使用Python生成Excel格式的图片,,之前曾看到过 一篇报道
- 实现tee命令,tee命令,# -*- coding
- 初学者实现计算器功能,初学者实现计算器,没有使用任
- 国外赌场热门游戏Craps,国外热门游戏craps,运行方法:
- python生成sitemap.xml,pythonsitemap.xml,# _*_ coding
- django 微博链接登陆,django微博链接,看了网上的认证。
评论关闭