def ai_move(self, delta_x):
     if not self.gameover and not self.paused:  # 게임 종료, 정지 상태가 아니라면
         new_x = self.stone_x + delta_x  # 새로운 x 좌표는   기존의 stone의 x좌표 + 이동좌표수
         if new_x < Var.board_start_x:  # 새로운 좌표가 0보다 작다면
             new_x = Var.board_start_x  # 새로운 좌표는 0 ( 변경 없음 )
         if new_x > self.board.width - len(Var.piece_length(
                 self.stone)):  # 새로운 좌표 > 열의개수(10) - 블럭의 x축 길이
             new_x = self.board.width - len(Var.piece_length(
                 self.stone))  # 이동 불가 (변경 없음)
         if not self.board.ai_check_collision(
                 self.ai_board, self.stone,
             (new_x, self.stone_y)):  # 벽과 부딪히지 않는 다면
             self.stone_x = new_x  # 새로운 좌표로 이동
Esempio n. 2
0
 def projectPieceDown(self, piece, offsetX, workingPieceIndex):
     if offsetX + len(Var.piece_length(
             piece)) > self.width or offsetX < Var.board_start_x:
         return None
     # result = copy.deepcopy(self)
     offsetY = self.height
     for y in range(Var.board_start_y, self.height):
         if Ai.check_collision(self.field, piece, (offsetX, y)):
             offsetY = y
             break
     for x in range(Var.block_start_index, len(Var.piece_length(piece))):
         for y in range(Var.block_start_index, len(piece)):
             value = piece[y][x]
             if value > Var.board_empty_state:
                 self.field[offsetY - Var.for_index_var +
                            y][offsetX + x] = -workingPieceIndex
     return self
 def ai_new_stone(self):
     self.stone = self.next_stone[:]
     self.next_stone = Var.ai_tetris_shapes[random.randint(
         Var.ai_block_choice_start,
         Var.ai_block_choice_end)]  # 다음 블럭 랜덤으로 고르기 0~6 사이의 랜덤 숫자를 통해 고르기
     self.stone_x = int(
         (self.board.width - len(Var.piece_length(self.stone))) *
         Var.ai_stone_start_x_rate)  # self.width 기준 스톤의 위치 x
     self.stone_y = Var.ai_stone_start_y
     if self.board.ai_check_collision(self.ai_board, self.stone,
                                      (self.stone_x, self.stone_y)):
         self.gameover = True  # 블럭이 부딪히는 판단, 새점로 생성한 블럭이 벽에 부딪히면은 게임 종료
Esempio n. 4
0
 def rotate_clockwise(shape):  # 회전 시킨 모양 만들어 주기
     return [[shape[y][x] for y in range(len(shape))] for x in range(
         len(Var.piece_length(shape)) - Var.for_index_var,
         Var.search_rotate_next_index, Var.last_rotate_index_prev)]