Beispiel #1
0
 def _init_action_set(self):
     actions = {}
     for i, row in enumerate(self.board.rows):
         for j , col in enumerate(self.board.cols):
             x = 0.1 * self.side_length + 0.8 * (j+0.5) / len(self.board.cols) * self.side_length
             y = 0.1 * self.side_length + 0.8 * (i+0.5) / len(self.board.rows) * self.side_length
             actions[row+col] = utils.element_wise_addition(self.top_left, (x, y))
     return actions
Beispiel #2
0
 def _display_game_over(self):
     """
     Display 'GAME OVER' on the screen 
     """
     font = pygame.font.Font(self.font, 72)
     text = font.render('GAME OVER', True, (255, 255, 255))
     text_rect = text.get_rect()
     text_rect.center = utils.element_wise_addition(self.top_left, (0.5 * self.side_length, 0.5 * self.side_length))
     self.screen.blit(text, text_rect)
Beispiel #3
0
 def _display_current_player(self):
     """
     Display who's turn to play.
     """
     content = {-1: 'Black\'s turn.', 1: 'White\'s turn.'}
     text_color = {-1: (0, 0, 0), 1: (255, 255, 255)}
     font = pygame.font.Font(self.font, 24)
     text = font.render(content[self.cur_player], True, text_color[self.cur_player])
     text_rect = text.get_rect()
     text_rect.center = utils.element_wise_addition(self.top_left, (0.5 * self.side_length, 0.95 * self.side_length))
     self.screen.blit(text, text_rect)
Beispiel #4
0
 def _display_scores_and_time_left(self):
     """
     Dispaly scores and time left for both players.
     """
     text_colors = [[(255,160,122), (255,160,122)], [(0, 0, 0), (255, 255, 255)]]
     time_left = {key: max(0, int(self.time_left[key] // 1000)) for key in self.time_left}
     for i, display_dict in enumerate((time_left, self.scores)):
         for j, (player, text_color) in enumerate(zip(display_dict, text_colors[i])):
             font = pygame.font.Font(self.font, 24)
             text = font.render(str(display_dict[player]), True, text_color)
             text_rect = text.get_rect()
             text_rect.center = utils.element_wise_addition(self.top_left, (abs(0.1*(i+1)-j) * self.side_length, 0.95 * self.side_length))
             self.screen.blit(text, text_rect)
Beispiel #5
0
    def draw_board(self, screen):
        self.board_size = (self.side_length, self.side_length)
        self.border_size = (0.1 * self.side_length, self.side_length)

        translation = (0.9 * self.side_length, 0)
        top_left = self.top_left
        top_right = utils.element_wise_addition(top_left, translation)
        bottom_left = utils.element_wise_addition(top_left,
                                                  reversed(translation))

        pygame.draw.rect(screen, self.bg_color, (top_left, self.board_size))
        pygame.draw.rect(screen, self.border_color,
                         (top_left, self.border_size))
        pygame.draw.rect(screen, self.border_color,
                         (top_right, self.border_size))
        pygame.draw.rect(screen, self.border_color,
                         (top_left, tuple(reversed(self.border_size))))
        pygame.draw.rect(screen, self.border_color,
                         (bottom_left, tuple(reversed(self.border_size))))

        for i, col in enumerate([''] + self.cols):
            x = 0.1 * self.side_length + 0.8 * i / len(
                self.cols) * self.side_length
            start = utils.element_wise_addition(top_left,
                                                (x, 0.1 * self.side_length))
            end = utils.element_wise_addition(top_left,
                                              (x, 0.9 * self.side_length))
            pygame.draw.line(screen, self.line_color, start, end)

            pos = utils.element_wise_addition(
                top_left, (x - 0.5 * 0.8 / len(self.cols) * self.side_length,
                           0.5 * 0.8 / len(self.cols) * self.side_length))
            self._draw_label(screen, col, pos)

        for i, row in enumerate([''] + self.rows):
            y = 0.1 * self.side_length + 0.8 * i / len(
                self.rows) * self.side_length
            start = utils.element_wise_addition(top_left,
                                                (0.1 * self.side_length, y))
            end = utils.element_wise_addition(top_left,
                                              (0.9 * self.side_length, y))
            pygame.draw.line(screen, self.line_color, start, end)

            pos = utils.element_wise_addition(
                top_left, (0.5 * 0.8 / len(self.rows) * self.side_length,
                           y - 0.5 * 0.8 / len(self.rows) * self.side_length))
            self._draw_label(screen, row, pos)