Finish the Boggle part 0 assignment.

This commit is contained in:
Charles Descamps 2025-01-17 20:25:58 -07:00
parent 7ff3958cda
commit b2c4634e30

View file

@ -13,25 +13,20 @@ def printBoard(boardInput):
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.
maxLen = len(boardInput) - 1
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))
# possible moves: (x+1, y), (x-1, y), (x, y+1), (x, y-1), (x+1, y+1), (x-1, y-1), (x+1, y-1), (x-1, y+1)
possibleMoves = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
for move in possibleMoves:
newX = inputCoords[0] + move[0]
newY = inputCoords[1] + move[1]
if (0 <= newX <= maxLen) and (0 <= newY <= maxLen):
moveList.append((newX, newY))
print(moveList)
# return moveList
# put your code for loadBoard, printBoard, possibleMoves here.
myBoard = loadBoard("board.txt")