Add the Boggle part 0 assignment.
This commit is contained in:
parent
a6873e3903
commit
7ff3958cda
4 changed files with 178748 additions and 0 deletions
40
Boggle/02_test.py
Normal file
40
Boggle/02_test.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue