40 lines
No EOL
1.5 KiB
Python
40 lines
No EOL
1.5 KiB
Python
def loadBoard(fileName):
|
|
with open(fileName) as board:
|
|
boardContents = board.read()
|
|
boardContents = boardContents.splitlines()
|
|
for boardIter in range(len(boardContents)):
|
|
boardContents[boardIter] = list(boardContents[boardIter].split())
|
|
return boardContents
|
|
|
|
def printBoard(boardInput):
|
|
for boardIter in range(len(boardInput)):
|
|
for boardIterTwo in range(len(boardInput[boardIter])):
|
|
print(boardInput[boardIter][boardIterTwo], end=" ")
|
|
print()
|
|
|
|
def possibleMoves(inputCoords, boardInput):
|
|
totalBoard = len(boardInput) * len(boardInput)
|
|
maxLen = len(boardInput)
|
|
# print("Length of boardInput: " + str(totalBoard))
|
|
# generate all the possibilities for moving, aka +- 1 x or y, +- 1 x and y.
|
|
moveList = []
|
|
for moveIter in range(len(inputCoords)):
|
|
# increase the X
|
|
moveList.append((inputCoords[0] + 1, inputCoords[1]))
|
|
# increase the y
|
|
moveList.append((inputCoords[0], inputCoords[1] + 1))
|
|
# increase the X and Y
|
|
moveList.append((inputCoords[0] + 1, inputCoords[1] + 1))
|
|
# decrease the X
|
|
moveList.append((inputCoords[0] - 1, inputCoords[1]))
|
|
# decrease the Y
|
|
moveList.append((inputCoords[0], inputCoords[1] - 1))
|
|
# decrease the X and Y
|
|
moveList.append((inputCoords[0] - 1, inputCoords[1] - 1))
|
|
print(moveList)
|
|
|
|
# put your code for loadBoard, printBoard, possibleMoves here.
|
|
myBoard = loadBoard("board.txt")
|
|
printBoard(myBoard)
|
|
possibleMoves((0,0),myBoard)
|
|
possibleMoves((2,2),myBoard) |