One way is to create a value for each play area.
You can have many values.
Corners would have best place value.
Change value. How many would change to your color.
And whatever else you can think of.
Then you can have computer choose the best option or second best option.
Depends how smart you want the computer to be.
Here one way of doing it.
You can have many values.
Corners would have best place value.
Change value. How many would change to your color.
And whatever else you can think of.
Then you can have computer choose the best option or second best option.
Depends how smart you want the computer to be.
(Apr-20-2019, 03:41 AM)keames Wrote: That's good advice. I haven't used pygame since 2014! How is it over there in pygamia? I'd be surprised if they didn't update it since then. Do you still have to write the event loop yourself or did they implement mainloop and bind functions?Why would they need to change to widget event system. If you wanted that in pygame. It really easy to do.
Here one way of doing it.
import pygame class State: def __init__(self): self._bind_event = {} def bind(self, event, callback): if self._bind_event.get(event, False): self._bind_event[event].append(callback) else: self._bind_event[event] = [callback] def draw(self, surface): pass def _event(self, event): group = self._bind_event.get(event.type, False) if group: for callback in group: callback(event) def update(self): pass class StateMachine: @classmethod def setup(cls, caption, width, height): # Basic Pygame Setup pygame.display.set_caption(caption) cls.surface = pygame.display.set_mode((width, height)) cls.rect = cls.surface.get_rect() cls.clock = pygame.time.Clock() cls.running = False cls.delta = 0 cls.fps = 30 # State Interface cls.states = {} cls.state = State() @classmethod def mainloop(cls): cls.running = True while cls.running: for event in pygame.event.get(): cls.state._event(event) cls.state.update() cls.state.draw(cls.surface) pygame.display.flip() cls.delta = cls.clock.tick(cls.fps) class Scene(State): def __init__(self): State.__init__(self) self.bind(pygame.MOUSEBUTTONDOWN, self.on_mousebuttondown) self.bind(pygame.QUIT, self.on_quit) def draw(self, surface): surface.fill(pygame.Color("navy")) def on_mousebuttondown(self, event): print(event.button) def on_quit(self, event): StateMachine.running = False def main(): pygame.init() StateMachine.setup("Example", 400, 300) StateMachine.state = Scene() StateMachine.mainloop() pygame.quit() main()
99 percent of computer problems exists between chair and keyboard.