From b2c4634e308034c56d511a89510bbc7bbaf41ab0 Mon Sep 17 00:00:00 2001 From: cdez Date: Fri, 17 Jan 2025 20:25:58 -0700 Subject: [PATCH] Finish the Boggle part 0 assignment. --- Boggle/02_test.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/Boggle/02_test.py b/Boggle/02_test.py index ff87070..2e718b3 100644 --- a/Boggle/02_test.py +++ b/Boggle/02_test.py @@ -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")