diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/.DS_Store new file mode 100644 index 00000000..f4530ad0 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/.DS_Store differ diff --git a/README.md b/DeveshAustineAtharv/DeveshAtharvAustine/README.md similarity index 100% rename from README.md rename to DeveshAustineAtharv/DeveshAtharvAustine/README.md diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/main.py b/DeveshAustineAtharv/DeveshAtharvAustine/main.py new file mode 100644 index 00000000..c32a5b80 --- /dev/null +++ b/DeveshAustineAtharv/DeveshAtharvAustine/main.py @@ -0,0 +1,72 @@ +""" +Quantum version of the classic Pong game +""" + +import random + +import pygame +from pygame import DOUBLEBUF, HWSURFACE, FULLSCREEN + +from qpong.utils.input import Input +from qpong.utils.level import Level +from qpong.utils.scene import Scene +from qpong.viz.statevector_grid import StatevectorGrid +from qpong.utils.parameters import ( + WINDOW_SIZE, + CLASSICAL_COMPUTER, + QUANTUM_COMPUTER, + WIN_SCORE, + WIDTH_UNIT, + MEASURE_RIGHT, +) + + +def main(): + """ + Main game loop + """ + + if not pygame.get_init(): + print("Warning, fonts disabled") + pygame.init() + + if not pygame.font.get_init(): + print("Warning, fonts disabled") + pygame.font.init() + + if not pygame.mixer.get_init(): + print("Warning, sound disabled") + pygame.mixer.init() + + # hardware acceleration to reduce flickering. Works only in full screen + flags = DOUBLEBUF | HWSURFACE | FULLSCREEN + screen = pygame.display.set_mode(WINDOW_SIZE, flags) + + + # clock for timing + clock = pygame.time.Clock() + old_clock = pygame.time.get_ticks() + + # initialize scene, level and input Classes + scene = Scene() + level = Level() + input = Input() + + # update the screen + pygame.display.flip() + + # Main Loop + while input.running: + # set maximum frame rate + clock.tick(60) + # refill whole screen with black color at each frame + screen.fill((0, 0, 0)) + # handle input events + input.handle_input(level, screen, scene) + + level.statevector_grid.print_statevector(5) + pygame.quit() + + +if __name__ == "__main__": + main() diff --git a/poetry.lock b/DeveshAustineAtharv/DeveshAtharvAustine/poetry.lock similarity index 100% rename from poetry.lock rename to DeveshAustineAtharv/DeveshAtharvAustine/poetry.lock diff --git a/pyproject.toml b/DeveshAustineAtharv/DeveshAtharvAustine/pyproject.toml similarity index 100% rename from pyproject.toml rename to DeveshAustineAtharv/DeveshAtharvAustine/pyproject.toml diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/.DS_Store new file mode 100644 index 00000000..f4530ad0 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/.DS_Store differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/.DS_Store new file mode 100644 index 00000000..294fbecf Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/.DS_Store differ diff --git a/QPong/qpong/containers/__init__.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__init__.py similarity index 100% rename from QPong/qpong/containers/__init__.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__init__.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/__init__.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..a4514eb5 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/__init__.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/__init__.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 00000000..56d0b646 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/__init__.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/vbox.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/vbox.cpython-311.pyc new file mode 100644 index 00000000..3faac1cf Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/vbox.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/vbox.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/vbox.cpython-313.pyc new file mode 100644 index 00000000..48543d9c Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/__pycache__/vbox.cpython-313.pyc differ diff --git a/QPong/qpong/containers/vbox.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/vbox.py similarity index 88% rename from QPong/qpong/containers/vbox.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/vbox.py index 247f61d1..47cc0532 100644 --- a/QPong/qpong/containers/vbox.py +++ b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/containers/vbox.py @@ -39,8 +39,3 @@ def arrange(self): next_xpos = self.xpos next_ypos = self.ypos sprite_list = self.sprites() - - for sprite in sprite_list: - sprite.rect.left = next_xpos - sprite.rect.top = next_ypos - next_ypos += sprite.rect.height diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/.DS_Store new file mode 100644 index 00000000..0a588f84 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/.DS_Store differ diff --git a/QPong/qpong/controls/__init__.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__init__.py similarity index 100% rename from QPong/qpong/controls/__init__.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__init__.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/__init__.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..db607887 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/__init__.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/__init__.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 00000000..ccb3f8b3 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/__init__.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/circuit_grid.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/circuit_grid.cpython-311.pyc new file mode 100644 index 00000000..18b54595 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/circuit_grid.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/circuit_grid.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/circuit_grid.cpython-313.pyc new file mode 100644 index 00000000..2c147535 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/__pycache__/circuit_grid.cpython-313.pyc differ diff --git a/QPong/qpong/controls/circuit_grid.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/circuit_grid.py similarity index 91% rename from QPong/qpong/controls/circuit_grid.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/circuit_grid.py index b6cadd2c..60e8437f 100644 --- a/QPong/qpong/controls/circuit_grid.py +++ b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/controls/circuit_grid.py @@ -49,22 +49,32 @@ def __init__(self, xpos, ypos, circuit_grid_model): self.selected_column = 0 self.circuit_grid_background = CircuitGridBackground(circuit_grid_model) self.circuit_grid_cursor = CircuitGridCursor() + self.music_grid_cursor = MusicGridCursor() self.gate_tiles = np.empty( (circuit_grid_model.max_wires, circuit_grid_model.max_columns), dtype=CircuitGridGate, ) + self.music_tiles = np.empty( + (circuit_grid_model.max_wires, circuit_grid_model.max_columns), + dtype=CircuitGridGate, + ) for row_idx in range(self.circuit_grid_model.max_wires): for col_idx in range(self.circuit_grid_model.max_columns): self.gate_tiles[row_idx][col_idx] = CircuitGridGate( circuit_grid_model, row_idx, col_idx ) + self.music_tiles[row_idx][col_idx] = CircuitGridGate( + circuit_grid_model, row_idx, col_idx + ) pygame.sprite.RenderPlain.__init__( self, self.circuit_grid_background, self.gate_tiles, + self.music_tiles, self.circuit_grid_cursor, + self.music_grid_cursor ) self.update() @@ -87,7 +97,14 @@ def update(self): ].rect.centerx = self.xpos + GRID_WIDTH * (col_idx + 1.5) self.gate_tiles[row_idx][ col_idx - ].rect.centery = self.ypos + GRID_HEIGHT * (row_idx + 1.0) + ].rect.centery = self.ypos + GRID_HEIGHT * ((row_idx + 1) * 0.65) + + self.music_tiles[row_idx][ + col_idx + ].rect.centerx = self.xpos + GRID_WIDTH * (col_idx + 1.5) + self.music_tiles[row_idx][ + col_idx + ].rect.centery = self.ypos + GRID_HEIGHT * ((row_idx + 1) * 0.65 - 200) self.highlight_selected_node(self.selected_wire, self.selected_column) @@ -107,9 +124,21 @@ def highlight_selected_node(self, wire_num, column_num): + GRID_WIDTH * (self.selected_column + 1) + round(0.375 * WIDTH_UNIT) ) + self.music_grid_cursor.rect.left = ( + (self.xpos) + + GRID_WIDTH * (self.selected_column + 1) + + round(0.375 * WIDTH_UNIT) + ) self.circuit_grid_cursor.rect.top = ( self.ypos - + GRID_HEIGHT * (self.selected_wire + 0.5) + + 10 + + GRID_HEIGHT * (self.selected_wire * 0.65) + + round(0.375 * WIDTH_UNIT) + ) + self.music_grid_cursor.rect.top = ( + (self.ypos + 250) + + 10 + + GRID_HEIGHT * (self.selected_wire * 0.65) + round(0.375 * WIDTH_UNIT) ) @@ -135,11 +164,11 @@ def move_to_adjacent_node(self, direction): and self.selected_column < self.circuit_grid_model.max_columns - 1 ): self.selected_column += 1 - elif direction == MOVE_UP and self.selected_wire > 0: + elif direction == MOVE_UP and self.selected_wire >= 0: self.selected_wire -= 1 elif ( direction == MOVE_DOWN - and self.selected_wire < self.circuit_grid_model.max_wires - 1 + and self.selected_wire < 4 ): self.selected_wire += 1 @@ -478,21 +507,29 @@ class CircuitGridBackground(pygame.sprite.Sprite): def __init__(self, circuit_grid_model): pygame.sprite.Sprite.__init__(self) - self.image = pygame.Surface([GRID_WIDTH * (18 + 2), GRID_HEIGHT * (3 + 1)]) + self.image = pygame.Surface([GRID_WIDTH * (18 + 2), GRID_HEIGHT * (9 + 1)]) self.image.convert() self.image.fill(WHITE) self.rect = self.image.get_rect() pygame.draw.rect(self.image, BLACK, self.rect, LINE_WIDTH) - for wire_num in range(circuit_grid_model.max_wires): + for wire_num in range(5): pygame.draw.line( self.image, - BLACK, - (GRID_WIDTH * 0.5, (wire_num + 1) * GRID_HEIGHT), - (self.rect.width - (GRID_WIDTH * 0.5), (wire_num + 1) * GRID_HEIGHT), + MAGENTA, + (GRID_WIDTH * 0.5, (wire_num * 0.65) * GRID_HEIGHT), + (self.rect.width - (GRID_WIDTH * 0.5), (wire_num * 0.65) * GRID_HEIGHT), LINE_WIDTH, ) + for wire_num in range(5): + pygame.draw.line( + self.image, + BLACK, + (GRID_WIDTH * 0.5, 250 + (wire_num * 0.65) * GRID_HEIGHT), + (self.rect.width - (GRID_WIDTH * 0.5), 250 + (wire_num * 0.65) * GRID_HEIGHT), + LINE_WIDTH, + ) class CircuitGridGate(pygame.sprite.Sprite): """ @@ -618,3 +655,13 @@ def __init__(self): "cursor_images/circuit-grid-cursor-medium.png", -1 ) self.image.convert_alpha() + +class MusicGridCursor(pygame.sprite.Sprite): + """Cursor to highlight current music node""" + + def __init__(self): + pygame.sprite.Sprite.__init__(self) + self.image, self.rect = load_image( + "cursor_images/circuit-grid-cursor-medium.png", -1 + ) + self.image.convert_alpha() diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/.DS_Store new file mode 100644 index 00000000..03b025d8 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/.DS_Store differ diff --git a/QPong/qpong/data/font/bit5x3.ttf b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/font/bit5x3.ttf similarity index 100% rename from QPong/qpong/data/font/bit5x3.ttf rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/font/bit5x3.ttf diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/.DS_Store new file mode 100644 index 00000000..4b51b547 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/.DS_Store differ diff --git a/QPong/qpong/data/images/cursor_images/circuit-grid-cursor-big.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/cursor_images/circuit-grid-cursor-big.png similarity index 100% rename from QPong/qpong/data/images/cursor_images/circuit-grid-cursor-big.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/cursor_images/circuit-grid-cursor-big.png diff --git a/QPong/qpong/data/images/cursor_images/circuit-grid-cursor-medium.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/cursor_images/circuit-grid-cursor-medium.png similarity index 100% rename from QPong/qpong/data/images/cursor_images/circuit-grid-cursor-medium.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/cursor_images/circuit-grid-cursor-medium.png diff --git a/QPong/qpong/data/images/cursor_images/circuit-grid-cursor.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/cursor_images/circuit-grid-cursor.png similarity index 100% rename from QPong/qpong/data/images/cursor_images/circuit-grid-cursor.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/cursor_images/circuit-grid-cursor.png diff --git a/QPong/qpong/data/images/gate_images/ctrl_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ctrl_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/ctrl_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ctrl_gate.png diff --git a/QPong/qpong/data/images/gate_images/ctrl_gate_bottom_wire.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ctrl_gate_bottom_wire.png similarity index 100% rename from QPong/qpong/data/images/gate_images/ctrl_gate_bottom_wire.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ctrl_gate_bottom_wire.png diff --git a/QPong/qpong/data/images/gate_images/ctrl_gate_top_wire.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ctrl_gate_top_wire.png similarity index 100% rename from QPong/qpong/data/images/gate_images/ctrl_gate_top_wire.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ctrl_gate_top_wire.png diff --git a/QPong/qpong/data/images/gate_images/h_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/h_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/h_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/h_gate.png diff --git a/QPong/qpong/data/images/gate_images/iden_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/iden_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/iden_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/iden_gate.png diff --git a/QPong/qpong/data/images/gate_images/not_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/not_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/not_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/not_gate.png diff --git a/QPong/qpong/data/images/gate_images/not_gate_above_ctrl.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/not_gate_above_ctrl.png similarity index 100% rename from QPong/qpong/data/images/gate_images/not_gate_above_ctrl.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/not_gate_above_ctrl.png diff --git a/QPong/qpong/data/images/gate_images/not_gate_below_ctrl.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/not_gate_below_ctrl.png similarity index 100% rename from QPong/qpong/data/images/gate_images/not_gate_below_ctrl.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/not_gate_below_ctrl.png diff --git a/QPong/qpong/data/images/gate_images/rx_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/rx_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/rx_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/rx_gate.png diff --git a/QPong/qpong/data/images/gate_images/ry_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ry_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/ry_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/ry_gate.png diff --git a/QPong/qpong/data/images/gate_images/rz_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/rz_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/rz_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/rz_gate.png diff --git a/QPong/qpong/data/images/gate_images/s_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/s_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/s_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/s_gate.png diff --git a/QPong/qpong/data/images/gate_images/sdg_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/sdg_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/sdg_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/sdg_gate.png diff --git a/QPong/qpong/data/images/gate_images/swap_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/swap_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/swap_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/swap_gate.png diff --git a/QPong/qpong/data/images/gate_images/t_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/t_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/t_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/t_gate.png diff --git a/QPong/qpong/data/images/gate_images/tdg_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/tdg_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/tdg_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/tdg_gate.png diff --git a/QPong/qpong/data/images/gate_images/trace_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/trace_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/trace_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/trace_gate.png diff --git a/QPong/qpong/data/images/gate_images/transparent.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/transparent.png similarity index 100% rename from QPong/qpong/data/images/gate_images/transparent.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/transparent.png diff --git a/QPong/qpong/data/images/gate_images/x_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/x_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/x_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/x_gate.png diff --git a/QPong/qpong/data/images/gate_images/y_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/y_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/y_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/y_gate.png diff --git a/QPong/qpong/data/images/gate_images/z_gate.png b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/z_gate.png similarity index 100% rename from QPong/qpong/data/images/gate_images/z_gate.png rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/images/gate_images/z_gate.png diff --git a/QPong/qpong/data/sound/4384__noisecollector__pongblipd4.wav b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/sound/4384__noisecollector__pongblipd4.wav similarity index 100% rename from QPong/qpong/data/sound/4384__noisecollector__pongblipd4.wav rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/sound/4384__noisecollector__pongblipd4.wav diff --git a/QPong/qpong/data/sound/4390__noisecollector__pongblipf-4.wav b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/sound/4390__noisecollector__pongblipf-4.wav similarity index 100% rename from QPong/qpong/data/sound/4390__noisecollector__pongblipf-4.wav rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/sound/4390__noisecollector__pongblipf-4.wav diff --git a/QPong/qpong/data/sound/4391__noisecollector__pongblipf-5.wav b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/sound/4391__noisecollector__pongblipf-5.wav similarity index 100% rename from QPong/qpong/data/sound/4391__noisecollector__pongblipf-5.wav rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/data/sound/4391__noisecollector__pongblipf-5.wav diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/.DS_Store new file mode 100644 index 00000000..8d6f3c7b Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/.DS_Store differ diff --git a/QPong/qpong/model/__init__.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__init__.py similarity index 100% rename from QPong/qpong/model/__init__.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__init__.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/__init__.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..4e6afc13 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/__init__.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/__init__.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 00000000..14fcbeac Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/__init__.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_grid_model.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_grid_model.cpython-311.pyc new file mode 100644 index 00000000..59bdf753 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_grid_model.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_grid_model.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_grid_model.cpython-313.pyc new file mode 100644 index 00000000..a47982b5 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_grid_model.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_node_types.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_node_types.cpython-311.pyc new file mode 100644 index 00000000..582a3736 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_node_types.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_node_types.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_node_types.cpython-313.pyc new file mode 100644 index 00000000..dc34ea00 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/__pycache__/circuit_node_types.cpython-313.pyc differ diff --git a/QPong/qpong/model/circuit_grid_model.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/circuit_grid_model.py similarity index 98% rename from QPong/qpong/model/circuit_grid_model.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/circuit_grid_model.py index 6a58a5cb..1790b069 100644 --- a/QPong/qpong/model/circuit_grid_model.py +++ b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/circuit_grid_model.py @@ -44,10 +44,10 @@ class CircuitGridModel: """ def __init__(self, max_wires, max_columns): - self.max_wires = max_wires + self.max_wires = 5 self.max_columns = max_columns self.nodes = np.full( - (max_wires, max_columns), + (self.max_wires, max_columns), CircuitGridNode(node_types.EMPTY), dtype=CircuitGridNode, ) diff --git a/QPong/qpong/model/circuit_node_types.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/circuit_node_types.py similarity index 100% rename from QPong/qpong/model/circuit_node_types.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/model/circuit_node_types.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/.DS_Store new file mode 100644 index 00000000..d71c102f Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/.DS_Store differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/colors.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/colors.cpython-311.pyc new file mode 100644 index 00000000..f11e36fb Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/colors.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/colors.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/colors.cpython-313.pyc new file mode 100644 index 00000000..fdf900d7 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/colors.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/font.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/font.cpython-311.pyc new file mode 100644 index 00000000..30f84b9e Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/font.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/font.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/font.cpython-313.pyc new file mode 100644 index 00000000..3ed1b1b9 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/font.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/input.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/input.cpython-311.pyc new file mode 100644 index 00000000..854f31ff Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/input.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/input.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/input.cpython-313.pyc new file mode 100644 index 00000000..456e310a Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/input.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/level.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/level.cpython-311.pyc new file mode 100644 index 00000000..a6854242 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/level.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/level.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/level.cpython-313.pyc new file mode 100644 index 00000000..6cb9d1dc Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/level.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/navigation.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/navigation.cpython-311.pyc new file mode 100644 index 00000000..34898d00 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/navigation.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/navigation.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/navigation.cpython-313.pyc new file mode 100644 index 00000000..b936341e Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/navigation.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/parameters.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/parameters.cpython-311.pyc new file mode 100644 index 00000000..d883ebcc Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/parameters.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/parameters.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/parameters.cpython-313.pyc new file mode 100644 index 00000000..362fd4c8 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/parameters.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/resources.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/resources.cpython-311.pyc new file mode 100644 index 00000000..29a57abf Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/resources.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/resources.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/resources.cpython-313.pyc new file mode 100644 index 00000000..0ccebf41 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/resources.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/scene.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/scene.cpython-311.pyc new file mode 100644 index 00000000..d3c6c287 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/scene.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/scene.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/scene.cpython-313.pyc new file mode 100644 index 00000000..83b5af30 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/scene.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/states.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/states.cpython-311.pyc new file mode 100644 index 00000000..85134658 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/states.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/states.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/states.cpython-313.pyc new file mode 100644 index 00000000..614fc244 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/__pycache__/states.cpython-313.pyc differ diff --git a/QPong/qpong/utils/colors.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/colors.py similarity index 100% rename from QPong/qpong/utils/colors.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/colors.py diff --git a/QPong/qpong/utils/font.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/font.py similarity index 100% rename from QPong/qpong/utils/font.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/font.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/input.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/input.py new file mode 100644 index 00000000..8cf63b8c --- /dev/null +++ b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/input.py @@ -0,0 +1,118 @@ +# +# Copyright 2022 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +""" +Quantum player input events and control +""" + +import numpy as np + +import pygame + +from qpong.utils.navigation import MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT + + +class Input: + """ + Handle input events + """ + + def __init__(self): + self.running = True + + def handle_input(self, level, screen, scene): + # pylint: disable=too-many-branches disable=too-many-statements + """ + Handle quantum player input + """ + + circuit_grid = level.circuit_grid + + # Handle Input Events + for event in pygame.event.get(): + pygame.event.pump() + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + self.running = False + elif event.key == pygame.K_a: + circuit_grid.move_to_adjacent_node(MOVE_LEFT) + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_d: + circuit_grid.move_to_adjacent_node(MOVE_RIGHT) + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_w: + circuit_grid.move_to_adjacent_node(MOVE_UP) + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_s: + circuit_grid.move_to_adjacent_node(MOVE_DOWN) + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_x: + circuit_grid.handle_input_x() + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_y: + circuit_grid.handle_input_y() + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_z: + circuit_grid.handle_input_z() + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_h: + circuit_grid.handle_input_h() + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_SPACE: + circuit_grid.handle_input_delete() + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_c: + # Add or remove a control + circuit_grid.handle_input_ctrl() + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_UP: + # Move a control qubit up + circuit_grid.handle_input_move_ctrl(MOVE_UP) + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_DOWN: + # Move a control qubit down + circuit_grid.handle_input_move_ctrl(MOVE_DOWN) + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_LEFT: + # Rotate a gate + circuit_grid.handle_input_rotate(-np.pi / 8) + circuit_grid.draw(screen) + pygame.display.flip() + elif event.key == pygame.K_RIGHT: + # Rotate a gate + circuit_grid.handle_input_rotate(np.pi / 8) + circuit_grid.draw(screen) + pygame.display.flip() + @staticmethod + def move_update_circuit_grid_display(screen, circuit_grid, direction): + """ + Update circuit grid after move + """ + circuit_grid.move_to_adjacent_node(direction) + circuit_grid.draw(screen) + pygame.display.flip() diff --git a/QPong/qpong/utils/level.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/level.py similarity index 55% rename from QPong/qpong/utils/level.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/level.py index 176a9d1b..b11a062a 100644 --- a/QPong/qpong/utils/level.py +++ b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/level.py @@ -38,13 +38,15 @@ def __init__(self): self.win = False # flag for winning the game self.left_paddle = pygame.sprite.Sprite() self.right_paddle = pygame.sprite.Sprite() - self.circuit = None - self.circuit_grid = None - self.circuit_grid_model = None - self.statevector_grid = None - self.right_statevector = None + self.circuit_grid_model = CircuitGridModel(5, CIRCUIT_DEPTH) + self.circuit = self.circuit_grid_model.construct_circuit() + self.circuit_grid = CircuitGrid(0, 500, self.circuit_grid_model) + self.statevector_grid = StatevectorGrid(self.circuit, 5) + self.right_statevector = VBox( + WIDTH_UNIT * 90, WIDTH_UNIT * 0, self.statevector_grid + ) - def setup(self, scene, ball): + def setup(self, scene): """ Setup a level with a certain level number """ @@ -56,34 +58,7 @@ def setup(self, scene, ball): self.right_statevector = VBox( WIDTH_UNIT * 90, WIDTH_UNIT * 0, self.statevector_grid ) - self.circuit_grid = CircuitGrid(0, ball.screenheight, self.circuit_grid_model) + self.circuit_grid = CircuitGrid(0, 500, self.circuit_grid_model) # computer paddle - self.left_paddle.image = pygame.Surface( - [WIDTH_UNIT, int(round(ball.screenheight / 2**scene.qubit_num))] - ) - self.left_paddle.image.fill((255, 255, 255)) - self.left_paddle.image.set_alpha(255) - self.left_paddle.rect = self.left_paddle.image.get_rect() - self.left_paddle.rect.x = 9 * WIDTH_UNIT - - # player paddle for detection of collision. It is invisible on the screen - - self.right_paddle.image = pygame.Surface( - [WIDTH_UNIT, int(round(ball.screenheight / 2**scene.qubit_num))] - ) - self.right_paddle.image.fill((255, 255, 255)) - self.right_paddle.image.set_alpha(0) - self.right_paddle.rect = self.right_paddle.image.get_rect() - self.right_paddle.rect.x = self.right_statevector.xpos - - def levelup(self): - """ - Increase level by 1 - """ - if self.level <= 3: - self.level += self.level - # self.setup() - else: - self.win = True # win the game if level is higher than 3 diff --git a/QPong/qpong/utils/navigation.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/navigation.py similarity index 100% rename from QPong/qpong/utils/navigation.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/navigation.py diff --git a/QPong/qpong/utils/parameters.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/parameters.py similarity index 100% rename from QPong/qpong/utils/parameters.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/parameters.py diff --git a/QPong/qpong/utils/resources.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/resources.py similarity index 100% rename from QPong/qpong/utils/resources.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/resources.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/scene.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/scene.py new file mode 100644 index 00000000..5ce42f1c --- /dev/null +++ b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/scene.py @@ -0,0 +1,173 @@ +# +# Copyright 2022 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +""" +A container for managing game screens +""" + +import pygame + +from qpong.utils.parameters import ( + WIDTH_UNIT, + WINDOW_WIDTH, + WINDOW_HEIGHT, + QUANTUM_COMPUTER, + CLASSICAL_COMPUTER, + EASY, + NORMAL, + EXPERT, +) +from qpong.utils.colors import WHITE, BLACK, GRAY +from qpong.utils.font import Font + + +class Scene: + """ + Display Game Over screen and handle play again + """ + + def __init__(self): + super().__init__() + + self.begin = False + self.restart = False + self.qubit_num = 3 + self.font = Font() + + def start(self, screen): + # pylint: disable=too-many-branches disable=too-many-return-statements + """ + Show start screen + """ + + screen.fill(WHITE) + + gameover_text = "Quantum Composer" + text = self.font.gameover_font.render(gameover_text, 1, WHITE) + text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 15)) + screen.blit(text, text_pos) + + gameover_text = "[A] Start" + text = self.font.replay_font.render(gameover_text, 5, WHITE) + text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 35)) + screen.blit(text, text_pos) + + self.credits(screen) + + while not self.begin: + + for event in pygame.event.get(): + pygame.event.pump() + + if event.type == pygame.QUIT: + pygame.quit() + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + return False + if event.key == pygame.K_a: + # start + return True + + if self.begin: + # reset all parameters to restart the game + # + # screen.fill(BLACK) + pass + + pygame.display.flip() + + # reset restart flag when self.restart = True and the while ends + self.begin = False + + def gameover(self, screen, player): + """ + Display Game Over screen + """ + if player == CLASSICAL_COMPUTER: + + + gameover_text = "Game Over" + text = self.font.gameover_font.render(gameover_text, 1, WHITE) + text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 10)) + screen.blit(text, text_pos) + + def credits(self, screen): + """ + Show credits screen + """ + credit_text = "Credits" + text = self.font.credit_font.render(credit_text, 1, WHITE) + text_pos = text.get_rect( + center=(WINDOW_WIDTH / 2, WINDOW_HEIGHT - WIDTH_UNIT * 8) + ) + screen.blit(text, text_pos) + + credit_text = ( + "Made by Austine, Atharv, and Devesh" + ) + text = self.font.credit_font.render(credit_text, 1, WHITE) + text_pos = text.get_rect( + center=(WINDOW_WIDTH / 2, WINDOW_HEIGHT - WIDTH_UNIT * 5) + ) + screen.blit(text, text_pos) + + def replay(self, screen, circuit_grid_model, circuit_grid): + """ + Pause the game and ask if the player wants to play again + """ + blink_time = pygame.time.get_ticks() + + while not self.restart: + + for event in pygame.event.get(): + pygame.event.pump() + + if event.type == pygame.QUIT: + pygame.quit() + else: + self.restart = True + + if self.restart: + # reset all parameters to restart the game + circuit_grid_model.reset_circuit() + circuit_grid.update() + circuit_grid.reset_cursor() + + # Make blinking text + if pygame.time.get_ticks() - blink_time > 1000: + blink_time = pygame.time.get_ticks() + if pygame.time.get_ticks() - blink_time > 500: + replay_text = "Press Any Key to Play Again" + text = self.font.replay_font.render(replay_text, 1, WHITE) + text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 40)) + screen.blit(text, text_pos) + pygame.display.flip() + else: + # show a black box to blink the text every 0.5s + pygame.draw.rect( + screen, + WHITE, + ( + WIDTH_UNIT * 10, + WIDTH_UNIT * 35, + WIDTH_UNIT * 80, + WIDTH_UNIT * 10, + ), + ) + pygame.display.flip() + + # reset restart flag when self.restart = True and the while ends + self.restart = False diff --git a/QPong/qpong/utils/states.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/states.py similarity index 100% rename from QPong/qpong/utils/states.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/utils/states.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/.DS_Store b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/.DS_Store new file mode 100644 index 00000000..53ae6932 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/.DS_Store differ diff --git a/QPong/qpong/viz/__init__.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__init__.py similarity index 100% rename from QPong/qpong/viz/__init__.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__init__.py diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/__init__.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..c7a5d5cf Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/__init__.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/__init__.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 00000000..42425cc3 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/__init__.cpython-313.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/statevector_grid.cpython-311.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/statevector_grid.cpython-311.pyc new file mode 100644 index 00000000..61748841 Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/statevector_grid.cpython-311.pyc differ diff --git a/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/statevector_grid.cpython-313.pyc b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/statevector_grid.cpython-313.pyc new file mode 100644 index 00000000..23bbf4ab Binary files /dev/null and b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/__pycache__/statevector_grid.cpython-313.pyc differ diff --git a/QPong/qpong/viz/statevector_grid.py b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/statevector_grid.py similarity index 58% rename from QPong/qpong/viz/statevector_grid.py rename to DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/statevector_grid.py index 404956b9..b365959d 100755 --- a/QPong/qpong/viz/statevector_grid.py +++ b/DeveshAustineAtharv/DeveshAtharvAustine/qpong/viz/statevector_grid.py @@ -25,7 +25,6 @@ from qpong.utils.colors import WHITE, BLACK from qpong.utils.parameters import WIDTH_UNIT from qpong.utils.states import comp_basis_states -from qpong.utils.ball import Ball from qpong.utils.font import Font @@ -38,18 +37,11 @@ def __init__(self, circuit, qubit_num): pygame.sprite.Sprite.__init__(self) self.image = None self.rect = None - self.ball = Ball() self.font = Font() - self.block_size = int(round(self.ball.screenheight / 2**qubit_num)) + self.block_size = int(round(500 / 2**qubit_num)) self.basis_states = comp_basis_states(circuit.width()) self.circuit = circuit - self.paddle = pygame.Surface([WIDTH_UNIT, self.block_size]) - self.paddle.fill(WHITE) - self.paddle.convert() - - self.paddle_before_measurement(circuit, qubit_num) - def display_statevector(self, qubit_num): """ Draw computational basis for a statevector of a specified @@ -62,42 +54,23 @@ def display_statevector(self, qubit_num): text_height = text.get_height() y_offset = self.block_size * 0.5 - text_height * 0.5 self.image.blit(text, (2 * WIDTH_UNIT, qb_idx * self.block_size + y_offset)) - - def paddle_before_measurement(self, circuit, qubit_num): + + def print_statevector(self, qubit_num): """ - Get statevector from circuit, and set the - paddle(s) alpha values according to basis - state(s) probabilitie(s) - """ - self.update() - self.display_statevector(qubit_num) - quantum_state = Statevector(circuit) - - for basis_state, ampl in enumerate(quantum_state): - self.paddle.set_alpha(int(round(abs(ampl) ** 2 * 255))) - self.image.blit(self.paddle, (0, basis_state * self.block_size)) - - def paddle_after_measurement(self, circuit, qubit_num): - """ - Measure all qubits on circuit + Print computational basis for a statevector of a specified + number of qubits """ - self.update() - self.display_statevector(qubit_num) - measurement_bitstring = Statevector(circuit).sample_memory(1)[0] - measurement_int = int(measurement_bitstring, 2) - - self.paddle.set_alpha(255) - self.image.blit(self.paddle, (0, measurement_int * self.block_size)) - - return measurement_int + for qb_idx in range(2**qubit_num): + text = "|" + self.basis_states[qb_idx] + ">", 1, WHITE + print(text) def update(self): """ Update statevector grid """ self.image = pygame.Surface( - [(self.circuit.width() + 1) * 3 * WIDTH_UNIT, self.ball.screenheight] + [(self.circuit.width() + 1) * 3 * WIDTH_UNIT, 500] ) self.image.convert() - self.image.fill(BLACK) + self.image.fill(WHITE) self.rect = self.image.get_rect() diff --git a/QPong/.coveragerc b/QPong/.coveragerc deleted file mode 100644 index fb376c41..00000000 --- a/QPong/.coveragerc +++ /dev/null @@ -1,8 +0,0 @@ -[run] -omit = - # omit template files - .tox/* - .py3*/* - lint/* - coverage/* - .github/* diff --git a/QPong/.gitignore b/QPong/.gitignore deleted file mode 100644 index 55a5227a..00000000 --- a/QPong/.gitignore +++ /dev/null @@ -1,134 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -.idea/ - -# macos finder -.DS_Store diff --git a/QPong/.pylintrc b/QPong/.pylintrc deleted file mode 100644 index e004f39e..00000000 --- a/QPong/.pylintrc +++ /dev/null @@ -1,623 +0,0 @@ -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code. -extension-pkg-allow-list= - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code. (This is an alternative name to extension-pkg-allow-list -# for backward compatibility.) -extension-pkg-whitelist= - -# Return non-zero exit code if any of these messages/categories are detected, -# even if score is above --fail-under value. Syntax same as enable. Messages -# specified are enabled, while categories only check already-enabled messages. -fail-on= - -# Specify a score threshold to be exceeded before program exits with error. -fail-under=10.0 - -# Files or directories to be skipped. They should be base names, not paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against paths. -ignore-paths= - -# Files or directories matching the regex patterns are skipped. The regex -# matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the -# number of processors available to use. -jobs=1 - -# Control the amount of potential inferred values when inferring a single -# object. This can help the performance when dealing with large functions or -# complex, nested conditions. -limit-inference-results=100 - -# List of plugins (as comma separated values of python module names) to load, -# usually to register additional checkers. -load-plugins= - -# Pickle collected data for later comparisons. -persistent=yes - -# When enabled, pylint would attempt to guess common misconfiguration and emit -# user-friendly hints instead of false-positive error messages. -suggestion-mode=yes - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED. -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once). You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use "--disable=all --enable=classes -# --disable=W". -disable=print-statement, - parameter-unpacking, - unpacking-in-except, - old-raise-syntax, - backtick, - long-suffix, - old-ne-operator, - old-octal-literal, - import-star-module-level, - non-ascii-bytes-literal, - raw-checker-failed, - bad-inline-option, - locally-disabled, - file-ignored, - suppressed-message, - useless-suppression, - deprecated-pragma, - use-symbolic-message-instead, - apply-builtin, - basestring-builtin, - buffer-builtin, - cmp-builtin, - coerce-builtin, - execfile-builtin, - file-builtin, - long-builtin, - raw_input-builtin, - reduce-builtin, - standarderror-builtin, - unicode-builtin, - xrange-builtin, - coerce-method, - delslice-method, - getslice-method, - setslice-method, - no-absolute-import, - old-division, - dict-iter-method, - dict-view-method, - next-method-called, - metaclass-assignment, - indexing-exception, - raising-string, - reload-builtin, - oct-method, - hex-method, - nonzero-method, - cmp-method, - input-builtin, - round-builtin, - intern-builtin, - unichr-builtin, - map-builtin-not-iterating, - zip-builtin-not-iterating, - range-builtin-not-iterating, - filter-builtin-not-iterating, - using-cmp-argument, - eq-without-hash, - div-method, - idiv-method, - rdiv-method, - exception-message-attribute, - invalid-str-codec, - sys-max-int, - bad-python3-import, - deprecated-string-function, - deprecated-str-translate-call, - deprecated-itertools-function, - deprecated-types-field, - next-method-defined, - dict-items-not-iterating, - dict-keys-not-iterating, - dict-values-not-iterating, - deprecated-operator-function, - deprecated-urllib-function, - xreadlines-attribute, - deprecated-sys-function, - exception-escape, - comprehension-escape - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable=c-extension-no-member - - -[REPORTS] - -# Python expression which should return a score less than or equal to 10. You -# have access to the variables 'error', 'warning', 'refactor', and 'convention' -# which contain the number of messages in each category, as well as 'statement' -# which is the total number of statements analyzed. This score is used by the -# global evaluation report (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details. -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio). You can also give a reporter class, e.g. -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages. -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - -# Complete name of functions that never returns. When checking for -# inconsistent-return-statements if a never returning function is called then -# it will be considered as an explicit return statement and no message will be -# printed. -never-returning-functions=sys.exit,argparse.parse_error - - -[LOGGING] - -# The type of string formatting that logging methods do. `old` means using % -# formatting, `new` is for `{}` formatting. -logging-format-style=old - -# Logging modules to check that the string format arguments are in logging -# function parameter format. -logging-modules=logging - - -[SPELLING] - -# Limits count of emitted suggestions for spelling mistakes. -max-spelling-suggestions=4 - -# Spelling dictionary name. Available dictionaries: none. To make it work, -# install the 'python-enchant' package. -spelling-dict= - -# List of comma separated words that should be considered directives if they -# appear and the beginning of a comment and should not be checked. -spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains the private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to the private dictionary (see the -# --spelling-private-dict-file option) instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -notes=FIXME, - XXX, - TODO - -# Regular expression of note tags to take in consideration. -#notes-rgx= - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members=math.*,pygame.* - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# Tells whether to warn about missing members when the owner of the attribute -# is inferred to be None. -ignore-none=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis). It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules= - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - -# List of decorators that change the signature of a decorated function. -signature-mutators= - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid defining new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of names allowed to shadow builtins -allowed-redefined-builtins= - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_, - _cb - -# A regular expression matching the name of dummy variables (i.e. expected to -# not be used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore. -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format= - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module. -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=no - -# Ignore function signatures when computing similarities. -ignore-signatures=no - -# Minimum lines number of a similarity. -min-similarity-lines=4 - - -[BASIC] - -# Naming style matching correct argument names. -argument-naming-style=snake_case - -# Regular expression matching correct argument names. Overrides argument- -# naming-style. -#argument-rgx= - -# Naming style matching correct attribute names. -attr-naming-style=snake_case - -# Regular expression matching correct attribute names. Overrides attr-naming- -# style. -#attr-rgx= - -# Bad variable names which should always be refused, separated by a comma. -bad-names=foo, - bar, - baz, - toto, - tutu, - tata - -# Bad variable names regexes, separated by a comma. If names match any regex, -# they will always be refused -bad-names-rgxs= - -# Naming style matching correct class attribute names. -class-attribute-naming-style=any - -# Regular expression matching correct class attribute names. Overrides class- -# attribute-naming-style. -#class-attribute-rgx= - -# Naming style matching correct class constant names. -class-const-naming-style=UPPER_CASE - -# Regular expression matching correct class constant names. Overrides class- -# const-naming-style. -#class-const-rgx= - -# Naming style matching correct class names. -class-naming-style=PascalCase - -# Regular expression matching correct class names. Overrides class-naming- -# style. -#class-rgx= - -# Naming style matching correct constant names. -const-naming-style=UPPER_CASE - -# Regular expression matching correct constant names. Overrides const-naming- -# style. -#const-rgx= - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Naming style matching correct function names. -function-naming-style=snake_case - -# Regular expression matching correct function names. Overrides function- -# naming-style. -#function-rgx= - -# Good variable names which should always be accepted, separated by a comma. -good-names=i, - j, - k, - ex, - Run, - _ - -# Good variable names regexes, separated by a comma. If names match any regex, -# they will always be accepted -good-names-rgxs= - -# Include a hint for the correct naming format with invalid-name. -include-naming-hint=no - -# Naming style matching correct inline iteration names. -inlinevar-naming-style=any - -# Regular expression matching correct inline iteration names. Overrides -# inlinevar-naming-style. -#inlinevar-rgx= - -# Naming style matching correct method names. -method-naming-style=snake_case - -# Regular expression matching correct method names. Overrides method-naming- -# style. -#method-rgx= - -# Naming style matching correct module names. -module-naming-style=snake_case - -# Regular expression matching correct module names. Overrides module-naming- -# style. -#module-rgx= - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -# These decorators are taken in consideration only for invalid-name. -property-classes=abc.abstractproperty - -# Naming style matching correct variable names. -variable-naming-style=snake_case - -# Regular expression matching correct variable names. Overrides variable- -# naming-style. -#variable-rgx= - - -[STRING] - -# This flag controls whether inconsistent-quotes generates a warning when the -# character used as a quote delimiter is used inconsistently within a module. -check-quote-consistency=no - -# This flag controls whether the implicit-str-concat should generate a warning -# on implicit string concatenation in sequences defined over several lines. -check-str-concat-over-line-jumps=no - - -[IMPORTS] - -# List of modules that can be imported at any level, not just the top level -# one. -allow-any-import-level= - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma. -deprecated-modules= - -# Output a graph (.gv or any supported image format) of external dependencies -# to the given file (report RP0402 must not be disabled). -ext-import-graph= - -# Output a graph (.gv or any supported image format) of all (i.e. internal and -# external) dependencies to the given file (report RP0402 must not be -# disabled). -import-graph= - -# Output a graph (.gv or any supported image format) of internal dependencies -# to the given file (report RP0402 must not be disabled). -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - -# Couples of modules and preferred modules, separated by a comma. -preferred-modules= - - -[CLASSES] - -# Warn about protected attribute access inside special methods -check-protected-access-in-special-methods=no - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__, - __new__, - setUp, - __post_init__ - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict, - _fields, - _replace, - _source, - _make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=cls - - -[DESIGN] - -# Maximum number of arguments for function / method. -max-args=20 - -# Maximum number of attributes for a class (see R0902). -max-attributes=14 - -# Maximum number of boolean expressions in an if statement (see R0916). -max-bool-expr=5 - -# Maximum number of branch for function / method body. -max-branches=12 - -# Maximum number of locals for function / method body. -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body. -max-returns=6 - -# Maximum number of statements in function / method body. -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=2 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "BaseException, Exception". -overgeneral-exceptions=BaseException, - Exception diff --git a/QPong/LICENSE b/QPong/LICENSE deleted file mode 100644 index 261eeb9e..00000000 --- a/QPong/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/QPong/README.md b/QPong/README.md deleted file mode 100644 index 0d6c0aa2..00000000 --- a/QPong/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# QPong -This is a quantum version of classic game Pong using IBM Qiskit and PyGame. This game was initiated in IBM Qiskit Camp 2019 by Huang Junye, Jarrod Reilly, Anastasia Jeffery and James Weaver based on James Weaver's quantum-circuit-pygame package: https://github.com/JavaFXpert/quantum-circuit-pygame - -**NEW!** Unity version is being actively developed over here: https://github.com/HuangJunye/QPong-Unity - -## Story -In the dawn of the Quantum Era, a primitive 3-qubit Quantum Computer is trying to challenge the Classical Computer, the long-time ruler of the Computer Empire. Your mission is to use your Human Intelligence to help the Quantum Computer defeat the Classical Computer and demonstrate "quantum supremacy" for the first time in human history. The battle field of the Quantum-Classic war is none other than the classic Pong game. - -## Installation -To play the game, you will need to install Python and three required packages. To do that, you need to use command line tool (Command Prompt for Windows or Terminal for macOS). - -### Open command line tool - -On Windows, open Command Prompt by typing "Command Prompt" on the search box of Start menu. Check this link if you are not sure about how to do that: https://www.wikihow.com/Open-the-Command-Prompt-in-Windows - -On macOS, press Command + Space to open Spotlight. Type "Terminal" on Spotlight to open Terminal. Check this link if you are not sure about how to do that: https://www.wikihow.com/Open-a-Terminal-Window-in-Mac - -### Install Python -You can install Python from https://www.python.org/ or install Anaconda from https://www.anaconda.com - -### Install required packages -There are three Python packages required to run the game: PyGame, Qiskit and matplotlib. - -Run `pip install [package name]` on command line tool (same for Windows and macOS) to install the packages. For example: -```console -pip install pygame -``` -### Install QPong - -Clone or download the master branch by clicking the green button on the top right corner on this page (above the files and below "contributors"). Unzip the files to the "Downloads" folder on your computer. - -Change the directory to the downloaded files. (Downloads/QPong-master) - -On Windows, run the following code to change your directory to the QPong folder: -```console -cd C:\users\[your username]\downloads\QPong-main\ -``` -On macOS, run the following code to change your directory to the QPong folder: -```console -cd Downloads/QPong-main/ -``` - -On both Windows and macOS, run the following command to start the game: -```console -python main.py -``` - -## How to play - -### Keyboard -W, A, S, D: Up, Left, Down, Right to move cursor - -SPACE: delete gate - -X, Y, Z, H: add Pauli-X, Pauli-Y, Pauli-Z, Hadamard gate - -C: add CNOT gate - -UP, DOWN: move control qubit up or down - -Left, Right: add rotation to a gate, at pi/8 step - -TAB: update visulization - - -### Joystick -Joystick button correspondence depends on the model of joystick. Details will be added later - -## Credits -Sound effects are made by NoiseCollector from Freesound.org: https://freesound.org/people/NoiseCollector/packs/254/ -Font used in the game is Bit5x3 made by Matt LaGrandeur: http://www.mattlag.com/bitfonts/ diff --git a/QPong/ecosystem.json b/QPong/ecosystem.json deleted file mode 100644 index 716b1ffc..00000000 --- a/QPong/ecosystem.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "dependencies_files": [ - "requirements.txt", - "requirements-dev.txt" - ], - "extra_dependencies": [ - "pytest" - ], - "language": { - "name": "python", - "versions": ["3.9"] - }, - "tests_command": [ - "pytest" - ], - "styles_check_command": [ - "pylint -rn qpong tests" - ], - "coverages_check_command": [ - "coverage3 run -m pytest", - "coverage3 report --fail-under=80" - ], - "qiskit": true -} diff --git a/QPong/main.py b/QPong/main.py deleted file mode 100644 index 6b10c632..00000000 --- a/QPong/main.py +++ /dev/null @@ -1,178 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# - -""" -Quantum version of the classic Pong game -""" - -import random - -import pygame -from pygame import DOUBLEBUF, HWSURFACE, FULLSCREEN - -from qpong.utils.ball import Ball -from qpong.utils.input import Input -from qpong.utils.level import Level -from qpong.utils.scene import Scene -from qpong.utils.parameters import ( - WINDOW_SIZE, - CLASSICAL_COMPUTER, - QUANTUM_COMPUTER, - WIN_SCORE, - WIDTH_UNIT, - MEASURE_RIGHT, -) -from qpong.utils.colors import BLACK - - -def main(): - """ - Main game loop - """ - - if not pygame.get_init(): - print("Warning, fonts disabled") - pygame.init() - - if not pygame.font.get_init(): - print("Warning, fonts disabled") - pygame.font.init() - - if not pygame.mixer.get_init(): - print("Warning, sound disabled") - pygame.mixer.init() - - # hardware acceleration to reduce flickering. Works only in full screen - flags = DOUBLEBUF | HWSURFACE | FULLSCREEN - screen = pygame.display.set_mode(WINDOW_SIZE, flags) - - pygame.display.set_caption("QPong") - - # clock for timing - clock = pygame.time.Clock() - old_clock = pygame.time.get_ticks() - - # initialize scene, level and input Classes - scene = Scene() - level = Level() - input = Input() - - # define ball - ball = Ball() - balls = ( - pygame.sprite.Group() - ) # sprite group type is needed for sprite collide function in pygame - balls.add(ball) - - # Show start screen to select difficulty - input.running = scene.start(screen, ball) # start screen returns running flag - level.setup(scene, ball) - - # Put all moving sprites a group so that they can be drawn together - moving_sprites = pygame.sprite.Group() - moving_sprites.add(ball) - moving_sprites.add(level.left_paddle) - moving_sprites.add(level.right_paddle) - - # update the screen - pygame.display.flip() - - # reset the ball - ball.reset() - - # a valuable to record the time when the paddle is measured - measure_time = 100000 - - # Main Loop - while input.running: - # set maximum frame rate - clock.tick(60) - # refill whole screen with black color at each frame - screen.fill(BLACK) - - ball.update() # update ball position - scene.dashed_line(screen, ball) # draw dashed line in the middle of the screen - scene.score(screen, ball) # print score - - # level.statevector_grid.display_statevector(scene.qubit_num) # generate statevector grid - level.right_statevector.draw( - screen - ) # draw right paddle together with statevector grid - level.circuit_grid.draw(screen) # draw circuit grid - moving_sprites.draw(screen) # draw moving sprites - - # Show game over screen if the score reaches WIN_SCORE, reset everything if replay == TRUE - if ball.score.get_score(CLASSICAL_COMPUTER) >= WIN_SCORE: - scene.gameover(screen, CLASSICAL_COMPUTER) - scene.replay( - screen, ball.score, level.circuit_grid_model, level.circuit_grid - ) - input.update_paddle(level, screen, scene) - - if ball.score.get_score(QUANTUM_COMPUTER) >= WIN_SCORE: - scene.gameover(screen, QUANTUM_COMPUTER) - scene.replay( - screen, ball.score, level.circuit_grid_model, level.circuit_grid - ) - input.update_paddle(level, screen, scene) - - # computer paddle movement - if pygame.time.get_ticks() - old_clock > 300: - level.left_paddle.rect.y = ( - ball.get_ypos() - - level.statevector_grid.block_size / 2 - + random.randint(-WIDTH_UNIT * 4, WIDTH_UNIT * 4) - ) - old_clock = pygame.time.get_ticks() - - # handle input events - input.handle_input(level, screen, scene) - - # check ball location and decide what to do - ball.action() - - if ball.ball_action == MEASURE_RIGHT: - circuit = level.circuit_grid_model.construct_circuit() - pos = level.statevector_grid.paddle_after_measurement( - circuit, scene.qubit_num - ) - level.right_statevector.arrange() - - # paddle after measurement - level.right_paddle.rect.y = pos * ball.screenheight / (2**scene.qubit_num) - measure_time = pygame.time.get_ticks() - - if pygame.sprite.spritecollide(level.right_paddle, balls, False): - ball.bounce_edge() - - if pygame.sprite.spritecollide(level.left_paddle, balls, False): - ball.bounce_edge() - - if pygame.time.get_ticks() - measure_time > 400: - # refresh the screen a moment after measurement to update visual - input.update_paddle(level, screen, scene) - # add a buffer time before measure again - measure_time = pygame.time.get_ticks() + 100000 - - # Update the screen - pygame.display.flip() - - pygame.quit() - - -if __name__ == "__main__": - main() diff --git a/QPong/qpong/VERSION.txt b/QPong/qpong/VERSION.txt deleted file mode 100644 index 9084fa2f..00000000 --- a/QPong/qpong/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -1.1.0 diff --git a/QPong/qpong/__init__.py b/QPong/qpong/__init__.py deleted file mode 100644 index d5592e70..00000000 --- a/QPong/qpong/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -QPong game -""" - -import os - -from .containers import * -from .utils import * -from .viz import * -from .model import * -from .controls import * - -with open( - os.path.abspath(os.path.join(os.path.dirname(__file__), "VERSION.txt")), "r" -) as _ver_file: - __version__ = _ver_file.read().rstrip() diff --git a/QPong/qpong/utils/__init__.py b/QPong/qpong/utils/__init__.py deleted file mode 100644 index cf2b7548..00000000 --- a/QPong/qpong/utils/__init__.py +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Utilities for loading resources and quantum states -""" - -from .ball import Ball -from .input import Input -from .level import Level -from .scene import Scene -from .score import Score -from .sound import Sound -from .font import Font - -from .colors import * -from .gamepad import * -from .parameters import * -from .navigation import * -from .resources import * -from .states import * diff --git a/QPong/qpong/utils/ball.py b/QPong/qpong/utils/ball.py deleted file mode 100644 index 0b9bb29a..00000000 --- a/QPong/qpong/utils/ball.py +++ /dev/null @@ -1,203 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -""" -A QPong ball -""" - -import math -import random - -import pygame - -from qpong.utils.colors import WHITE -from qpong.utils.parameters import ( - WIDTH_UNIT, - WINDOW_HEIGHT, - WINDOW_WIDTH, - LEFT, - RIGHT, - NOTHING, - NO, - YES, - MEASURE_LEFT, - MEASURE_RIGHT, -) -from qpong.utils.score import Score -from qpong.utils.sound import Sound - - -class Ball(pygame.sprite.Sprite): - """ - A QPong ball - """ - - # pylint: disable=too-many-instance-attributes - def __init__(self): - super().__init__() - - # get ball screen dimensions - self.screenheight = round(WINDOW_HEIGHT * 0.7) - self.screenwidth = WINDOW_WIDTH - self.width_unit = WIDTH_UNIT - - self.left_edge = self.width_unit - self.right_edge = self.screenwidth - self.left_edge - - self.top_edge = self.width_unit * 0 - self.bottom_edge = self.screenheight - self.top_edge - - # define the ball sizes - self.height = self.width_unit - self.width = self.width_unit - - # create a pygame Surface with ball size - self.image = pygame.Surface([self.height, self.width]) - - self.image.fill(WHITE) - - self.rect = self.image.get_rect() - - self.xpos = 0 - self.ypos = 0 - self.speed = 0 - self.initial_speed_factor = 0.8 - self.direction = 0 - - # initialize ball action type, measure and bounce flags - self.ball_action = NOTHING - self.measure_flag = NO - - # initialize ball reset on the left - self.reset_position = LEFT - self.reset() - - self.sound = Sound() - self.score = Score() - - def update(self): - """ - Update ball - """ - radians = math.radians(self.direction) - - self.xpos += self.speed * math.sin(radians) - self.ypos -= self.speed * math.cos(radians) - - # Update ball position - self.rect.x = self.xpos - self.rect.y = self.ypos - - if self.ypos <= self.top_edge: - self.direction = (180 - self.direction) % 360 - self.sound.edge_sound.play() - if self.ypos > self.bottom_edge - 1 * self.height: - self.direction = (180 - self.direction) % 360 - self.sound.edge_sound.play() - - def reset(self): - """ - Reset ball position and speed to initial settings. - """ - self.ypos = self.screenheight / 2 - self.speed = self.width_unit * self.initial_speed_factor - - # alternate reset at left and right - if self.reset_position == LEFT: - self.xpos = self.left_edge + self.width_unit * 15 - self.direction = random.randrange(30, 120) - self.reset_position = RIGHT - else: - self.xpos = self.right_edge - self.width_unit * 15 - self.direction = random.randrange(-120, -30) - self.reset_position = LEFT - - def bounce_edge(self): - """ - Bounce ball off a screen edge - """ - self.direction = (360 - self.direction) % 360 - self.speed *= 1.1 - self.sound.bounce_sound.play() - - def get_xpos(self): - """ - Get ball's x position - """ - xpos = self.xpos - return xpos - - def get_ypos(self): - """ - Get ball's y position - """ - ypos = self.ypos - return ypos - - # 1 = comp, 2 = player, none = 0 - def action(self): - """ - Decide ball action based on the ball's position - """ - if self.xpos < self.left_edge: - # reset the ball when it reaches beyond left edge - self.reset() - self.sound.lost_sound.play(3) - self.score.update(1) - - elif ( - self.left_edge + 10 * self.width_unit - <= self.xpos - < self.left_edge + 12 * self.width_unit - ): - # measure the ball when it reaches the left measurement zone - if self.measure_flag == NO: - self.ball_action = MEASURE_LEFT - self.measure_flag = YES - else: - self.ball_action = NOTHING - - elif ( - self.right_edge - 12 * self.width_unit - <= self.xpos - < self.right_edge - 10 * self.width_unit - ): - # measure the ball when it reaches the right measurement zone - if self.measure_flag == NO: - # do measurement if not yet done - self.ball_action = MEASURE_RIGHT - self.measure_flag = YES - else: - # do nothing if measurement was done already - self.ball_action = NOTHING - - elif self.xpos > self.right_edge: - # reset the ball when it reaches beyond right edge - self.reset() - self.sound.lost_sound.play(3) - self.score.update(0) - - else: - # reset flags and do nothing when the ball is outside measurement and bounce zone - self.ball_action = NOTHING - self.measure_flag = NO - - def check_score(self, player): - """ - Check a player score - """ - return self.score.get_score(player) diff --git a/QPong/qpong/utils/gamepad.py b/QPong/qpong/utils/gamepad.py deleted file mode 100644 index 4e0f3ee6..00000000 --- a/QPong/qpong/utils/gamepad.py +++ /dev/null @@ -1,49 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# - -""" -Gamepad button and axis mappings, currently specific to PS4 gamepads -""" - -BTN_X = 0 # PS4 gamepad is 3, PS3 gamepad is 2 -BTN_Y = 3 -BTN_A = 1 # PS4 gamepad is 1, PS3 gamepad is 3 -BTN_B = 2 - -BTN_LEFT_BUMPER = 4 -BTN_RIGHT_BUMPER = 5 - -BTN_LEFT_TRIGGER = 6 -BTN_RIGHT_TRIGGER = 7 - -BTN_SELECT = 8 -BTN_START = 9 - -BTN_LEFT_THUMB = 10 -BTN_RIGHT_THUMB = 11 - -BTN_HOME = 12 # Not present on PS3 -BTN_TOUCHPAD = 13 # Not present on PS3 - -AXIS_LEFT_THUMB_X = 0 -AXIS_LEFT_THUMB_Y = 1 - -AXIS_RIGHT_THUMB_X = 2 -AXIS_RIGHT_THUMB_Y = 3 - -AXIS_LEFT_TRIGGER = 4 # Not present on PS3 -AXIS_RIGHT_TRIGGER = 5 diff --git a/QPong/qpong/utils/input.py b/QPong/qpong/utils/input.py deleted file mode 100644 index cf46acd3..00000000 --- a/QPong/qpong/utils/input.py +++ /dev/null @@ -1,284 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Quantum player input events and control -""" - -import numpy as np - -import pygame - -from qpong.utils import gamepad -from qpong.utils.navigation import MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT - - -class Input: - """ - Handle input events - """ - - def __init__(self): - self.running = True - - if not pygame.joystick.get_init(): - pygame.joystick.init() - - self.num_joysticks = pygame.joystick.get_count() - if self.num_joysticks > 0: - self.joystick = pygame.joystick.Joystick(0) - if not self.joystick.get_init(): - self.joystick.init() - - self.gamepad_repeat_delay = 200 - self.gamepad_neutral = True - self.gamepad_pressed_timer = 0 - self.gamepad_last_update = pygame.time.get_ticks() - - def handle_input(self, level, screen, scene): - # pylint: disable=too-many-branches disable=too-many-statements - """ - Handle quantum player input - """ - - gamepad_move = False - circuit_grid = level.circuit_grid - - # use joystick if it's connected - if self.num_joysticks > 0: - joystick_hat = self.joystick.get_hat(0) - - if joystick_hat == (0, 0): - self.gamepad_neutral = True - self.gamepad_pressed_timer = 0 - else: - if self.gamepad_neutral: - gamepad_move = True - self.gamepad_neutral = False - else: - self.gamepad_pressed_timer += ( - pygame.time.get_ticks() - self.gamepad_last_update - ) - if self.gamepad_pressed_timer > self.gamepad_repeat_delay: - gamepad_move = True - self.gamepad_pressed_timer -= self.gamepad_repeat_delay - if gamepad_move: - if joystick_hat == (-1, 0): - self.move_update_circuit_grid_display( - screen, circuit_grid, MOVE_LEFT - ) - elif joystick_hat == (1, 0): - self.move_update_circuit_grid_display( - screen, circuit_grid, MOVE_RIGHT - ) - elif joystick_hat == (0, 1): - self.move_update_circuit_grid_display(screen, circuit_grid, MOVE_UP) - elif joystick_hat == (0, -1): - self.move_update_circuit_grid_display( - screen, circuit_grid, MOVE_DOWN - ) - self.gamepad_last_update = pygame.time.get_ticks() - - # Check left thumbstick position - # left_thumb_x = self.joystick.get_axis(0) - # left_thumb_y = self.joystick.get_axis(1) - - # Handle Input Events - for event in pygame.event.get(): - pygame.event.pump() - - if event.type == pygame.QUIT: - self.running = False - elif event.type == pygame.JOYBUTTONDOWN: - if event.button == gamepad.BTN_A: - # Place X gate - circuit_grid.handle_input_x() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.button == gamepad.BTN_X: - # Place Y gate - circuit_grid.handle_input_y() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.button == gamepad.BTN_B: - # Place Z gate - circuit_grid.handle_input_z() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.button == gamepad.BTN_Y: - # Place Hadamard gate - circuit_grid.handle_input_h() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.button == gamepad.BTN_RIGHT_TRIGGER: - # Delete gate - circuit_grid.handle_input_delete() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.button == gamepad.BTN_RIGHT_THUMB: - # Add or remove a control - circuit_grid.handle_input_ctrl() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.button == gamepad.BTN_LEFT_BUMPER: - # Update visualizations - self.update_paddle(level, screen, scene) - - elif event.type == pygame.JOYAXISMOTION: - # print("event: ", event) - if ( - event.axis == gamepad.AXIS_RIGHT_THUMB_X - and self.joystick.get_axis(gamepad.AXIS_RIGHT_THUMB_X) >= 0.95 - ): - circuit_grid.handle_input_rotate(np.pi / 8) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - if ( - event.axis == gamepad.AXIS_RIGHT_THUMB_X - and self.joystick.get_axis(gamepad.AXIS_RIGHT_THUMB_X) <= -0.95 - ): - circuit_grid.handle_input_rotate(-np.pi / 8) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - if ( - event.axis == gamepad.AXIS_RIGHT_THUMB_Y - and self.joystick.get_axis(gamepad.AXIS_RIGHT_THUMB_Y) <= -0.95 - ): - circuit_grid.handle_input_move_ctrl(MOVE_UP) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - if ( - event.axis == gamepad.AXIS_RIGHT_THUMB_Y - and self.joystick.get_axis(gamepad.AXIS_RIGHT_THUMB_Y) >= 0.95 - ): - circuit_grid.handle_input_move_ctrl(MOVE_DOWN) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - - elif event.type == pygame.KEYDOWN: - if event.key == pygame.K_ESCAPE: - self.running = False - elif event.key == pygame.K_a: - circuit_grid.move_to_adjacent_node(MOVE_LEFT) - circuit_grid.draw(screen) - pygame.display.flip() - elif event.key == pygame.K_d: - circuit_grid.move_to_adjacent_node(MOVE_RIGHT) - circuit_grid.draw(screen) - pygame.display.flip() - elif event.key == pygame.K_w: - circuit_grid.move_to_adjacent_node(MOVE_UP) - circuit_grid.draw(screen) - pygame.display.flip() - elif event.key == pygame.K_s: - circuit_grid.move_to_adjacent_node(MOVE_DOWN) - circuit_grid.draw(screen) - pygame.display.flip() - elif event.key == pygame.K_x: - circuit_grid.handle_input_x() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_y: - circuit_grid.handle_input_y() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_z: - circuit_grid.handle_input_z() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_h: - circuit_grid.handle_input_h() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_SPACE: - circuit_grid.handle_input_delete() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_c: - # Add or remove a control - circuit_grid.handle_input_ctrl() - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_UP: - # Move a control qubit up - circuit_grid.handle_input_move_ctrl(MOVE_UP) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_DOWN: - # Move a control qubit down - circuit_grid.handle_input_move_ctrl(MOVE_DOWN) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_LEFT: - # Rotate a gate - circuit_grid.handle_input_rotate(-np.pi / 8) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_RIGHT: - # Rotate a gate - circuit_grid.handle_input_rotate(np.pi / 8) - circuit_grid.draw(screen) - self.update_paddle(level, screen, scene) - pygame.display.flip() - elif event.key == pygame.K_TAB: - # Update visualizations - self.update_paddle(level, screen, scene) - - @staticmethod - def update_paddle(level, screen, scene): - """ - Update state vector paddle - """ - # Update visualizations - - circuit_grid_model = level.circuit_grid_model - right_statevector = level.right_statevector - circuit_grid = level.circuit_grid - statevector_grid = level.statevector_grid - - circuit = circuit_grid_model.construct_circuit() - statevector_grid.paddle_before_measurement(circuit, scene.qubit_num) - right_statevector.arrange() - circuit_grid.draw(screen) - pygame.display.flip() - - @staticmethod - def move_update_circuit_grid_display(screen, circuit_grid, direction): - """ - Update circuit grid after move - """ - circuit_grid.move_to_adjacent_node(direction) - circuit_grid.draw(screen) - pygame.display.flip() diff --git a/QPong/qpong/utils/scene.py b/QPong/qpong/utils/scene.py deleted file mode 100644 index d7d387fc..00000000 --- a/QPong/qpong/utils/scene.py +++ /dev/null @@ -1,303 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -A container for managing game screens -""" - -import pygame - -from qpong.utils.parameters import ( - WIDTH_UNIT, - WINDOW_WIDTH, - WINDOW_HEIGHT, - QUANTUM_COMPUTER, - CLASSICAL_COMPUTER, - EASY, - NORMAL, - EXPERT, -) -from qpong.utils.colors import WHITE, BLACK, GRAY -from qpong.utils import gamepad -from qpong.utils.font import Font - - -class Scene: - """ - Display Game Over screen and handle play again - """ - - def __init__(self): - super().__init__() - - self.begin = False - self.restart = False - self.qubit_num = 3 - self.font = Font() - - def start(self, screen, ball): - # pylint: disable=too-many-branches disable=too-many-return-statements - """ - Show start screen - """ - - screen.fill(BLACK) - - gameover_text = "QPong" - text = self.font.gameover_font.render(gameover_text, 1, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 15)) - screen.blit(text, text_pos) - - gameover_text = "Select difficulty level" - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 30)) - screen.blit(text, text_pos) - - gameover_text = "[A] Easy " - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 35)) - screen.blit(text, text_pos) - - gameover_text = "[B] Normal" - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 40)) - screen.blit(text, text_pos) - - gameover_text = "[X] Expert" - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 45)) - screen.blit(text, text_pos) - - self.credits(screen) - - while not self.begin: - - for event in pygame.event.get(): - pygame.event.pump() - - if event.type == pygame.QUIT: - pygame.quit() - elif event.type == pygame.JOYBUTTONDOWN: - if event.button == gamepad.BTN_A: - # easy mode - ball.initial_speed_factor = EASY - return True - if event.button == gamepad.BTN_B: - # normal mode - ball.initial_speed_factor = NORMAL - return True - if event.button == gamepad.BTN_X: - # expert mode - ball.initial_speed_factor = EXPERT - return True - elif event.type == pygame.KEYDOWN: - if event.key == pygame.K_ESCAPE: - return False - if event.key == pygame.K_a: - # easy mode - ball.initial_speed_factor = EASY - return True - if event.key == pygame.K_b: - # normal mode - ball.initial_speed_factor = NORMAL - return True - if event.key == pygame.K_x: - # expert mode - ball.initial_speed_factor = EXPERT - return True - - if self.begin: - # reset all parameters to restart the game - screen.fill(BLACK) - - pygame.display.flip() - - # reset restart flag when self.restart = True and the while ends - self.begin = False - - def gameover(self, screen, player): - """ - Display Game Over screen - """ - if player == CLASSICAL_COMPUTER: - - screen.fill(BLACK) - - gameover_text = "Game Over" - text = self.font.gameover_font.render(gameover_text, 1, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 10)) - screen.blit(text, text_pos) - - gameover_text = "Classical computer" - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 22)) - screen.blit(text, text_pos) - - gameover_text = "still rules the world" - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 27)) - screen.blit(text, text_pos) - - self.credits(screen) - - if player == QUANTUM_COMPUTER: - - screen.fill(BLACK) - - gameover_text = "Congratulations!" - text = self.font.gameover_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 10)) - screen.blit(text, text_pos) - - gameover_text = "You demonstrated quantum supremacy" - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 22)) - screen.blit(text, text_pos) - - gameover_text = "for the first time in human history!" - text = self.font.replay_font.render(gameover_text, 5, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 27)) - screen.blit(text, text_pos) - - self.credits(screen) - - @staticmethod - def dashed_line(screen, ball): - """ - Show dashed line diving the playing field - """ - - for i in range(10, ball.screenheight, 2 * WIDTH_UNIT): # draw dashed line - pygame.draw.rect( - screen, - GRAY, - (WINDOW_WIDTH // 2 - 5, i, 0.5 * WIDTH_UNIT, WIDTH_UNIT), - 0, - ) - - def score(self, screen, ball): - """ - Show score for both player - """ - # Print the score - text = self.font.player_font.render("Classical Computer", 1, GRAY) - text_pos = text.get_rect( - center=(round(WINDOW_WIDTH * 0.25) + WIDTH_UNIT * 4.5, WIDTH_UNIT * 1.5) - ) - screen.blit(text, text_pos) - - text = self.font.player_font.render("Quantum Computer", 1, GRAY) - text_pos = text.get_rect( - center=(round(WINDOW_WIDTH * 0.75) - WIDTH_UNIT * 4.5, WIDTH_UNIT * 1.5) - ) - screen.blit(text, text_pos) - - score_print = str(ball.check_score(0)) - text = self.font.score_font.render(score_print, 1, GRAY) - text_pos = text.get_rect( - center=(round(WINDOW_WIDTH * 0.25) + WIDTH_UNIT * 4.5, WIDTH_UNIT * 8) - ) - screen.blit(text, text_pos) - - score_print = str(ball.check_score(1)) - text = self.font.score_font.render(score_print, 1, GRAY) - text_pos = text.get_rect( - center=(round(WINDOW_WIDTH * 0.75) - WIDTH_UNIT * 4.5, WIDTH_UNIT * 8) - ) - screen.blit(text, text_pos) - - def credits(self, screen): - """ - Show credits screen - """ - credit_text = "Credits" - text = self.font.credit_font.render(credit_text, 1, WHITE) - text_pos = text.get_rect( - center=(WINDOW_WIDTH / 2, WINDOW_HEIGHT - WIDTH_UNIT * 8) - ) - screen.blit(text, text_pos) - - credit_text = ( - "Made by Huang Junye, James Weaver, Jarrod Reilly and Anastasia Jeffery" - ) - text = self.font.credit_font.render(credit_text, 1, WHITE) - text_pos = text.get_rect( - center=(WINDOW_WIDTH / 2, WINDOW_HEIGHT - WIDTH_UNIT * 5) - ) - screen.blit(text, text_pos) - - credit_text = "Initiated at IBM Qiskit Camp 2019" - text = self.font.credit_font.render(credit_text, 1, WHITE) - text_pos = text.get_rect( - center=(WINDOW_WIDTH / 2, WINDOW_HEIGHT - WIDTH_UNIT * 3) - ) - screen.blit(text, text_pos) - - credit_text = "Powered by JavaFXpert/quantum-circuit-game" - text = self.font.credit_font.render(credit_text, 1, WHITE) - text_pos = text.get_rect( - center=(WINDOW_WIDTH / 2, WINDOW_HEIGHT - WIDTH_UNIT * 1) - ) - screen.blit(text, text_pos) - - def replay(self, screen, score, circuit_grid_model, circuit_grid): - """ - Pause the game and ask if the player wants to play again - """ - blink_time = pygame.time.get_ticks() - - while not self.restart: - - for event in pygame.event.get(): - pygame.event.pump() - - if event.type == pygame.QUIT: - pygame.quit() - else: - self.restart = True - - if self.restart: - # reset all parameters to restart the game - score.reset_score() - circuit_grid_model.reset_circuit() - circuit_grid.update() - circuit_grid.reset_cursor() - - # Make blinking text - if pygame.time.get_ticks() - blink_time > 1000: - blink_time = pygame.time.get_ticks() - if pygame.time.get_ticks() - blink_time > 500: - replay_text = "Press Any Key to Play Again" - text = self.font.replay_font.render(replay_text, 1, WHITE) - text_pos = text.get_rect(center=(WINDOW_WIDTH / 2, WIDTH_UNIT * 40)) - screen.blit(text, text_pos) - pygame.display.flip() - else: - # show a black box to blink the text every 0.5s - pygame.draw.rect( - screen, - BLACK, - ( - WIDTH_UNIT * 10, - WIDTH_UNIT * 35, - WIDTH_UNIT * 80, - WIDTH_UNIT * 10, - ), - ) - pygame.display.flip() - - # reset restart flag when self.restart = True and the while ends - self.restart = False diff --git a/QPong/qpong/utils/score.py b/QPong/qpong/utils/score.py deleted file mode 100644 index 684fa06f..00000000 --- a/QPong/qpong/utils/score.py +++ /dev/null @@ -1,64 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Game score -""" -import pygame - - -class Score(pygame.sprite.Sprite): - """ - Score container for ongoing game - """ - - def __init__(self): - super().__init__() - - self.player = 0 - self.computer = 0 - - # Computer = 0, Player = 1 - def update(self, player): - """ - Get score for a specified player - - Parameters: - player (integer): - """ - if player == 0: - self.computer += 1 - - if player == 1: - self.player += 1 - - def get_score(self, player): - """ - Get score for a specified player - - Parameters: - player (integer): - """ - if player == 0: - return self.computer - return self.player - - def reset_score(self): - """ - Reset score - """ - self.computer = 0 - self.player = 0 diff --git a/QPong/qpong/utils/sound.py b/QPong/qpong/utils/sound.py deleted file mode 100644 index d071e5c6..00000000 --- a/QPong/qpong/utils/sound.py +++ /dev/null @@ -1,32 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Utility class for loading game sounds -""" - -from qpong.utils.resources import load_sound - -# pylint: disable=too-few-public-methods -class Sound: - """ - Load sounds - """ - - def __init__(self): - self.bounce_sound = load_sound("4391__noisecollector__pongblipf-5.wav") - self.edge_sound = load_sound("4390__noisecollector__pongblipf-4.wav") - self.lost_sound = load_sound("4384__noisecollector__pongblipd4.wav") diff --git a/QPong/requirements-dev.txt b/QPong/requirements-dev.txt deleted file mode 100644 index 291e4116..00000000 --- a/QPong/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -coverage==5.5 -pylint==2.9.5 -tox==3.24.0 -black==22.3.0 diff --git a/QPong/requirements.txt b/QPong/requirements.txt deleted file mode 100644 index eae6af01..00000000 --- a/QPong/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -pytest==6.2.4 -qiskit~=1.0 -pygame~=2.5 diff --git a/QPong/screenshots/gameplay.png b/QPong/screenshots/gameplay.png deleted file mode 100644 index 21d9e549..00000000 Binary files a/QPong/screenshots/gameplay.png and /dev/null differ diff --git a/QPong/screenshots/setup.png b/QPong/screenshots/setup.png deleted file mode 100644 index 76946552..00000000 Binary files a/QPong/screenshots/setup.png and /dev/null differ diff --git a/QPong/setup.cfg b/QPong/setup.cfg deleted file mode 100644 index 08aedd7e..00000000 --- a/QPong/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[metadata] -description_file = README.md diff --git a/QPong/setup.py b/QPong/setup.py deleted file mode 100644 index 83b30fa7..00000000 --- a/QPong/setup.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Setup file for QPong.""" - -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -with open('requirements.txt') as fp: - install_requires = fp.read() - -setuptools.setup( - name="qpong", - description="Qpong", - long_description=long_description, - packages=setuptools.find_packages(), - install_requires=install_requires, - python_requires='>=3.6' -) diff --git a/QPong/tests/__init__.py b/QPong/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/QPong/tests/test_ball.py b/QPong/tests/test_ball.py deleted file mode 100644 index ab28c825..00000000 --- a/QPong/tests/test_ball.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -""" -Test ball -""" - -import unittest - -from qpong.utils.ball import Ball - -from qpong.utils.parameters import ( - LEFT, - RIGHT, - NOTHING, - NO, - WINDOW_HEIGHT, -) - - -class TestBall(unittest.TestCase): - """ - Unit tests for QPong ball - """ - - def setUp(self): - """ - Set up - """ - - self.ball = Ball() - - def test_ball_initialization(self): - """ - Test ball initialization - """ - - self.assertEqual( - self.ball.xpos, self.ball.left_edge + self.ball.width_unit * 15 - ) - self.assertEqual(self.ball.ypos, 0.7 * WINDOW_HEIGHT / 2) - self.assertEqual(self.ball.initial_speed_factor, 0.8) - self.assertEqual(self.ball.ball_action, NOTHING) - self.assertEqual(self.ball.measure_flag, NO) - self.assertEqual(self.ball.reset_position, RIGHT) - - def test_reset_ball(self): - """ - Test ball reset - """ - - self.ball.reset() - - self.assertEqual( - self.ball.xpos, self.ball.right_edge - self.ball.width_unit * 15 - ) - self.assertEqual(self.ball.ypos, 0.7 * WINDOW_HEIGHT / 2) - self.assertEqual(self.ball.reset_position, LEFT) diff --git a/QPong/tests/test_circuit_grid.py b/QPong/tests/test_circuit_grid.py deleted file mode 100644 index 0419c5c0..00000000 --- a/QPong/tests/test_circuit_grid.py +++ /dev/null @@ -1,255 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test circuit grid -""" - -import unittest - -import pygame - -from qpong.model.circuit_grid_model import CircuitGridModel, CircuitGridNode -from qpong.model import circuit_node_types as node_types - -from qpong.controls.circuit_grid import CircuitGrid - -from qpong.utils.parameters import WINDOW_SIZE, WINDOW_HEIGHT, CIRCUIT_DEPTH - -from qpong.utils.navigation import MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT - - -class TestCircuitGrid(unittest.TestCase): - """ - Unit tests for circuit grid - """ - - def setUp(self): - """ - Set up - """ - - pygame.init() - - flags = pygame.DOUBLEBUF | pygame.HWSURFACE - _ = pygame.display.set_mode(WINDOW_SIZE, flags) - - qubit_num = 4 - self.circuit_grid_model = CircuitGridModel(qubit_num, CIRCUIT_DEPTH) - self.grid = CircuitGrid(0, 0.7 * WINDOW_HEIGHT, self.circuit_grid_model) - - def test_circuit_grid_initialization(self): - """ - Test circuit grid initialization - """ - - self.assertEqual(self.grid.selected_wire, 0) - self.assertEqual(self.grid.selected_column, 0) - self.assertEqual(self.grid.xpos, 0) - self.assertEqual(self.grid.ypos, 0.7 * WINDOW_HEIGHT) - - def test_highlight_selected_node(self): - """ - Test highlight selected node - """ - - self.grid.highlight_selected_node(1, 1) - - self.assertEqual(self.grid.selected_wire, 1) - self.assertEqual(self.grid.selected_column, 1) - - self.grid.highlight_selected_node(2, 2) - - self.assertEqual(self.grid.selected_wire, 2) - self.assertEqual(self.grid.selected_column, 2) - - def test_reset_cursor(self): - """ - Test reset cursor - """ - - self.grid.highlight_selected_node(2, 2) - self.grid.reset_cursor() - - self.assertEqual(self.grid.selected_column, 0) - self.assertEqual(self.grid.selected_wire, 0) - - def test_move_to_adjacent_node(self): - """ - Test move cursor to adjacent node - """ - - self.grid.move_to_adjacent_node(MOVE_RIGHT) - - self.assertEqual(self.grid.selected_column, 1) - self.assertEqual(self.grid.selected_wire, 0) - - self.grid.move_to_adjacent_node(MOVE_DOWN) - - self.assertEqual(self.grid.selected_column, 1) - self.assertEqual(self.grid.selected_wire, 1) - - self.grid.move_to_adjacent_node(MOVE_LEFT) - - self.assertEqual(self.grid.selected_column, 0) - self.assertEqual(self.grid.selected_wire, 1) - - self.grid.move_to_adjacent_node(MOVE_UP) - - self.assertEqual(self.grid.selected_column, 0) - self.assertEqual(self.grid.selected_wire, 0) - - def test_get_selected_node_gate_part(self): - """ - Test getting gate on currently selected node - """ - - node1 = CircuitGridNode(node_types.X) - node2 = CircuitGridNode(node_types.Y) - node3 = CircuitGridNode(node_types.Z) - - self.circuit_grid_model.set_node(0, 1, node1) - self.circuit_grid_model.set_node(1, 0, node2) - self.circuit_grid_model.set_node(2, 0, node3) - - self.grid.move_to_adjacent_node(MOVE_RIGHT) - - selected_gate = self.grid.get_selected_node_gate_part() - self.assertEqual(node1.node_type, selected_gate) - - self.grid.move_to_adjacent_node(MOVE_LEFT) - self.grid.move_to_adjacent_node(MOVE_DOWN) - - selected_gate = self.grid.get_selected_node_gate_part() - self.assertEqual(node2.node_type, selected_gate) - - self.grid.move_to_adjacent_node(MOVE_DOWN) - - selected_gate = self.grid.get_selected_node_gate_part() - self.assertEqual(node3.node_type, selected_gate) - - def test_handle_single_qubit_gate_inputs(self): - """ - Test handling input placing single - qubit gates on circuit grid - """ - - # 0 X-------- - # 1 Y-------- - # 2 Z-------- - # 3 H-------- - - self.grid.handle_input_x() - self.grid.move_to_adjacent_node(MOVE_DOWN) - self.grid.handle_input_y() - self.grid.move_to_adjacent_node(MOVE_DOWN) - self.grid.handle_input_z() - self.grid.move_to_adjacent_node(MOVE_DOWN) - self.grid.handle_input_h() - - self.assertEqual(node_types.X, self.circuit_grid_model.get_node_gate_part(0, 0)) - self.assertEqual(node_types.Y, self.circuit_grid_model.get_node_gate_part(1, 0)) - self.assertEqual(node_types.Z, self.circuit_grid_model.get_node_gate_part(2, 0)) - self.assertEqual(node_types.H, self.circuit_grid_model.get_node_gate_part(3, 0)) - - # 0 --------- - # 1 --------- - # 2 --------- - # 3 --------- - - self.grid.handle_input_delete() - self.grid.move_to_adjacent_node(MOVE_UP) - self.grid.handle_input_delete() - self.grid.move_to_adjacent_node(MOVE_UP) - self.grid.handle_input_delete() - self.grid.move_to_adjacent_node(MOVE_UP) - self.grid.handle_input_delete() - - self.assertEqual( - node_types.EMPTY, self.circuit_grid_model.get_node_gate_part(1, 0) - ) - self.assertEqual( - node_types.EMPTY, self.circuit_grid_model.get_node_gate_part(1, 0) - ) - self.assertEqual( - node_types.EMPTY, self.circuit_grid_model.get_node_gate_part(2, 0) - ) - self.assertEqual( - node_types.EMPTY, self.circuit_grid_model.get_node_gate_part(3, 0) - ) - - def test_handle_multi_gate_inputs(self): - """ - Test handling input placing multi - qubit gates on circuit grid - """ - - # 0 |-----|-- - # 1 X-----H-- - # 2 --Y-Z---- - # 3 --|-|---- - - self.grid.move_to_adjacent_node(MOVE_DOWN) - - self.grid.handle_input_x() - self.grid.handle_input_ctrl() - - self.grid.move_to_adjacent_node(MOVE_RIGHT) - self.grid.move_to_adjacent_node(MOVE_DOWN) - - self.grid.handle_input_y() - self.grid.handle_input_ctrl() - self.grid.handle_input_move_ctrl(MOVE_DOWN) - - self.grid.move_to_adjacent_node(MOVE_RIGHT) - - self.grid.handle_input_z() - self.grid.handle_input_ctrl() - self.grid.handle_input_move_ctrl(MOVE_DOWN) - - self.grid.move_to_adjacent_node(MOVE_RIGHT) - self.grid.move_to_adjacent_node(MOVE_UP) - - self.grid.handle_input_h() - self.grid.handle_input_ctrl() - - node1 = self.circuit_grid_model.get_node(1, 0) - node2 = self.circuit_grid_model.get_node(2, 1) - node3 = self.circuit_grid_model.get_node(2, 2) - node4 = self.circuit_grid_model.get_node(1, 3) - - self.assertEqual(node_types.X, node1.node_type) - self.assertEqual(0, node1.ctrl_a) - self.assertEqual(-1, node1.ctrl_b) - - self.assertEqual(node_types.Y, node2.node_type) - self.assertEqual(3, node2.ctrl_a) - self.assertEqual(-1, node2.ctrl_b) - - self.assertEqual(node_types.Z, node3.node_type) - self.assertEqual(3, node3.ctrl_a) - self.assertEqual(-1, node3.ctrl_b) - - self.assertEqual(node_types.H, node4.node_type) - self.assertEqual(0, node4.ctrl_a) - self.assertEqual(-1, node4.ctrl_b) - - def tearDown(self): - """ - Tear down - """ - - pygame.quit() diff --git a/QPong/tests/test_circuit_grid_model.py b/QPong/tests/test_circuit_grid_model.py deleted file mode 100644 index b0e28806..00000000 --- a/QPong/tests/test_circuit_grid_model.py +++ /dev/null @@ -1,106 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test circuit grid model -""" - -import unittest - -from qpong.model import CircuitGridModel, CircuitGridNode -from qpong.model import circuit_node_types as node_types - - -class TestCircuitGridModel(unittest.TestCase): - """ - Unit tests for circuit grid model - """ - - def setUp(self): - """ - Set up - """ - - self.model = CircuitGridModel(3, 3) - self.node_x = CircuitGridNode(node_types.X) - self.node_y = CircuitGridNode(node_types.Y) - self.node_z = CircuitGridNode(node_types.Z) - - def test_circuit_node_initialization(self): - """ - Test circuit node initialization - """ - - self.assertEqual(self.node_x.node_type, node_types.X) - self.assertEqual(self.node_x.radians, 0.0) - self.assertEqual(self.node_x.swap, -1.0) - self.assertEqual(self.node_x.ctrl_a, -1.0) - self.assertEqual(self.node_x.ctrl_b, -1.0) - - self.assertEqual(self.node_y.node_type, node_types.Y) - self.assertEqual(self.node_y.radians, 0.0) - self.assertEqual(self.node_y.swap, -1.0) - self.assertEqual(self.node_y.ctrl_a, -1.0) - self.assertEqual(self.node_y.ctrl_b, -1.0) - - self.assertEqual(self.node_z.node_type, node_types.Z) - self.assertEqual(self.node_z.radians, 0.0) - self.assertEqual(self.node_z.swap, -1.0) - self.assertEqual(self.node_z.ctrl_a, -1.0) - self.assertEqual(self.node_z.ctrl_b, -1.0) - - def test_circuit_grid_model_initialization(self): - """ - Test circuit grid model initialization - """ - - for wire_num in range(self.model.max_wires): - for column_num in range(self.model.max_columns): - self.assertEqual( - self.model.get_node(wire_num, column_num).node_type, - node_types.EMPTY, - ) - - def test_get_node(self): - """ - Test get node - """ - - self.model.set_node(0, 0, self.node_x) - - self.assertEqual(self.model.get_node(0, 0).node_type, self.node_x.node_type) - self.assertEqual(self.model.get_node(0, 0).radians, self.node_x.radians) - self.assertEqual(self.model.get_node(0, 0).swap, self.node_x.swap) - self.assertEqual(self.model.get_node(0, 0).ctrl_a, self.node_x.ctrl_a) - self.assertEqual(self.model.get_node(0, 0).ctrl_b, self.node_x.ctrl_b) - - def test_reset_circuit(self): - """ - Test reset circuit - """ - - self.model.set_node(0, 0, self.node_x) - self.model.set_node(1, 0, self.node_y) - self.model.set_node(2, 0, self.node_z) - - self.model.reset_circuit() - - for wire_num in range(self.model.max_wires): - for column_num in range(self.model.max_columns): - self.assertEqual( - self.model.get_node(wire_num, column_num).node_type, - node_types.EMPTY, - ) diff --git a/QPong/tests/test_input.py b/QPong/tests/test_input.py deleted file mode 100644 index 4e489f08..00000000 --- a/QPong/tests/test_input.py +++ /dev/null @@ -1,291 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test input -""" - -import unittest - -import numpy as np -import pygame - -from qpong.utils.level import Level -from qpong.utils.scene import Scene -from qpong.utils.ball import Ball -from qpong.utils.input import Input - -from qpong.model import circuit_node_types as node_types - -from qpong.utils.parameters import WINDOW_SIZE - - -class TestLevel(unittest.TestCase): - """ - Unit tests for input - """ - - def setUp(self): - """ - Set up - """ - - pygame.init() - - flags = pygame.DOUBLEBUF | pygame.HWSURFACE - self.screen = pygame.display.set_mode(WINDOW_SIZE, flags) - - self.scene = Scene() - self.level = Level() - self.input = Input() - self.ball = Ball() - - self.level.setup(self.scene, self.ball) - - def inject_event(self, event=pygame.KEYDOWN, key=pygame.K_ESCAPE): - """ - Inject keyboard press event to event queue - """ - - pygame.event.get() - post_event = pygame.event.Event(event, key=key) - pygame.event.post(post_event) - - self.input.handle_input(self.level, self.screen, self.scene) - - def test_input_initialization(self): - """ - Test input initialization - """ - - self.assertEqual(self.input.running, True) - self.assertEqual(self.input.gamepad_repeat_delay, 200) - self.assertEqual(self.input.gamepad_neutral, True) - self.assertEqual(self.input.gamepad_pressed_timer, 0) - - def test_handle_escape_keyboard_press(self): - """ - Test handling key event for quiting pygame - """ - - self.inject_event(pygame.KEYDOWN, key=pygame.K_ESCAPE) - self.assertEqual(self.input.running, False) - - def test_handle_navigation_keyboard_presses(self): - """ - Test handling key events for navigating - circuit grid - """ - - self.inject_event(pygame.KEYDOWN, key=pygame.K_d) - - # should have moved highlighted node right - self.assertEqual(self.level.circuit_grid.selected_column, 1) - self.assertEqual(self.level.circuit_grid.selected_wire, 0) - - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - - # should have moved highlighted node left - self.assertEqual(self.level.circuit_grid.selected_column, 0) - self.assertEqual(self.level.circuit_grid.selected_wire, 0) - - self.inject_event(pygame.KEYDOWN, key=pygame.K_s) - - # should have moved highlighted node down - self.assertEqual(self.level.circuit_grid.selected_column, 0) - self.assertEqual(self.level.circuit_grid.selected_wire, 1) - - self.inject_event(pygame.KEYDOWN, key=pygame.K_w) - - # should have moved highlighted node u - self.assertEqual(self.level.circuit_grid.selected_column, 0) - self.assertEqual(self.level.circuit_grid.selected_wire, 0) - - def test_handle_single_qubit_gate_keyboard_presses(self): - """ - Test handling key events for placing single - qubit gates on circuit grid - """ - - # 0 X-Y-Z-H-- - # 1 --------- - # 2 --------- - - self.inject_event(pygame.KEYDOWN, key=pygame.K_x) - self.inject_event(pygame.KEYDOWN, key=pygame.K_d) - self.inject_event(pygame.KEYDOWN, key=pygame.K_y) - self.inject_event(pygame.KEYDOWN, key=pygame.K_d) - self.inject_event(pygame.KEYDOWN, key=pygame.K_z) - self.inject_event(pygame.KEYDOWN, key=pygame.K_d) - self.inject_event(pygame.KEYDOWN, key=pygame.K_h) - - self.assertEqual( - node_types.X, self.level.circuit_grid_model.get_node_gate_part(0, 0) - ) - self.assertEqual( - node_types.Y, self.level.circuit_grid_model.get_node_gate_part(0, 1) - ) - self.assertEqual( - node_types.Z, self.level.circuit_grid_model.get_node_gate_part(0, 2) - ) - self.assertEqual( - node_types.H, self.level.circuit_grid_model.get_node_gate_part(0, 3) - ) - - # 0 --------- - # 1 --------- - # 2 --------- - - self.inject_event(pygame.KEYDOWN, key=pygame.K_SPACE) - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - self.inject_event(pygame.KEYDOWN, key=pygame.K_SPACE) - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - self.inject_event(pygame.KEYDOWN, key=pygame.K_SPACE) - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - self.inject_event(pygame.KEYDOWN, key=pygame.K_SPACE) - - self.assertEqual( - node_types.EMPTY, self.level.circuit_grid_model.get_node_gate_part(0, 0) - ) - self.assertEqual( - node_types.EMPTY, self.level.circuit_grid_model.get_node_gate_part(0, 1) - ) - self.assertEqual( - node_types.EMPTY, self.level.circuit_grid_model.get_node_gate_part(0, 2) - ) - self.assertEqual( - node_types.EMPTY, self.level.circuit_grid_model.get_node_gate_part(0, 3) - ) - - # 0 Rx-------- - # 1 Ry-------- - # 2 Rz-------- - - self.inject_event(pygame.KEYDOWN, key=pygame.K_x) - self.inject_event(pygame.KEYDOWN, key=pygame.K_RIGHT) - self.inject_event(pygame.KEYDOWN, key=pygame.K_s) - self.inject_event(pygame.KEYDOWN, key=pygame.K_y) - self.inject_event(pygame.KEYDOWN, key=pygame.K_RIGHT) - self.inject_event(pygame.KEYDOWN, key=pygame.K_RIGHT) - self.inject_event(pygame.KEYDOWN, key=pygame.K_s) - self.inject_event(pygame.KEYDOWN, key=pygame.K_z) - self.inject_event(pygame.KEYDOWN, key=pygame.K_LEFT) - self.inject_event(pygame.KEYDOWN, key=pygame.K_LEFT) - - node1 = self.level.circuit_grid_model.get_node(0, 0) - node2 = self.level.circuit_grid_model.get_node(1, 0) - node3 = self.level.circuit_grid_model.get_node(2, 0) - - self.assertEqual(node_types.X, node1.node_type) - self.assertEqual(np.pi / 8, node1.radians) - - self.assertEqual(node_types.Y, node2.node_type) - self.assertEqual(np.pi / 4, node2.radians) - - self.assertEqual(node_types.Z, node3.node_type) - self.assertAlmostEqual(2 * np.pi - np.pi / 4, node3.radians) - - def test_handle_multi_qubit_gate_keyboard_presses(self): - # pylint: disable=too-many-statements - """ - Test handling key events placing for multi - qubit gates on circuit grid - """ - # 0 X-Y-Z-H-- - # 1 |-|-|-|-- - # 2 --------- - - # cx - self.inject_event(pygame.KEYDOWN, key=pygame.K_x) - self.inject_event(pygame.KEYDOWN, key=pygame.K_c) - - self.inject_event(pygame.KEYDOWN, key=pygame.K_d) - - # cy - self.inject_event(pygame.KEYDOWN, key=pygame.K_y) - self.inject_event(pygame.KEYDOWN, key=pygame.K_c) - - self.inject_event(pygame.KEYDOWN, key=pygame.K_d) - # cz - self.inject_event(pygame.KEYDOWN, key=pygame.K_z) - self.inject_event(pygame.KEYDOWN, key=pygame.K_c) - - self.inject_event(pygame.KEYDOWN, key=pygame.K_d) - - # ch - self.inject_event(pygame.KEYDOWN, key=pygame.K_h) - self.inject_event(pygame.KEYDOWN, key=pygame.K_c) - - node1 = self.level.circuit_grid_model.get_node(0, 0) - node2 = self.level.circuit_grid_model.get_node(0, 1) - node3 = self.level.circuit_grid_model.get_node(0, 2) - node4 = self.level.circuit_grid_model.get_node(0, 3) - - self.assertEqual(node_types.X, node1.node_type) - self.assertEqual(1, node1.ctrl_a) - self.assertEqual(-1, node1.ctrl_b) - - self.assertEqual(node_types.Y, node2.node_type) - self.assertEqual(1, node2.ctrl_a) - self.assertEqual(-1, node2.ctrl_b) - - self.assertEqual(node_types.Z, node3.node_type) - self.assertEqual(1, node3.ctrl_a) - self.assertEqual(-1, node3.ctrl_b) - - self.assertEqual(node_types.H, node4.node_type) - self.assertEqual(1, node4.ctrl_a) - self.assertEqual(-1, node4.ctrl_b) - - # 0 X-Y-Z-H-- - # 1 |-|-|-|-- - # 2 |-|-|-|-- - - self.inject_event(pygame.KEYDOWN, key=pygame.K_DOWN) - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - self.inject_event(pygame.KEYDOWN, key=pygame.K_DOWN) - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - self.inject_event(pygame.KEYDOWN, key=pygame.K_DOWN) - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - self.inject_event(pygame.KEYDOWN, key=pygame.K_DOWN) - - node1 = self.level.circuit_grid_model.get_node(0, 0) - node2 = self.level.circuit_grid_model.get_node(0, 1) - node3 = self.level.circuit_grid_model.get_node(0, 2) - node4 = self.level.circuit_grid_model.get_node(0, 3) - - self.assertEqual(node_types.X, node1.node_type) - self.assertEqual(2, node1.ctrl_a) - self.assertEqual(-1, node1.ctrl_b) - - self.assertEqual(node_types.Y, node2.node_type) - self.assertEqual(2, node2.ctrl_a) - self.assertEqual(-1, node2.ctrl_b) - - self.assertEqual(node_types.Z, node3.node_type) - self.assertEqual(2, node3.ctrl_a) - self.assertEqual(-1, node3.ctrl_b) - - self.assertEqual(node_types.H, node4.node_type) - self.assertEqual(2, node4.ctrl_a) - self.assertEqual(-1, node4.ctrl_b) - - def tearDown(self): - """ - Tear down - """ - - pygame.quit() diff --git a/QPong/tests/test_level.py b/QPong/tests/test_level.py deleted file mode 100644 index ce48bf0b..00000000 --- a/QPong/tests/test_level.py +++ /dev/null @@ -1,83 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test level -""" - -import unittest - -import pygame - -from qpong.utils.level import Level -from qpong.utils.scene import Scene -from qpong.utils.ball import Ball - -from qpong.utils.parameters import WINDOW_SIZE - - -class Testlevel(unittest.TestCase): - """ - Unit tests for level - """ - - def setUp(self): - """ - Set up - """ - - pygame.init() - - flags = pygame.DOUBLEBUF | pygame.HWSURFACE - _ = pygame.display.set_mode(WINDOW_SIZE, flags) - - self.scene = Scene() - self.level = Level() - self.ball = Ball() - - def test_level_initialization(self): - """ - Test level initialization - """ - - self.assertEqual(self.level.level, 3) - self.assertEqual(self.level.win, False) - self.assertEqual(self.level.circuit is None, True) - self.assertEqual(self.level.circuit_grid is None, True) - self.assertEqual(self.level.circuit_grid_model is None, True) - self.assertEqual(self.level.statevector_grid is None, True) - self.assertEqual(self.level.right_statevector is None, True) - - def test_level_setup(self): - """ - Test level setup - """ - - self.level.setup(self.scene, self.ball) - - self.assertEqual(self.scene.qubit_num, 3) - self.assertEqual(self.level.circuit is None, False) - self.assertEqual(self.level.circuit_grid is None, False) - self.assertEqual(self.level.circuit_grid_model is None, False) - self.assertEqual(self.level.statevector_grid is None, False) - self.assertEqual(self.level.right_statevector is None, False) - - def tearDown(self): - """ - Tear down - """ - - pygame.quit() diff --git a/QPong/tests/test_resources.py b/QPong/tests/test_resources.py deleted file mode 100644 index f4747962..00000000 --- a/QPong/tests/test_resources.py +++ /dev/null @@ -1,83 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test states utilities -""" - -import unittest - -import pygame - -from qpong.utils.resources import load_font, load_sound, load_image - -from qpong.utils.parameters import WINDOW_SIZE - - -class TestResources(unittest.TestCase): - """ - Unit tests for resource loading utilities - """ - - def setUp(self): - """ - Set up - """ - - pygame.init() - - flags = pygame.DOUBLEBUF | pygame.HWSURFACE - _ = pygame.display.set_mode(WINDOW_SIZE, flags) - - self.bit_font = load_font("bit5x3.ttf") - - self.sound1 = load_sound("4384__noisecollector__pongblipd4.wav") - self.sound2 = load_sound("4390__noisecollector__pongblipf-4.wav") - self.sound3 = load_sound("4391__noisecollector__pongblipf-5.wav") - - self.image1 = load_image("gate_images/h_gate.png") - self.image2 = load_image("gate_images/not_gate.png") - - def test_load_font(self): - """ - Test load font - """ - - self.assertEqual(self.bit_font is not None, True) - - def test_load_sound(self): - """ - Test load sound - """ - - self.assertEqual(self.sound1 is not None, True) - self.assertEqual(self.sound2 is not None, True) - self.assertEqual(self.sound3 is not None, True) - - def test_load_image(self): - """ - Test load image - """ - - self.assertEqual(self.image1 is not None, True) - self.assertEqual(self.image2 is not None, True) - - def tearDown(self): - """ - Tear down - """ - - pygame.quit() diff --git a/QPong/tests/test_scene.py b/QPong/tests/test_scene.py deleted file mode 100644 index e8374e47..00000000 --- a/QPong/tests/test_scene.py +++ /dev/null @@ -1,100 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test scene -""" - -import unittest - -import pygame - -from qpong.utils.scene import Scene -from qpong.utils.level import Level -from qpong.utils.ball import Ball - -from qpong.utils.parameters import ( - WINDOW_SIZE, - EASY, - NORMAL, - EXPERT, -) - - -class TestScene(unittest.TestCase): - """ - Unit tests for scene - """ - - def setUp(self): - """ - Set up. - """ - - pygame.init() - - flags = pygame.DOUBLEBUF | pygame.HWSURFACE - self.screen = pygame.display.set_mode(WINDOW_SIZE, flags) - - self.ball = Ball() - self.level = Level() - self.scene = Scene() - - @staticmethod - def inject_event(event=pygame.KEYDOWN, key=pygame.K_ESCAPE): - """ - Inject keyboard press event to pygame event queue - """ - - pygame.event.get() - post_event = pygame.event.Event(event, key=key) - pygame.event.post(post_event) - - def test_scene_initialization(self): - """ - Test scene initialization - """ - - self.assertEqual(self.scene.begin, False) - self.assertEqual(self.scene.restart, False) - self.assertEqual(self.scene.qubit_num, 3) - - def test_start_scene(self): - """ - Test start scene - """ - - # select easy mode - self.inject_event(pygame.KEYDOWN, key=pygame.K_a) - self.scene.start(self.screen, self.ball) - self.assertEqual(self.ball.initial_speed_factor, EASY) - - # select normal mode - self.inject_event(pygame.KEYDOWN, key=pygame.K_b) - self.scene.start(self.screen, self.ball) - self.assertEqual(self.ball.initial_speed_factor, NORMAL) - - # select expert mode - self.inject_event(pygame.KEYDOWN, key=pygame.K_x) - self.scene.start(self.screen, self.ball) - self.assertEqual(self.ball.initial_speed_factor, EXPERT) - - def tearDown(self): - """ - Tear down - """ - - pygame.quit() diff --git a/QPong/tests/test_score.py b/QPong/tests/test_score.py deleted file mode 100644 index bff9b611..00000000 --- a/QPong/tests/test_score.py +++ /dev/null @@ -1,83 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test score -""" - -import unittest - -from qpong.utils.score import Score - - -class TestScene(unittest.TestCase): - """ - Unit tests for score - """ - - def setUp(self): - """ - Set up - """ - - self.score = Score() - - def test_score_initialization(self): - """ - Test score initialization - """ - - self.assertEqual(self.score.player, 0) - self.assertEqual(self.score.computer, 0) - - def test_score_update(self): - """ - Test score update - """ - - self.score.update(0) - - self.assertEqual(self.score.computer, 1) - self.assertEqual(self.score.player, 0) - - self.score.update(1) - - self.assertEqual(self.score.computer, 1) - self.assertEqual(self.score.player, 1) - - def test_score_reset(self): - """ - Test score reset - """ - - self.score.update(0) - self.score.update(1) - - self.score.reset_score() - - self.assertEqual(self.score.computer, 0) - self.assertEqual(self.score.player, 0) - - def test_score_getter(self): - """ - Test score getter - """ - - self.score.update(0) - self.score.update(1) - - self.assertEqual(self.score.get_score(0), 1) - self.assertEqual(self.score.get_score(1), 1) diff --git a/QPong/tests/test_states.py b/QPong/tests/test_states.py deleted file mode 100644 index 195fc31a..00000000 --- a/QPong/tests/test_states.py +++ /dev/null @@ -1,68 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test states utilities -""" - -import unittest - -from qpong.utils.states import comp_basis_states - - -class TestUtilsStates(unittest.TestCase): - """ - Unit tests for quantum state utilities - """ - - def test_comp_basis_states_length(self): - """ - Test how many basis states are generated - for a given number of qubits - """ - - basis_state = comp_basis_states(3) - - self.assertEqual(len(basis_state), 8) - - basis_state = comp_basis_states(2) - - self.assertEqual(len(basis_state), 4) - - basis_state = comp_basis_states(1) - - self.assertEqual(len(basis_state), 2) - - def test_comp_basis_states(self): - """ - Test if computational basis states - strings. - """ - - basis_state = comp_basis_states(3) - - for i, state in enumerate(basis_state): - self.assertEqual(state, format(i, "03b")) - - basis_state = comp_basis_states(2) - - for i, state in enumerate(basis_state): - self.assertEqual(state, format(i, "02b")) - - basis_state = comp_basis_states(1) - - for i, state in enumerate(basis_state): - self.assertEqual(state, format(i, "01b")) diff --git a/QPong/tests/test_vbox.py b/QPong/tests/test_vbox.py deleted file mode 100644 index 5e7634d2..00000000 --- a/QPong/tests/test_vbox.py +++ /dev/null @@ -1,76 +0,0 @@ -# -# Copyright 2022 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -""" -Test vbox -""" - -import unittest - -import pygame - -from qpong.containers.vbox import VBox -from qpong.utils.parameters import WINDOW_SIZE - - -class TestVBox(unittest.TestCase): - """ - Unit tests for VBox - """ - - def setUp(self): - class Block(pygame.sprite.Sprite): - # pylint: disable=too-few-public-methods - """ - Testing block - """ - - def __init__(self, width, height): - pygame.sprite.Sprite.__init__(self) - - self.image = pygame.Surface([width, height]) - - self.rect = self.image.get_rect() - - pygame.init() - - flags = pygame.DOUBLEBUF | pygame.HWSURFACE - _ = pygame.display.set_mode(WINDOW_SIZE, flags) - - self.rectangle = Block(50, 10) - self.square = Block(20, 20) - self.vbox = VBox(50, 10, self.rectangle, self.square) - - def test_vbox_initialization(self): - """ - Test vbox initialization - """ - - self.assertEqual(self.vbox.xpos, 50) - self.assertEqual(self.vbox.ypos, 10) - - self.assertEqual(self.rectangle.rect.top, 10) - self.assertEqual(self.rectangle.rect.left, 50) - - self.assertEqual(self.square.rect.top, 20) - self.assertEqual(self.square.rect.left, 50) - - def tearDown(self): - """ - Tear down - """ - - pygame.quit() diff --git a/QPong/tox.ini b/QPong/tox.ini deleted file mode 100644 index 4a3ead6e..00000000 --- a/QPong/tox.ini +++ /dev/null @@ -1,39 +0,0 @@ -[tox] -minversion = 3.6 -envlist = py36, py37, py38, py39, lint, coverage, black -skipsdist = True - -[testenv] -usedevelop = true -install_command = pip install -U {opts} {packages} -setenv = - VIRTUAL_ENV={envdir} - LANGUAGE=en_US - LC_ALL=en_US.utf-8 -deps = -r requirements.txt - -r requirements-dev.txt -commands = - pip check - python -m unittest -v - -[testenv:lint] -envdir = .tox/lint -sitepackages = False -commands = - pylint -rn qpong tests - -[testenv:coverage] -basepython = python3 -commands = - coverage3 run -m unittest -v - coverage3 report --fail-under=80 - -[testenv:black] -envdir = .tox/lint -commands = black {posargs} qpong tests --check - -[testenv:json] -skip_install = true -allowlist_externals = /bin/bash -commands = - /bin/bash -ec 'cat ecosystem.json | jq empty'