I'm relatively new to Python, but something that came to my mind the other day was that I wanted to implement a version of The Brain Puzzle by Magnif No. 2225, which is demonstrated here:
https://www.youtube.com/watch?v=o6V1UlEzdD8&t=160s
Here's the thing, is I used to own one of these, and it broke. It was something I really enjoyed, and decided I wanted to implement it in software. I read that pygame could help draw things, so I started with that library and a small tutorial... Long story short, I'm able to get the "starting" board state, but it seems really slow to update.
Without further ramble, here's what I have -- I haven't written the elif block yet, but it's essentially the same, just in the "other" direction:
import pygame
import pygame.freetype
import numpy as np
import time
class Particle:
def __init__(self,position,size,thickness,color):
self.x=position[0]
self.y=position[1]
self.size = size
self.rred = color[0]
self.bblue = color[1]
self.ggreen = color[2]
self.thickness = thickness
def display(self):
pygame.draw.circle(screen, (self.rred,self.bblue,self.ggreen), (self.x, self.y), self.size, self.thickness)
# sets a window size
(width, height) = (800, 600)
screen = pygame.display.set_mode((width, height))
# Sets a color for background
background_colour = (255,255,255)
# Sets window title
pygame.display.set_caption('The Brain Puzzler')
# Makes background white
screen.fill(background_colour)
#draws a black circle on the screen at the specified location
myParticles = []
mainBoard = Particle((400,300),225,5,(0,0,0))
myParticles.append(mainBoard)
#185 for tab out
for circ in range(0,8):
gameTab = Particle((400+70*np.cos(circ*np.pi/4),300+70*np.sin(circ*np.pi/4)),10,3,(0,0,0))
myParticles.append(gameTab)
for part in myParticles:
part.display()
#displays screen
pygame.display.flip()
running = True
#while running:
#for event in pygame.event.get():
#if event.type == pygame.QUIT:
#running = False
#initialize binary variables
#each position represents the state of each slider
binaryy = '11111111'
#initialize solution
sol = '12131214121312151213121412131216121312141213121512131214121312171213121412131215121312141213121612131214121312151213121412131218121312141213121512131214121312161213121412'
#initialize user path
x=''
#initialize iter variable for solution path
y=0
while x != sol:
inputf = int(input('Input the slider that you\'d like to actuate?: '))
if str(inputf) == sol[y]:
y=y+1
x+=str(inputf)
print("Current Path:", x)
if binaryy[inputf-1]=='1':
binaryy = binaryy[:inputf-1]+'2'+binaryy[inputf+0:]
print("Staus:", binaryy)
#update game status
gameTab = Particle((400+70*np.cos((inputf-1)*np.pi/4),300+70*np.sin((inputf-1)*np.pi/4)),10,3,(0,0,0))
myParticles.append(gameTab)
gameTab = Particle((400+185*np.cos((inputf-1)*np.pi/4),300+185*np.sin((inputf-1)*np.pi/4)),10,3,(255,255,255))
myParticles.append(gameTab)
for part in myParticles:
part.display()
pygame.display.update()
else:
binaryy = binaryy[:inputf-1]+'1'+binaryy[inputf+0:]
print("Status:", binaryy)
gameTab = Particle((400+70*np.cos((inputf-1)*np.pi/4),300+70*np.sin((inputf-1)*np.pi/4)),10,3,(255,255,255))
myParticles.append(gameTab)
gameTab = Particle((400+185*np.cos((inputf-1)*np.pi/4),300+185*np.sin((inputf-1)*np.pi/4)),10,3,(0,0,0))
myParticles.append(gameTab)
for part in myParticles:
part.display()
pygame.display.update()
elif inputf == sol[y-1]:
y=y-1
x= x[:-1]
print(x)
else:
print("try again")