pygame

Game AI works powerfully on one side and becomes dumb on the other in Tic-Tac-Toe

笑着哭i 提交于 2020-06-23 18:06:08
问题 I am trying to make a Tic-Tac-Toe game in Python using PyGame and the MiniMax algorithm. The AI plays really well when given the first chance (playing as 'X'), but becomes dumb enough to help the user win when not given the first chance (playing as 'O'). I think I know what the problem is but changing it is messing with the whole program and is not going by the given docstrings. I've made two python files - one for the GUI (runner.py) and the other for the logic behind the game and the AI

Game AI works powerfully on one side and becomes dumb on the other in Tic-Tac-Toe

跟風遠走 提交于 2020-06-23 18:05:29
问题 I am trying to make a Tic-Tac-Toe game in Python using PyGame and the MiniMax algorithm. The AI plays really well when given the first chance (playing as 'X'), but becomes dumb enough to help the user win when not given the first chance (playing as 'O'). I think I know what the problem is but changing it is messing with the whole program and is not going by the given docstrings. I've made two python files - one for the GUI (runner.py) and the other for the logic behind the game and the AI

Pygame on Ubuntu Python 3

ぐ巨炮叔叔 提交于 2020-06-23 11:57:31
问题 I have searched everywhere. There is no answer for my specific problem! I have Ubuntu, I want to use pygame on Python 3. I installed the pygame package with sudo apt-get python-pygame but it just doesn't work when I type import pygame Please help! 回答1: You must install pip for python3 $ sudo apt install python3-pip and then, with the pip installed, install pygame $ pip3 install pygame 回答2: The pygame package on Ubuntu is only for python 2.7, so it is impossible to import if you use python 3.

Pygame on Ubuntu Python 3

我只是一个虾纸丫 提交于 2020-06-23 11:57:06
问题 I have searched everywhere. There is no answer for my specific problem! I have Ubuntu, I want to use pygame on Python 3. I installed the pygame package with sudo apt-get python-pygame but it just doesn't work when I type import pygame Please help! 回答1: You must install pip for python3 $ sudo apt install python3-pip and then, with the pip installed, install pygame $ pip3 install pygame 回答2: The pygame package on Ubuntu is only for python 2.7, so it is impossible to import if you use python 3.

how to modify the view of the camera with pygame and openGL

依然范特西╮ 提交于 2020-06-23 08:53:12
问题 I'm using python3 I have just started learning openGL and I need some help turning the camera of your view with a mouse (Like a FPS game). Right now my program looks like i'm moving but i'm just moving the object so if you could tell me how to move the camera(forward, backwards, etc) too that would be nice. Thanks in advance My Code: import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * vertices = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (1,

How to fade the screen out and back in using PyGame?

[亡魂溺海] 提交于 2020-06-23 06:12:08
问题 So I am trying to fade my screen out and back in after completing a level using PyGame. My problem is that only the fadeout() works and not the fadein(). When calling the fadein() the screen turns black for a few seconds then suddenly shows the next level. I can't find the problem, any ideas? def fadeout(): fadeout = pg.Surface((screen_width, screen_height)) fadeout = fadeout.convert() fadeout.fill(black) for i in range(255): fadeout.set_alpha(i) screen.blit(fadeout, (0, 0)) pg.display.update

How can I made a collision mask?

若如初见. 提交于 2020-06-22 04:10:49
问题 I try to make a collision mask to detect if two sprites collide themselves, but It's not working at all, I got an instant crash, Can you help me ? My code is : Player.rect = Player.image.get_rect() oc1.rect = oc1.image.get_rect() mask_1 = pg.mask.from_surface(Player) mask_2 = pg.mask.from_surface(oc1) Cm = pg.sprite.collide_mask(mask_1, mask_2) if Cm != None : print('life - 1') 回答1: See the documentation of pygame.sprite.collide_mask(): Collision detection between two sprites, using masks.

How can I made a collision mask?

烂漫一生 提交于 2020-06-22 04:08:06
问题 I try to make a collision mask to detect if two sprites collide themselves, but It's not working at all, I got an instant crash, Can you help me ? My code is : Player.rect = Player.image.get_rect() oc1.rect = oc1.image.get_rect() mask_1 = pg.mask.from_surface(Player) mask_2 = pg.mask.from_surface(oc1) Cm = pg.sprite.collide_mask(mask_1, mask_2) if Cm != None : print('life - 1') 回答1: See the documentation of pygame.sprite.collide_mask(): Collision detection between two sprites, using masks.

Pygame 1.9.6 not loading in Python 3.8.1

雨燕双飞 提交于 2020-06-19 08:31:48
问题 Really strange issue here. I have a 64bit copy of Python 3.8.1 on my Mac (Catalina 10.15.2). I have successfully installed pygame via pip3 install pygame . Every time I run Python3 and import pygame, I get the successful message of hello from the pygame community... . However, if I run any program that requires an import of pygame, the icon for my python launcher just loops and loads for an infinite amount of time. I get no error messages. I literally get nothing. No opened windows. Just a

How do I blit an image on a keypressed event in pygame

梦想与她 提交于 2020-06-18 08:43:16
问题 I'm trying to blit an image to the screen when the event K_SPACE is triggered. However, when I press space nothing happens. I've tried moving where the screen is updated or flipped, but i've hit a brick wall. Here is my code: def Play(): background = pygame.image.load(bifPlay).convert() char = pygame.image.load(mif).convert_alpha() bullet = pygame.image.load(bulletLoad).convert() zombie = pygame.image.load(zombieLoad).convert_alpha() #converting images needed so pygame can use them x,y = 115