資源簡介
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
評論
共有 條評論