Compare commits

..

2 Commits

Author SHA1 Message Date
randomuser 07d9b659e3 add nix shell 2023-09-26 21:41:37 -05:00
randomuser d58ae87f8c adding simon module 2023-09-26 21:41:28 -05:00
3 changed files with 87 additions and 1 deletions

11
shell.nix Normal file
View File

@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:
let
my-python-packages = ps: with ps; [
prompt-toolkit
pyautogui
opencv4
numpy
# other python packages
];
my-python = pkgs.python3.withPackages my-python-packages;
in my-python.env

View File

@ -1,5 +1,6 @@
from modules.wires import WiresModule
from modules.button import ButtonModule
from modules.simon import SimonModule
from modules.comp_wires import ComplicatedWiresModule
from modules.password import PasswordModule
@ -7,7 +8,7 @@ modules = {
'wires': WiresModule,
'button': ButtonModule,
'keypad': None,
'simon': None,
'simon': SimonModule,
'first': None,
'memory': None,
'morse': None,

74
src/modules/simon.py Normal file
View File

@ -0,0 +1,74 @@
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
class SimonModule:
buttonmapping = {
"vowel": {
0: {
"red": "blue",
"blue": "red",
"green": "yellow",
"yellow": "green",
},
1: {
"red": "yellow",
"blue": "green",
"green": "blue",
"yellow": "red",
},
2: {
"red": "green",
"blue": "red",
"green": "yellow",
"yellow": "blue",
},
},
"novowel": {
0: {
"red": "blue",
"blue": "yellow",
"green": "green",
"yellow": "red",
},
1: {
"red": "red",
"blue": "blue",
"green": "yellow",
"yellow": "green",
},
2: {
"red": "yellow",
"blue": "green",
"green": "blue",
"yellow": "red",
},
},
}
def __init__(self, strikes, isvowel):
self.strikes = strikes
self.isvowel = isvowel
self.isvowel = "vowel" if isvowel else "novowel"
def convert(self, color):
return self.buttonmapping[self.isvowel][self.strikes][color]
@classmethod
def interactive(cls, state, cmdline):
try:
obj = cls(state.strikes, state.serial.vowel)
except AttributeError:
print("you need to specify a serial number before running this.")
return
while True:
print("enter information")
user_in = prompt("simon> ")
if user_in == "strike":
state.strikes += 1
obj.strikes += 1
elif user_in == "quit":
break
else:
for i in user_in.split(" "):
print(obj.convert(i))