From fd57ee8dd22ca0a439b142e367f18da0bf2bcd53 Mon Sep 17 00:00:00 2001 From: Leonid Belyaev Date: Fri, 3 Dec 2021 11:10:11 -0500 Subject: [PATCH] lock template --- code/bot/__pycache__/game.cpython-39.pyc | Bin 4844 -> 4751 bytes code/bot/game.py | 33 +++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/code/bot/__pycache__/game.cpython-39.pyc b/code/bot/__pycache__/game.cpython-39.pyc index bd2a87c6bd4c3a9e10c10e836cf57fd9131042ef..8d253b9597b4b27b15775af381a2a7a931f71595 100644 GIT binary patch delta 840 zcmbu7&ubG=5Xa~J*dN*KZkiBjLyHz`u&Y=Cq7qsaTJa>g^j2FWbgOOBB+c7JMCRE; z@Fpm}qX-HftT*xKpW&@HuhKulc?(v(>cY&M`3}sR&%8ZpzHG+bC<=hSh1;LH-|C;^ zQTe{4)FE3V%R1x`dT!kPJY@}-u)aeI#kP`jW;e-9rcHdN@*=RuJ%wmC%++2&AafxD=tZ4ng z>_*K)A`wJ+izuabw2LyAxntQ=VwtcBdrb49^GiKdTx94Ftz3ceV#>9LjQT9mo@~ER z`^eG10h*7W(0&AZZy=R#g;mf?9Xh@70h+V%<@sVU=V-2CJ4vYkI~Ho^;FxE*x@3lN zyOvWun8Ru89)cc3~(BO#`IH$ zUfpIT9bgIhG+=;Y+A3uoB74WNj3K%Y#e2qJT+iuOm@v(9i7?kIc162@o;#82aKt;x zzTlCkmd(e?`C3%as1|8z#k!m3du2aQ3%AZ1A70468?!|u2fs` UtG{O)R9|?W@A*}~{JM7X6MdznyZ`_I delta 951 zcmcIi&ubGw6n-n0{3rQG@F0`$^xtpU=f3r7Q*c#~XmDxpG&eMu4o#(IH!!^vv_f;LLs1;`RX+$?<4j~0d0YUA`3#_gVg@+1M*Wv#hHl+do~odSya8B2(J+j!0%RX7 z^fAEFKwSRF7$mcqjbxZ&nL|G-Q2?0)+iq@k;efA8L5&@h<{9 diff --git a/code/bot/game.py b/code/bot/game.py index b5bad88..d9ae354 100644 --- a/code/bot/game.py +++ b/code/bot/game.py @@ -101,14 +101,34 @@ def move_anchor(self, x_shift, y_shift): def is_legal(self): """Illegal if oob or intersecting""" - for i in range(len(self.piece)): - x, y, label = self.piece[i] + for x, y, label in self.piece: if x < 0 or x >= len(self.grid[0]) or y < 0 or grid[y][x] != BLANK_LABEL: return False return True def lock_piece(self, randomizer): """Fix the current piece to the board if possible, and get a new one""" + # TODO suboptimal + + can_lock = False + for x, y, label in self.piece: + if y == len(self.grid) - 1 or self.grid[y + 1][x] != BLANK_LABEL: + can_lock = True + break + if can_lock and self.is_legal(): + new_grid = [] + for row in self.grid: + new_grid.append(list(row)) + for x, y, label in self.piece: + new_grid[y][x] = label + for i in range(len(new_grid)): + new_grid[i] = tuple(new_grid[i]) + new_grid = tuple(new_grid) + new_piece = randomizer.choice() + mapped_piece = shift_piece(new_piece, self.spawn[0], self.spawn[1]) + return CheeseState(self.spawn, self.spawn, mapped_piece, new_grid) + else: + return CheeseState(self.spawn, self.anchor, self.piece, self.grid) def __repr__(self): rep = [] @@ -116,8 +136,7 @@ def __repr__(self): for row in self.grid: rep.append(list(row)) - for i in range(len(self.piece)): - x, y, label = self.piece[i] + for x, y, label in self.piece: if x in range(len(self.grid[0])) and y in range(len(self.grid)): rep[y][x] = label count = 0 @@ -131,8 +150,7 @@ def __repr__(self): def rotate_left(self): new_piece = [] anchor_x, anchor_y = self.anchor - for i in range(len(self.piece)): - x, y, label = self.piece[i] + for x, y, label in self.piece: offset_x, offset_y = (x - anchor_x, y - anchor_y) new_offset_x, new_offset_y = (offset_y, -1 * offset_x) new_x, new_y = (new_offset_x + anchor_x, new_offset_y + anchor_y) @@ -143,8 +161,7 @@ def rotate_left(self): def rotate_right(self): new_piece = [] anchor_x, anchor_y = self.anchor - for i in range(len(self.piece)): - x, y, label = self.piece[i] + for x, y, label in self.piece: offset_x, offset_y = (x - anchor_x, y - anchor_y) new_offset_x, new_offset_y = (-1 * offset_y, offset_x) new_x, new_y = (new_offset_x + anchor_x, new_offset_y + anchor_y)