Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "meterfeeder"]
path = meterfeeder
url = https://github.com/vfp2/meterfeeder
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## About

Some simple MMI games using random walk bias amplifier, majority voting, and comscire qrng.

1. The guessing game is a simple number guessing game where you guess between 0 and 1
1. pulse.py allows you to attempt to influence the pulse of a wave
1. quantum color picker is a color guessing game
1. quantum dream predictor tasks you with setting an intention to dream about a certain location, and then attempts to predict the location you dreamt of
1. quantum emotion detector asks you to send an emotion as an intention, and then tries to predict the emotion
1. quantum hot and cold is sort of like minesweeper, you click cells and attempt to only click on “hot” cells, which are red. clicking on “cold” blue cells causes you to lose score.
1. salamander.py is a simple implementation of newton’s majority vote mmi algorithm

## Usage

* $ pip install -r requirements
* $ brew install python-tk (if on Mac)
* $ python3 pulse.py (or py filename of the game)

## Credits

[https://github.com/luckyjupiter/mmi](https://github.com/luckyjupiter/mmi)
1 change: 1 addition & 0 deletions meterfeeder
Submodule meterfeeder added at 77d4e0
56 changes: 56 additions & 0 deletions meterfeeder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
from sys import platform
from ctypes import *

# List of connected devices with serial numbers (key) and descriptions (value)
devices = {}

def load_library():
# Load the MeterFeeter library
global METER_FEEDER_LIB
if platform == "linux" or platform == "linux2":
# Linux
METER_FEEDER_LIB = cdll.LoadLibrary(os.getcwd() + '/meterfeeder/builds/linux/libmeterfeeder.so')
elif platform == "darwin":
# OS X
METER_FEEDER_LIB = cdll.LoadLibrary(os.getcwd() + '/meterfeeder/builds/mac/libmeterfeeder.dylib')
elif platform == "win32":
# Windows
METER_FEEDER_LIB = cdll.LoadLibrary(os.getcwd() + '/meterfeeder/builds/windows/meterfeeder.dll')
METER_FEEDER_LIB.MF_Initialize.argtypes = c_char_p,
METER_FEEDER_LIB.MF_Initialize.restype = c_int
METER_FEEDER_LIB.MF_GetNumberGenerators.restype = c_int
METER_FEEDER_LIB.MF_GetBytes.argtypes = c_int, POINTER(c_ubyte), c_char_p, c_char_p,
METER_FEEDER_LIB.MF_RandUniform.argtypes = c_char_p, c_char_p
METER_FEEDER_LIB.MF_RandUniform.restype = c_double

# Make driver initialize all the connected devices
global med_error_reason
med_error_reason = create_string_buffer(256)
result = METER_FEEDER_LIB.MF_Initialize(med_error_reason)
print("MeterFeeder::MF_Initialize: result: " + str(result) + ", error (if any): ", med_error_reason.value)
if (len(med_error_reason.value) > 0):
exit(result)

def get_devices():
# Get the number of connected devices
numGenerators = METER_FEEDER_LIB.MF_GetNumberGenerators()
print("MeterFeeder::MF_GetNumberGenerators: " + str(numGenerators) + " connected device(s)")

# Get the list of connected devices
generatorsListBuffers = [create_string_buffer(58) for i in range(numGenerators)]
generatorsListBufferPointers = (c_char_p*numGenerators)(*map(addressof, generatorsListBuffers))
METER_FEEDER_LIB.MF_GetListGenerators(generatorsListBufferPointers)
generatorsList = [str(s.value, 'utf-8') for s in generatorsListBuffers]
print("MeterFeeder::MF_GetListGenerators: Device serial numbers and descriptions:")
for i in range(numGenerators):
kvs = generatorsList[i].split("|")
devices[kvs[0]] = kvs[1]
print("\t" + str(kvs[0]) + "->" + kvs[1])

def rand_uniform():
# Get a RandUniform, taking the first device in the list (if multiple devices connected)
firstDevice = next(iter(devices))
ret_RandUniform = METER_FEEDER_LIB.MF_RandUniform(firstDevice.encode("utf-8"), med_error_reason)
#print("MeterFeeder::MF_RandUniform: result: " + str(ret_RandUniform) + ", error (if any): ", med_error_reason.value)
return ret_RandUniform
12 changes: 5 additions & 7 deletions pulse.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import tkinter as tk
from tkinter import Canvas
import meterfeeder as mf
import time
import win32com.client

class RandomWalkBiasAmplifier:
def __init__(self, bound):
self.bound = bound
self.counter = 0

def process_bit(self, bit):
if bit == 1:
self.counter += 1
else:
self.counter -= 1

if self.counter >= self.bound:
self.counter = 0
return 1
elif self.counter <= -self.bound:
self.counter = 0
return 0

return None

class QuantumPulse:
Expand All @@ -30,14 +27,12 @@ def __init__(self, root):
self.canvas = Canvas(self.root, bg="white", height=400, width=400)
self.canvas.pack(pady=20)

self.qng = win32com.client.Dispatch("QWQNG.QNG")
self.rwba = RandomWalkBiasAmplifier(5)

self.pulse()

def pulse(self):
# Get a random frequency using QWQNG
frequency = self.qng.RandUniform
frequency = mf.rand_uniform()

# Apply bias amplification
bit = int(frequency > 0.5)
Expand All @@ -60,6 +55,9 @@ def pulse(self):
self.root.after(int(1000 * frequency), self.pulse)

if __name__ == "__main__":
mf.load_library()
mf.get_devices()

root = tk.Tk()
app = QuantumPulse(root)
root.mainloop()
9 changes: 5 additions & 4 deletions quantumcolorpicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
Date: [Date]
"""

import win32com.client
import tkinter as tk
import meterfeeder as mf

class RandomWalkBiasAmplifier:
"""Implements the Random Walk Bias Amplifier technique."""
Expand All @@ -36,10 +36,9 @@ def process_bit(self, bit):
return None

def predict_color():
"""Predicts a color using the QWQNG API."""
qng = win32com.client.Dispatch("QWQNG.QNG")
"""Predicts a color using the MeterFeeder API."""
colors = ["red", "blue", "green", "yellow"]
rand_index = int(qng.RandUniform * len(colors))
rand_index = int(mf.rand_uniform() * len(colors))
return colors[rand_index]

class QuantumColorPredictor:
Expand Down Expand Up @@ -92,5 +91,7 @@ def run(self):
self.window.mainloop()

if __name__ == "__main__":
mf.load_library()
mf.get_devices()
game = QuantumColorPredictor()
game.run()
10 changes: 5 additions & 5 deletions quantumdreampredicter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tkinter as tk
import win32com.client
import meterfeeder as mf
import time

class RandomWalkBiasAmplifier:
Expand Down Expand Up @@ -30,8 +30,6 @@ def __init__(self):
self.window = tk.Tk()
self.window.title("Quantum Dream Prediction")

self.qng = win32com.client.Dispatch("QWQNG.QNG")

self.topics = ["beach", "forest", "city", "mountains", "desert", "ocean", "space", "jungle", "cave", "island"]

self.label = tk.Label(self.window, text="Set your intention to dream about one of the topics below:")
Expand All @@ -51,7 +49,7 @@ def __init__(self):
self.window.mainloop()

def predict_dream_topic(self):
bits = [int(self.qng.RandUniform > 0.5) for _ in range(1000)]
bits = [int(mf.rand_uniform() > 0.5) for _ in range(1000)]
majority_result = majority_voting(bits)

rwba = RandomWalkBiasAmplifier(5)
Expand All @@ -63,11 +61,13 @@ def predict_dream_topic(self):
else:
bias = majority_result

index = int(self.qng.RandUniform * len(self.topics))
index = int(mf.rand_uniform() * len(self.topics))
index = (index + bias) % len(self.topics)

predicted_topic = self.topics[index]
self.result_label.config(text=f"The quantum prediction for your dream topic is: {predicted_topic.capitalize()}")

if __name__ == "__main__":
mf.load_library()
mf.get_devices()
QuantumDreamPrediction()
10 changes: 5 additions & 5 deletions quantumemotiondetector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tkinter as tk
import win32com.client
import meterfeeder as mf
import time
import sys

Expand Down Expand Up @@ -42,8 +42,6 @@ def __init__(self):
self.window = tk.Tk()
self.window.title("Quantum Emotion Detector")

self.qng = win32com.client.Dispatch("QWQNG.QNG")

self.emotions = ["happiness", "sadness", "anger", "fear", "surprise", "disgust"]

self.label = tk.Label(self.window, text="Select an emotion you want to send to the computer:")
Expand Down Expand Up @@ -75,7 +73,7 @@ def detect_emotion(self):

loading_animation(5) # Simulate longer processing time

bits = [int(self.qng.RandUniform > 0.5) for _ in range(100000)]
bits = [int(mf.rand_uniform() > 0.5) for _ in range(100000)]
majority_result = majority_voting(bits)

rwba = RandomWalkBiasAmplifier(5)
Expand All @@ -87,7 +85,7 @@ def detect_emotion(self):
else:
bias = majority_result

index = int(self.qng.RandUniform * len(self.emotions))
index = int(mf.rand_uniform() * len(self.emotions))
index = (index + bias) % len(self.emotions)

detected_emotion = self.emotions[index]
Expand All @@ -101,4 +99,6 @@ def detect_emotion(self):
self.stats_label.config(text=f"Matches: {self.matches} | Mismatches: {self.mismatches}")

if __name__ == "__main__":
mf.load_library()
mf.get_devices()
QuantumEmotionDetector()
17 changes: 8 additions & 9 deletions quantumhotandcold.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tkinter as tk
import win32com.client
import meterfeeder as mf
import math

class RandomWalkBiasAmplifier:
Expand Down Expand Up @@ -31,15 +31,12 @@ def __init__(self):
self.window = tk.Tk()
self.window.title("Quantum Hot and Cold")

# Initialize the Quantum RNG
self.qng = win32com.client.Dispatch("QWQNG.QNG")

# Randomly select a starting target point on the grid
self.target_x = int(self.qng.RandUniform * 10)
self.target_y = int(self.qng.RandUniform * 10)
self.target_x = int(mf.rand_uniform() * 10)
self.target_y = int(mf.rand_uniform() * 10)

# Apply bias amplification methods to potentially influence the target point
bits = [int(self.qng.RandUniform > 0.5) for _ in range(1000)]
bits = [int(mf.rand_uniform() > 0.5) for _ in range(1000)]
if majority_voting(bits) == 1:
self.target_x = (self.target_x + 1) % 10
else:
Expand Down Expand Up @@ -83,8 +80,8 @@ def check_guess(self, x, y):
if distance == 0:
self.hits += 1
feedback = "You found it!"
self.target_x = int(self.qng.RandUniform * 10)
self.target_y = int(self.qng.RandUniform * 10)
self.target_x = int(mf.rand_uniform() * 10)
self.target_y = int(mf.rand_uniform() * 10)
elif distance < 3:
feedback = "Hot!"
self.grid_buttons[x][y].config(bg=f"#{255-color_intensity:02x}0000")
Expand All @@ -98,4 +95,6 @@ def check_guess(self, x, y):
self.feedback_label.config(text=f"{feedback} Accuracy: {accuracy:.2f}%")

if __name__ == "__main__":
mf.load_library()
mf.get_devices()
QuantumHotAndCold()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tk