资源简介
InventWithPython_resources 所有源代码
代码片段和文件信息
# Reversegam: a clone of Othello/Reversi
import random
import sys
WIDTH = 8 # Board is 8 spaces wide
HEIGHT = 8 # Board is 8 spaces tall
def drawBoard(board):
# This function prints the board that it was passed. Returns None.
print(‘ 12345678‘)
print(‘ +--------+‘)
for y in range(HEIGHT):
print(‘%s|‘ % (y+1) end=‘‘)
for x in range(WIDTH):
print(board[x][y] end=‘‘)
print(‘|%s‘ % (y+1))
print(‘ +--------+‘)
print(‘ 12345678‘)
def getNewBoard():
# Creates a brand-new blank board data structure.
board = []
for i in range(WIDTH):
board.append([‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘])
return board
def isValidMove(board tile xstart ystart):
# Returns False if the player‘s move on space xstart ystart is invalid.
# If it is a valid move returns a list of spaces that would become the player‘s if they made a move here.
if board[xstart][ystart] != ‘ ‘ or not isOnBoard(xstart ystart):
return False
if tile == ‘X‘:
otherTile = ‘O‘
else:
otherTile = ‘X‘
tilesToFlip = []
for xdirection ydirection in [[0 1] [1 1] [1 0] [1 -1] [0 -1] [-1 -1] [-1 0] [-1 1]]:
x y = xstart ystart
x += xdirection # First step in the x direction
y += ydirection # First step in the y direction
while isOnBoard(x y) and board[x][y] == otherTile:
# Keep moving in this x & y direction.
x += xdirection
y += ydirection
if isOnBoard(x y) and board[x][y] == tile:
# There are pieces to flip over. Go in the reverse direction until we reach the original space noting all the tiles along the way.
while True:
x -= xdirection
y -= ydirection
if x == xstart and y == ystart:
break
tilesToFlip.append([x y])
if len(tilesToFlip) == 0: # If no tiles were flipped this is not a valid move.
return False
return tilesToFlip
def isOnBoard(x y):
# Returns True if the coordinates are located on the board.
return x >= 0 and x <= WIDTH - 1 and y >= 0 and y <= HEIGHT - 1
def getBoardWithValidMoves(board tile):
# Returns a new board with periods marking the valid moves the player can make.
boardCopy = getBoardCopy(board)
for x y in getValidMoves(boardCopy tile):
boardCopy[x][y] = ‘.‘
return boardCopy
def getValidMoves(board tile):
# Returns a list of [xy] lists of valid moves for the given player on the given board.
validMoves = []
for x in range(WIDTH):
for y in range(HEIGHT):
if isValidMove(board tile x y) != False:
validMoves.append([x y])
return validMoves
def getScoreOfBoard(board):
# Determine the score by counting the tiles. Returns a
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9343 2016-12-08 13:42 AISim1.py
文件 9681 2016-11-22 12:02 AISim2.py
文件 11071 2016-11-22 12:02 AISim3.py
文件 2806 2016-11-22 12:02 animation.py
文件 7162 2016-11-22 12:02 background.mid
文件 378 2016-11-22 12:02 baddie.png
文件 2128 2016-11-22 12:02 bagels.py
文件 285 2016-11-22 12:02 buggy.py
文件 179 2016-11-22 12:02 cherry.png
文件 1504 2016-11-22 12:02 cipher.py
文件 676 2016-11-22 12:02 coinFlips.py
文件 3525 2016-11-22 12:02 collisionDetection.py
文件 6927 2016-11-22 12:02 dodger.py
文件 1145 2016-11-22 12:02 dragon.py
文件 258876 2016-11-22 12:02 gameover.wav
文件 868 2016-12-08 13:42 guess.py
文件 3956 2016-11-22 12:02 hangman.py
文件 4930 2016-11-22 12:02 hangman2.py
文件 161 2016-11-22 12:02 hello.py
文件 359 2016-11-22 12:02 jokes.py
文件 8522 2016-11-22 12:02 pickup.wav
文件 1815 2016-11-22 12:02 pla
文件 1880 2016-11-22 12:02 pygameHelloWorld.py
文件 9317 2016-11-22 12:02 reversegam.py
文件 4259 2016-11-22 12:02 spritesAndSounds.py
文件 6007 2016-11-22 12:02 tictactoe.py
相关资源
- 用python代码把背景颜色过滤掉
- PyHook3-1.6.1-cp36-cp36m-win32.whl
- L2正则化python实现案例()
- tensorflow手写数字识别python源码案例
- 批量excel转shp(面)python
- python ds evidence theory code
- Python串口调试助手
- 推荐系统物质扩散代码python
- 基于python的行人重识别代码
- 基于Python语言的SAD算法进行双目立体
- Python 聊天室 客户端和服务端 聊天
- python随机森林应用
- 肺实质分割python代码
- 基于python2.7的LeNet5源代码实现
- caffe_log绘制accuracy和loss曲线python3
- Python+OpenCv实现AI人脸识别身份认证系
- Tensorflow之CNN实现CIFAR-10图像的分类p
- python零基础入门视频 百度云资源
- Python和pyqt5中安装VTK实现三维数据可视
- Python3.x+Pyqt5实现界面左侧导航栏的抽
- Python3.x+Pyqt5制作GUI界面的案例
- Python-2.7.2-xcompile.patch
- PIL中文手册.pdf
- Python操作MySQL数据进行图片存取操作
- win 10 python 3.7 pygraphviz 安装包
- python实现算术编码
- 围棋截屏图片扫描工具
- [python] Kmeans文本聚类算法+PAC降维+Ma
- mysqldb64位
- abaqus激光增材仿真,生死单元添加p
评论
共有 条评论