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)
|
||||
13
Boggle/02_test.txt
Normal file
13
Boggle/02_test.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
>>> myBoard = loadBoard('board.txt') # loads the specified file into a myBoard variable
|
||||
|
||||
>>> printBoard(myBoard)
|
||||
X G T S
|
||||
A M Z J
|
||||
E O C M
|
||||
U F E V
|
||||
|
||||
>>> possibleMoves((0,0), myBoard)
|
||||
{(0, 1), (1, 0), (1, 1)}
|
||||
|
||||
>>> possibleMoves((2,2), myBoard)
|
||||
{(1, 2), (3, 2), (1, 3), (3, 3), (3, 1), (2, 1), (2, 3), (1, 1)}
|
||||
4
Boggle/board.txt
Normal file
4
Boggle/board.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
J O P Y
|
||||
C M P V
|
||||
X F E G
|
||||
P G V U
|
||||
178691
Boggle/twl06.txt
Normal file
178691
Boggle/twl06.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue