import sys
IN_COLAB = 'google.colab' in sys.modules

if IN_COLAB:
  from google.colab import output
  output.enable_custom_widget_manager()
  !pip install qiskit
  !pip install ipympl
  !rm -rf /content/QuantumPoker/
  !git clone https://github.com/sintefmath/QuantumPoker
  sys.path.append('/content/QuantumPoker/Python')
  sys.path.append('/content/QuantumPoker')
  get_ipython().magic('matplotlib ipympl')
else:
  get_ipython().magic('matplotlib notebook')

from os.path import dirname, abspath
import sys
sys.path.append(dirname(abspath('')))
from PokerGame import PokerGame
import matplotlib.pyplot as plt
from numpy import array, count_nonzero

dealer = 0
nPlayers = 3
gameHasRun = False
deckOfGates = {"H": nPlayers, "X": nPlayers, "ZH": nPlayers, "CX": nPlayers}
money = array([100 for i in range(nPlayers)])
names = ["James", "Lilly", "Harry"]

if not count_nonzero(money==0) == (nPlayers-1):
    if gameHasRun:
        dealer = (dealer + 1) % nPlayers
        if 0 in money:
            toDelete=nonzero(money==0)[0]
            for i in flip(toDelete):
                if i < dealer:
                    dealer -= 1
            names = delete(names, nonzero(money==0)[0])
            money = delete(money, nonzero(money==0)[0])
            nPlayers = money.shape[0]
    gameHasRun = True
    pokerGame = PokerGame(deckOfGates, nPlayers, money, names = names, smallBlind=5, smallBlindPlayer=dealer,
                          enableEntanglement=True)