Coder Social home page Coder Social logo

tojen / quantum-connect-four Goto Github PK

View Code? Open in Web Editor NEW
12.0 5.0 1.0 369 KB

Quantum Connect Four

Home Page: https://quantum-connect-four.herokuapp.com

Python 8.92% JavaScript 39.91% HTML 2.44% CSS 0.90% Dockerfile 3.18% Svelte 44.65%
qiskit quantum flask hackathon ibmq python svelte quantum-computing superposition game

quantum-connect-four's Introduction

About

This web based game is a submission for the IBM Quantum Awards 2019 the Game Award Challenge.

This game is based on the tabletop game Connect Four and also inspired by the popular Quantum Tic Tac Toe.

However Connect Four differs from Tic Tac Toe in that the pieces are placed from the top and fall to the bottom under the influence of gravity.

Contributors

How To Play

The players take turns dropping different colored pieces into columns until they can form a horizontal, vertical or diagonal line of 4 pieces. Instead of placing these classical ('solid') pieces, players can also form quantum superpositions by clicking the 'Begin Superposition' button and placing two quantum pieces (indicated by a lighter shade) in different spots, such that the piece has a 50% chance of appearing in either spot upon quantum measurement. Forming superpositions with quantum pieces serves the additional purpose of denying crucial squares to opponents. Both sides continue placing solid or quantum pieces until the the board is filled up, at which point, the superpositions collapse and the surviving pieces fall into place under the influence of gravity and the game-play resumes.

The game will continue like this until any one of the following conditions is met:

  1. Player 1 forms a winning combo before their opponent. Note: the winning pieces must be solid and must not have any shaky quantum pieces underneath them, since that could potentially destroy a winning connection upon quantum measurement.
  2. Player 2 forms a winning combo before their opponent
  3. Tie I: The board gets completely filled up by solid pieces before either player can form a winning combo thereby ending in a draw
  4. Tie II: Both players form winning combos simultaneously upon collapse of the superpositions, this is a draw condition unique to our quantum version of Connect Four

Here's a sneak peak

screenshot

Math Behind It

To collapse n-pairs of superposed pieces all at once, we first map a qubit to each pair of superposed pieces. Then we create a equally weighted superposition of all 2^n states by applying Hadamard gates to every qubit:

Gate

quantum circuit

We then measure the state and collapse the game board accordingly. The plots below are from a 3-qubit example of our circuit, performed on the qasm_simulator of the Aer package:

The Quantum Circuit

quantum gate

Histogram of A Generated Circuit

HISTOGRAM

Developing Using Docker (Recommended)

  1. Clone this repo: git clone [email protected]:ToJen/quantum-connect-four.git
  2. docker-compose up --build --force-recreate --always-recreate-deps

Manually

  1. Clone this repo: git clone [email protected]:ToJen/quantum-connect-four.git
  2. cd client
  3. yarn && yarn dev
  4. Create a separate terminal session
  5. cd server
  6. pip install -r requirements.txt
  7. python main.py (Python 3.5.7)

Visit http://localhost:5000

Deploying to Heroku

  1. docker build -t registry.heroku.com/<heroku-app-name>/web . && docker push registry.heroku.com/<heroku-app-name>/web && heroku container:release web -a <heroku-app-name>

quantum-connect-four's People

Contributors

arjitkhullar avatar tojen avatar yensid12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

marak

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.