Python井字游戏
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"
Python井字游戏的更多相关文章
- 初学python第二天
今天我将用python来编写一款小游戏,用这个来总结一下自己学过的一些基础语法.没错,它就是井字游戏.想想自己第一接触这种游戏,还是小学生呢
- (转)Python实例手册
原文地址:http://hi.baidu.com/quanzhou722/item/cf4471f8e23d3149932af2a7 实在是太好的资料了,不得不转 python实例手册 #encodi ...
- 12岁的少年教你用Python做小游戏
首页 资讯 文章 频道 资源 小组 相亲 登录 注册 首页 最新文章 经典回顾 开发 设计 IT技术 职场 业界 极客 创业 访谈 在国外 - 导航条 - 首页 最新文章 经典回顾 开发 ...
- Python编程快速上手——让繁琐工作自动化学习笔记
第一部分 基本语法 1.字符串不能直接和数字相加,要用str()转一下:但是可以和数字相乘,用于表示多个字符串复制:字符串不能和浮点数直接结合,字符串可以和字符串直接相加: 2.输入函数用input( ...
- 转载 python实例手册
python实例手册 #encoding:utf8# 设定编码-支持中文 0说明 手册制作: 雪松 更新日期: 2013-12-19 欢迎系统运维加入Q群: 198173206 # 加群请回答问题 请 ...
- 陈斌python语言基础与应用00
软件改变生活:购物.餐饮.商旅出行.资料查找... Everybody in this country should learn how to program a computer...because ...
- 【转载】python实例手册
今天写爬虫的时候遇到了问题,在网上不停地查找资料,居然碰到两篇好文章: 1.python实例手册 作者:没头脑的土豆 另一篇在这:shell实例手册 python实例手册 #encoding:ut ...
- Python实例手册
在电脑中突然发现一个这么好的资料,雪松大神制作,不敢独享,特与大家共享.连他的广告也一并复制了吧! python实例手册 #encoding:utf8 # 设定编码-支持中文 0说明 手册制作: 雪松 ...
- Python列表推导
一. 列表推导式 ord() 函数是 chr() 函数(对于8位的ASCII字符串)或 unichr() 函数(对于Unicode对象)的配对函数, 它以一个字符(长度为1的字符串)作为参数,返回 ...
随机推荐
- 使用Lua的扩展库LuaSocket用例
目录结构 LuaSocket 是 Lua 的网络模块库,它可以很方便地提供 TCP.UDP.DNS.FTP.HTTP.SMTP.MIME 等多种网络协议的访问操作. 它由两部分组成:一部分是用 C 写 ...
- UVA Problem B: Fire!
Problem B: Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and t ...
- hdu Distant Galaxy(遥远的银河)
Distant Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Ream的入门使用
一.介绍 Realm是一个不错的手机平台上的数据库,支持多种编程环境,如:Java.Object-C.React Native.Swift.Xamari等. Realm的官网:https://real ...
- 【Selenium】之谷歌、IE、火狐浏览器各个版本的浏览器驱动下载地址
地址:chromedriver官网下载地址: http://chromedriver.storage.googleapis.com/index.html(失效了) http://npm.taobao. ...
- 在HTML5中如何提高网站前端性能
1. 用web storage替换cookiesCookie最大的问题是每次都会跟在请求后面.在HTML5中,用sessionStorage和localStorage把用户数据直接在客户端,这样 ...
- 蓝桥杯 第三届C/C++预赛真题(7) 放棋子(水题)
今有 6 x 6 的棋盘格.其中某些格子已经预先放好了棋子.现在要再放上去一些,使得:每行每列都正好有3颗棋子.我们希望推算出所有可能的放法.下面的代码就实现了这个功能. 初始数组中,“1”表示放有棋 ...
- 【Raspberry pi】python ide-spyder
sudo apt-get install spyder 简单 明了
- VC++ 在Watch窗口显示GetLastError值以及详细信息
You can display the value GetLastError() will return by putting "@err" in your watch windo ...
- 上传图片到数据库,读取数据库中图片并显示(C#)
from:http://blog.csdn.net/bfcady/article/details/2622701 思路:建立流对象,将上传图片临时保存到byte数组中,再用SQL语句将其保存到数据库中 ...