资源简介
没有用到GUI控件;python3.6版本;实现了五子棋双人对战,后面会尝试加入电脑对战的;希望你们可以喜欢
代码片段和文件信息
#!/usr/env/bin python
#-*- coding:utf-8 -*-
#author:涓涓清泉
#date:2018.4.11.20:34
#description: 最简单的双人对战五子棋游戏
#产生棋盘
row = 10
clo = 10
#显示棋盘
def displaymap(board):
#显示棋盘
for i in range(row+1):
print(“ “board[i])
#初始化
def initial():
board = [[“*“ for i in range(row+1)] for j in range(clo+1)]
for i in range(row+1):
board[i][0]=“%s“%(i);
for j in range(clo+1):
board[0][j] =“%s“%(j);
displaymap(board)
print(“——————————————————————————————Let‘s begin!——————————————————————————————“)
return board
#是否连成五子
def isFive(boardplayer):
#连成五子的情况有:横五,竖五,斜五
count = 1#记录连续子数
# 横五
for i in range(row+1):
if i != 0 :
for j in range(clo+1):
if j!=0:
if j + 4<=clo:
if board[i][j]==player:
count = 1
temp = j+1
while(temp!=j+5):
if board[i][temp]==player:
count += 1
if count == 5:
return True
temp += 1
if count == 5:
return True
# 竖五
for i in range(row + 1):
if i != 0:
for j in range(clo + 1):
if j != 0:
if i + 4 <= row:
if board[i][j] == player:
count = 1
temp = i + 1
while (temp != i + 5):
if board[temp][j] == player:
count += 1
if count >= 5:
return True
temp += 1
if count >= 5:
return True
# 斜上五:
for i in range(row + 1):
if i != 0:
for j in range(clo + 1):
if j != 0:
if i - 4 >= 1 and j + 4 <= clo:
if board[i][j] == player:
count = 1
temp1 = i - 1
temp2 = j + 1
while (temp1 != i - 5 or temp2 != j + 5):
if board[temp1][temp2] == player:
count += 1
if count >= 5:
return True
temp1 -= 1
temp2 += 1
if count >= 5:
return True
# 斜下五:
for i in range(row + 1):
if i != 0:
for j in range(clo + 1):
if j != 0:
if i + 4 <= row a
- 上一篇:模仿百度以图搜图功能/淘宝的拍立淘功能
- 下一篇:Python最小二乘法拟合直线
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论