Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/CogitoNTNU/TetrisAI into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
JonBergland committed Apr 8, 2024
2 parents 3ebf6cd + 40f1bf1 commit 7552f72
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/game/TetrisGameManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, board):
self.board.setGameOver(False)

self.switcher = {
Key.down: lambda: self.movePiece("DOWN"),
Key.f1: lambda: self.movePiece("DOWN"),
Key.left: lambda: self.movePiece("LEFT"),
Key.right: lambda: self.movePiece("RIGHT"),
Key.space: lambda: "HardDrop",
Expand Down Expand Up @@ -161,11 +161,11 @@ def placePiece(self, direction):
def checkTimer(self):
checkTime = self.currentTime + 1000/self.updateTimer
newTime = int(round(t.time() * 1000))
if (checkTime < newTime):
self.currentTime = newTime
self.movePiece("DOWN")
print("Timer checked")
self.board.printBoard()
# if (checkTime < newTime):
# self.currentTime = newTime
# self.movePiece("DOWN")
# print("Timer checked")
# self.board.printBoard()


return True
Expand Down
2 changes: 1 addition & 1 deletion src/game/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def moveDown(self, undo: bool = False):
if not undo:
self.y += 1
else:
self.moLeUp()
self.moveUp()

def moveLeft(self, undo: bool = False):
if not undo:
Expand Down
14 changes: 4 additions & 10 deletions src/game/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,17 @@ def blockLanded(self):

def validMove(self, simulateimulatedMove):
# if simulated move fails = move out of bounds and should be disallowed
try:
simulateimulatedMove()
except:
simulateimulatedMove(undo=True)
return False

simulateimulatedMove()
for i in range(4):
for j in range(4):
if i * 4 + j in self.block.image():
if i + self.block.y > self.rows - 1 or \
j + self.block.x > self.columns - 1 or \
j + self.block.x < 0 or \
self.board[i + self.block.y][j + self.block.x] > 0:

return True
simulateimulatedMove(undo=True)
return False # Return True if the move is valid
simulateimulatedMove(undo=True)
return False
return True


def clearRow(self, rownumber):
Expand Down

0 comments on commit 7552f72

Please sign in to comment.