Exemplo n.º 1
0
 def max_play(self, board):
     over_var = over(board)
     if over_var is not None:
         return -1 * over_var
     moves = [i for i in board[1:] if type(i) is int]
     best_score = float('-inf')
     for move in moves:
         clone = list(board)
         clone[move] = self.p
         score = self.min_play(clone)
         if score > best_score:
             best_score = score
     return best_score
Exemplo n.º 2
0
 def make_move(self, board):
     moves = [i for i in board[1:] if type(i) is int]
     a = random.choice(moves)
     board[a] = self.p
     ovr = over(board)
     if ovr is not None:
         print_board(board)
         if ovr == 10:
             print("I Win!")
         elif ovr == 0:
             print("It's a draw!")
         return 0
     return board
Exemplo n.º 3
0
 def make_move(self, board):
     moves = [i for i in board[1:] if type(i) is int]
     if len(moves) >= 8:
         m = self.first_move(board)
     else:
         m = self.minimax(board)
     board[m] = self.p
     print_board(board)
     ovr = over(board)
     if ovr is not None:
         if ovr == 10:
             print("I Win!")
         elif ovr == 0:
             print("It's a draw!")
         return 0
     return board
Exemplo n.º 4
0
def m(board, p):
    try:
        n = int(input("Please choose your space "))
    except ValueError:
        print("Illegal move")
        return m(board, p)

    if n == 0: quit()

    if n > 9 or board[n] != n:
        print("Illegal move")
        return m(board, p)
    else:
        board[n] = p
        ovr = over(board)
        if ovr is not None:
            print_board(board)
            if ovr == 10:
                print("You Win!")
            elif ovr == 0:
                print("It's a draw!")
            return 0
        return board
Exemplo n.º 5
0
def main():
    clock = pygame.time.Clock()
    pygame.init()

    # Some extra variables
    asseleration = 0.025
    speed_game = 30
    points = 0
    direction = "left_down"

    # Initializing objects
    player = Player()
    ball = Ball()     

    # Adding ball to group balls (that's for collision)
    balls = pygame.sprite.Group()
    balls.add(ball)

    # Making group of all sprites (to blit them later faster)
    all_sprites = pygame.sprite.Group()
    all_sprites.add(player)
    all_sprites.add(ball)

    running = True
    screen = pygame.display.set_mode((C.SCREEN_WIDTH, C.SCREEN_HEIGHT))
    pygame.display.set_caption("Ping-Pong")


    font = pygame.font.SysFont('Arial', 800) 

    # Main loop
    while running:

        # Check wheather ball hits botoom
        running = check_collision(player, ball, balls, direction)[0]

        # Checking events for quiting
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    running = False
            elif event.type == QUIT:
                running = False

        # User's input
        pressed_keys = pygame.key.get_pressed()

        # Updating ackground
        screen.fill((25, 50, 50))

        # Rendering text and drawing it
        text_points = font.render('{0}'.format(points), True, (100, 100, 100))
        text_points_rect = text_points.get_rect(center = (C.SCREEN_WIDTH/2, C.SCREEN_HEIGHT/2))
        screen.blit(text_points, text_points_rect)

        # Updating objects
        player.update(pressed_keys)
        ball.update(direction)

        # Drawing objects
        for sprite in all_sprites:
            screen.blit(sprite.surf, sprite.rect)

        points += check_collision(player, ball, balls, direction)[1]
        direction = check_collision(player, ball, balls, direction)[2]
        
        # flipping and asselereting of framerate
        pygame.display.flip()
        if speed_game <+ 120:
            speed_game += asseleration    
        clock.tick(speed_game) 
    pygame.quit()
    over.over(points)