// Update is called once per frame
    void Update()
    {
        updatePiecesColor();
        if (!tutorialMode)
        {
            if (!tutModeFin)
            {
                players [currPlayer].makeTurn();
                if (players [currPlayer].playedTurn)
                {
                    players [currPlayer].playedTurn = false;
                    int otherPlayer = (currPlayer + 1) % 2;
                    switchTurns(otherPlayer);
                }
                calculateScore();
                if (checkGameOver())
                {
//					Color winColor = endPiece.GetComponent<MeshRenderer> ().material.color;
                    GameObject endSprite = gameOverSprites [2];                     //default for tie
                    if (score [0] > score [1])
                    {
//						winColor = players [0].playerColor;
                        endSprite = gameOverSprites[0];
                        if (players[1].numPiecesLeft() > 0)
                        {
                            endSprite = gameOverSprites [3];                             //win by lockout bc player1 can still go
                        }
                    }
                    else if (score [1] > score [0])
                    {
//						winColor = players [1].playerColor;
                        endSprite = gameOverSprites[1];
                        if (players[0].numPiecesLeft() > 0)
                        {
                            endSprite = gameOverSprites [4];                             //win by lockout bc player0 can still go
                        }
                    }
                    Vector3 pos = endSprite.transform.position;
                    endSprite.transform.position = new Vector3(pos.x, pos.y, endPieceZ);
                    if (!endSpriteSoundPlaying)
                    {
                        this.GetComponent <AudioSource> ().Stop();
                        endSprite.GetComponent <AudioSource> ().Play();
                        endSpriteSoundPlaying = true;
                    }
                    if (!homeButton.activeInHierarchy)
                    {
                        homeButton.SetActive(true);
                    }
                    players [0].gameOver = true;
                    players [1].gameOver = true;
                }
                else
                {
                    checkShowHomeButton();
                }
            }
        }
        else
        {
            checkShowHomeButton();
            if (needNewTut || tutModeFin)
            {
                if (currTut >= tutorials.Length)
                {
                    //done with tutorials
                    tutStep.deActivateBground(0);
                    tutStep.deActivateBground(1);
                    tutorialTextFields[0].GetComponent <Text> ().text = "";
                    tutorialTextFields[1].GetComponent <Text> ().text = "";
                    tutModeFin = true;
                    Debug.Log("homer");
                    if (!homeButton.activeInHierarchy)
                    {
                        homeButton.SetActive(true);
                    }
                    needNewTut = false;
                }
                else
                {
                    tutStep = tutorials [currTut].GetComponent <tutorialSteps> ();
                    tutorialTextFields[currPlayer].GetComponent <Text> ().text = tutStep.instruction;
                    currTut++;
                    for (int i = 0; i < tutStep.pieceTags.Length; i++)
                    {
                        players [0].pieceDict [tutStep.pieceTags [i]] = tutStep.p0PieceAmt [i];
                        players [1].pieceDict [tutStep.pieceTags [i]] = tutStep.p1PieceAmt [i];
                    }
                    needNewTut = false;
                }
            }
            else
            {
                int otherPlayer = (currPlayer + 1) % 2;
                //use the tut that's in progress till it's finished
                if (!players [currPlayer].playedTurn)
                {
//					Debug.Log ("waiting for currPlayer to make turn");
                    tutorialTextFields[otherPlayer].GetComponent <Text> ().text = "";
                    tutStep.deActivateBground(otherPlayer);
                    tutStep.activateBground(currPlayer);
                    if (tutStep.saveGameBoard)
                    {
                        saveGridState();
                    }
                    players [currPlayer].makeTurn();
                }
                else
                {
                    testSuggestedInstructions();
                    if (tutStep.useCompleted)
                    {
                        string completedText = tutStep.completed;
                        if (tutStep.displayScoreInCompleted)
                        {
                            int numBlocksUptownControl = 0;
                            int numBlocksEmpireControl = 0;
                            for (int i = 0; i < grid.GetLength(0); i++)
                            {
                                for (int j = 0; j < grid.GetLength(1); j++)
                                {
                                    cellBehavior cellScript = grid [i, j].GetComponent <cellBehavior> ();
                                    if (cellScript.dotCount [0] > cellScript.dotCount [1])
                                    {
                                        numBlocksUptownControl++;
                                    }
                                    else if (cellScript.dotCount [1] > cellScript.dotCount [0])
                                    {
                                        numBlocksEmpireControl++;
                                    }
                                }
                            }
                            completedText += " " + numBlocksUptownControl.ToString() + " " + tutStep.completed1;
                            completedText += " " + numBlocksEmpireControl.ToString() + ". " + tutStep.completed2;
                        }
                        tutorialTextFields [currPlayer].GetComponent <Text> ().text = completedText;
                        if (Input.GetMouseButtonDown(1))
                        {
                            players [currPlayer].playedTurn = false;
                            tutStep.activateBground(otherPlayer);
                            tutStep.activateBground(currPlayer);
                            switchTurns(otherPlayer);
                            needNewTut = true;
                        }
                    }
                    else
                    {
                        tutorialTextFields[currPlayer].GetComponent <Text> ().text = tutStep.badCompleted;
                        if (Input.GetMouseButtonDown(1))
                        {
                            players [currPlayer].playedTurn = false;
                            Debug.Log("it was set to false");
//							Debug.Break ();
                            tutorialTextFields[currPlayer].GetComponent <Text> ().text = tutStep.instruction;
                            for (int i = 0; i < grid.GetLength(0); i++)
                            {
                                for (int j = 0; j < grid.GetLength(1); j++)
                                {
                                    grid [i, j].GetComponent <cellBehavior> ().goBackToPrevState();
                                }
                            }
                            players [currPlayer].firstTurn = players [currPlayer].oldFirstTurn;
                            tutStep.useCompleted           = true;
                            for (int i = 0; i < tutStep.pieceTags.Length; i++)
                            {
                                players [0].pieceDict [tutStep.pieceTags [i]] = tutStep.p0PieceAmt [i];
                                players [1].pieceDict [tutStep.pieceTags [i]] = tutStep.p1PieceAmt [i];
                            }
                        }
                    }
                }
                calculateScore();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        updatePiecesColor();
        if (!tutorialMode)
        {
            if (!tutModeFin)
            {
                players [currPlayer].makeTurn();
                if (players [currPlayer].playedTurn)
                {
                    players [currPlayer].playedTurn = false;
                    currPlayer = (currPlayer + 1) % 2;
                }
                calculateScore();
                if (checkGameOver())
                {
                    Color winColor = endPiece.GetComponent <MeshRenderer> ().material.color;
                    if (score [0] > score [1])
                    {
                        winColor = players [0].playerColor;
                    }
                    else if (score [1] > score [0])
                    {
                        winColor = players [1].playerColor;
                    }
                    endPiece.GetComponent <MeshRenderer> ().material.color = winColor;
                    Vector3 pos = endPiece.transform.position;
                    endPiece.transform.position = new Vector3(pos.x, pos.y, endPieceZ);
                    homeButton.SetActive(true);
                    players [0].gameOver = true;
                    players [1].gameOver = true;
                }
            }
        }
        else
        {
            if (needNewTut || tutModeFin)
            {
                if (currTut >= tutorials.Length)
                {
//					if (Input.GetMouseButtonDown (1)) {
                    tutStep.deActivateBground();
                    tutorialTextField.GetComponent <Text> ().text = "";
                    //tuts are over
//					tutorialMode = false;
                    tutModeFin = true;
                    Debug.Log("homer");
                    if (!homeButton.activeInHierarchy)
                    {
                        homeButton.SetActive(true);
                    }
                    needNewTut = false;
//					}
                }
                else
                {
                    tutStep = tutorials [currTut].GetComponent <tutorialSteps> ();
                    tutorialTextField.GetComponent <Text> ().text = tutStep.instruction;
                    currTut++;
                    for (int i = 0; i < tutStep.pieceTags.Length; i++)
                    {
                        //set pieces up
                        players [0].pieceDict [tutStep.pieceTags [i]] = tutStep.p0PieceAmt [i];
                        players [1].pieceDict [tutStep.pieceTags [i]] = tutStep.p1PieceAmt [i];
                    }
                    needNewTut = false;
                }
            }
            else
            {
                //use the tut that's in progress till it's finished
                if (!players [currPlayer].playedTurn)
                {
                    if (Input.GetMouseButton(0))
                    {
                        tutorialTextField.GetComponent <Text> ().text = "";
                        tutStep.deActivateBground();
                    }
                    else
                    {
                        tutorialTextField.GetComponent <Text> ().text = tutStep.instruction;
                        tutStep.activateBground();
                    }
                    players [currPlayer].makeTurn();
                }
                else
                {
                    tutorialTextField.GetComponent <Text> ().text = tutStep.completed;
                    if (Input.GetMouseButtonDown(1))
                    {
                        players [currPlayer].playedTurn = false;
                        currPlayer = (currPlayer + 1) % 2;
                        needNewTut = true;
//						if (currTut < tutorials.Length) {
                        tutStep.activateBground();
//						}
                    }
                }
                calculateScore();
            }
        }
    }