资源简介
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试题12套(包括选择题和
- pywin32_python3.6_64位
- 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获取硬件信息
评论
共有 条评论