import sys

 def print_board():
for i in range(3):
for j in range(3):
print map[2 - i][j],
if j != 2:
print '|',
print '' def check_done():
for i in range(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 False turn = 'X'
done = False
map = [[' ', ' ', ' '],
[' ', ' ', ' '],
[' ', ' ', ' ']]
print "Please select position by typing in a number between 1 and 9, see below for which number that is which position..."
print "7|8|9"
print "4|5|6"
print "1|2|3"
print_board()
while done != True:
print turn + "'s turn"
try:
pos = input("Select: ")
if 1 <= pos <= 9:
X = (pos - 1) / 3
Y = (pos - 1) % 3
if map[X][Y] == ' ':
map[X][Y] = turn
print_board()
done = check_done()
if done == False:
if turn == 'X':
turn = 'O'
else:
turn = 'X'
except:
print "You need to add a numeric value"

最新文章

  1. Xcode工作区间xxxx.xcworkspace不包含xxxx.xcodeproj
  2. 临时更换hadoop-ugi
  3. Oracle基本sql操作
  4. UVALive 6577 Binary Tree 二叉树的LRU串
  5. kail ip配置
  6. 简述Seesion和Cookie
  7. TCP快速重传和快速恢复
  8. poptest老李谈数据结构中深度优先和广度优先
  9. codeforces Gym - 100633J Ceizenpok’s formula
  10. DD XOFT虚拟键盘鼠标
  11. Python3 解析XML 层序遍历二叉树
  12. 1-1Controller之Request
  13. Safari-IoS调试
  14. Linux环境编程之同步(四):Posix信号量
  15. Html生成控件
  16. [ACM]Codeforces Round #534 (Div. 2)
  17. 从零开始玩转JMX(四)——Apache Commons Modeler &amp; Dynamic MBean
  18. HDU3047 Zjnu Stadium 【带权并查集】
  19. 关于在ASP.NET MVC 中使用EF的Code First的方式来读取数据库时的Validation failed for one or more entities. See &#39;EntityValidationErrors&#39; property for more details.
  20. 【Tarjan算法】【DFS】Petrozavodsk Summer Training Camp 2016 Day 9: AtCoder Japanese Problems Selection, Thursday, September 1, 2016 Problem B. Point Pairs

热门文章

  1. linux学习笔记16--命令find
  2. push images to private repostory
  3. EasyUI左右布居
  4. 理解java的 多态
  5. EF提供的3中查询方式
  6. WPF实用知识点
  7. Python 个人常用汇总
  8. 使用JMAP dump及分析dump文件
  9. win7物理主机与虚拟XP系统互相ping不通解决方法
  10. 5秒后跳转到另一个页面的js代码