Fix config loading, speed thresholds and block selection; add tests, README, CLAUDE.md
This commit is contained in:
+15
-15
@@ -85,8 +85,7 @@ class TetrisGame:
|
||||
else:
|
||||
self.current_block = self.next_block
|
||||
self.current_block_rotation = self.next_block_rotation
|
||||
while self.current_block == self.next_block:
|
||||
self.next_block = self.choice_random_block()
|
||||
self.next_block = self.choice_random_block(exclude=self.current_block)
|
||||
self.next_block_rotation = 0
|
||||
|
||||
self.current_block_x = self.width // 2 - 2
|
||||
@@ -97,11 +96,11 @@ class TetrisGame:
|
||||
self.current_block_rotation, self.current_block):
|
||||
self.game_over = True
|
||||
|
||||
def choice_random_block(self) -> BLOCK_TYPE:
|
||||
block: BLOCK_TYPE = random.choice(list(BLOCK_TYPE))
|
||||
while self.get_block_min_score(block) > self.score:
|
||||
block = random.choice(list(BLOCK_TYPE))
|
||||
return block
|
||||
def choice_random_block(self, exclude: BLOCK_TYPE = None) -> BLOCK_TYPE:
|
||||
"""Choose a random block allowed at the current score, avoiding `exclude` when possible"""
|
||||
allowed = [block for block in BLOCK_TYPE if self.get_block_min_score(block) <= self.score]
|
||||
candidates = [block for block in allowed if block != exclude] or allowed
|
||||
return random.choice(candidates)
|
||||
|
||||
def get_block_shape(self, block_type: BLOCK_TYPE, rotation: int) -> List[List[int]]:
|
||||
"""Get the shape matrix for a block at specific rotation"""
|
||||
@@ -220,20 +219,21 @@ class TetrisGame:
|
||||
elapsed = (current_ticks - self.last_time) / 1000.0 # Convert to seconds
|
||||
self.last_time = current_ticks
|
||||
|
||||
# Highest threshold first, otherwise only the first branch is ever reached
|
||||
if cfg.HIGH_SCORE_INC_SPEED:
|
||||
if self.score > 5000:
|
||||
self.fall_speed = 0.55
|
||||
if self.score > 15000:
|
||||
self.fall_speed = 0.65
|
||||
elif self.score > 10000:
|
||||
self.fall_speed = 0.6
|
||||
elif self.score > 15000:
|
||||
self.fall_speed = 0.65
|
||||
elif self.score > 5000:
|
||||
self.fall_speed = 0.55
|
||||
else:
|
||||
if self.score > 5000:
|
||||
self.fall_speed = 0.45
|
||||
if self.score > 15000:
|
||||
self.fall_speed = 0.35
|
||||
elif self.score > 10000:
|
||||
self.fall_speed = 0.4
|
||||
elif self.score > 15000:
|
||||
self.fall_speed = 0.35
|
||||
elif self.score > 5000:
|
||||
self.fall_speed = 0.45
|
||||
|
||||
if not self.game_over and not self.paused:
|
||||
self.fall_time += elapsed
|
||||
|
||||
Reference in New Issue
Block a user