public SpookyMark addSpookyMark()
    {
        Mark mark1 = currentSpookyMark[0];
        Mark mark2 = currentSpookyMark[1];

        currentSpookyMark = new List <Mark>();
        SpookyMark s = new SpookyMark(mark1, mark2);

        mark1.sm = s;
        mark2.sm = s;
        spookyMarks.Add(s);

        if (entGraph.addEdgeSQ(mark1.square, mark2.square))
        {
            toCollapse = s;
            return(s);
        }

        HashSet <Square> sqCycle = entGraph.getCycleSQ(mark1.square);

        if (sqCycle != null)
        {
            toCollapse = s;
            return(s);
        }
        else
        {
            return(null);
        }
    }
 public Mark(int p, int t, int pos, Square sq)
 {
     player   = p;
     turn     = t;
     position = pos;
     square   = sq;
     sm       = null;
 }
Exemple #3
0
    public SpookyMarkBot(SpookyMark sm)
    {
        MarkBot mark1 = new MarkBot(sm.mark1);

        mark1.sm = this;
        MarkBot mark2 = new MarkBot(sm.mark2);

        mark2.sm = this;
        this.init(mark1, mark2);
    }
    public HashSet <SpookyMark> getCycle(SpookyMark i)
    {
        HashSet <SpookyMark> visited = new HashSet <SpookyMark>();

        if (dfs(i, visited, null))
        {
            return(visited);
        }
        return(null);
    }
    public void deleteEdge(SpookyMark u, SpookyMark v)
    {
        if (adjlist[u].Contains(v))
        {
            adjlist[u].Remove(v);
        }

        if (adjlist[v].Contains(u))
        {
            adjlist[v].Remove(u);
        }
    }
 public bool removeCycle(SpookyMark v)
 {
     if (getCycle(v) != null)
     {
         foreach (SpookyMark j in getCycle(v))
         {
             deleteEdge(v, j);
         }
         return(true);
     }
     return(false);
 }
    // Start is called before the first frame update
    void Awake()
    {
        gameManager       = GameObject.Find("Game Manager").GetComponent <GameManager>();
        entGraph          = new Graph();
        squares           = new Square[9];
        spookyMarks       = new List <SpookyMark>();
        currentSpookyMark = new List <Mark>();
        collapsed         = new List <int>();
        int i = 0;

        foreach (Transform square in transform)
        {
            squares[i] = square.gameObject.GetComponent <Square>();
            i++;
        }
        toCollapse = null;
    }
 public bool dfs(SpookyMark i, HashSet <SpookyMark> visited, SpookyMark parent)
 {
     foreach (SpookyMark j in adjlist[i])
     {
         if (visited.Contains(j))
         {
             if (!j.Equals(parent))
             {
                 return(true);
             }
             continue;
         }
         else if (dfs(j, visited, i))
         {
             return(true);
         }
     }
     return(false);
 }
    public void collapseHelper(int position, int player, int turn)
    {
        if (collapsed.Contains(position))
        {
            return;
        }
        Square     square  = squares[position];
        GameObject toAdd   = null;
        string     restore = "";

        if (player == 1)
        {
            toAdd   = bigX;
            restore = "X";
        }
        else if (player == 2)
        {
            toAdd   = bigO;
            restore = "O";
        }
        toAdd.GetComponent <TextMeshProUGUI>().text += "<sub>" + turn.ToString() + "</sub>";
        square.setBigMark(toAdd, restore, player, turn);
        collapsed.Add(position);

        // Check all marks in the square S collapsed into. Each corresponding
        // SpookyMark collapses into the square S' that is NOT S. Then, recursively
        // check each of those squares S'.
        foreach (Mark mark in square.getMarks())
        {
            SpookyMark sm = mark.sm;
            int        spookyPosition;
            if (sm.position1 == position)
            {
                spookyPosition = sm.position2;
            }
            else
            {
                spookyPosition = sm.position1;
            }
            collapseHelper(spookyPosition, sm.player, sm.turn);
        }
    }
    public void collapse(int mark)
    {
        int position = 0;

        if (mark == 1)
        {
            position = toCollapse.position1;
        }
        else if (mark == 2)
        {
            position = toCollapse.position2;
        }
        int player = toCollapse.player;
        int turn   = toCollapse.turn;

        toCollapse = null;
        collapseHelper(position, player, turn);
        gameManager.finishCollapse();
        checkWin();
    }
 public void performAction(Board board)
 {
     if (actionType == 0)
     {
         board.squares[p1].addMark();
         board.squares[p2].addMark();
     }
     else if (actionType == 1)
     {
         SpookyMark toCollapse         = board.toCollapse;
         int        positionToCollapse = sqBot.position;
         Debug.Log("collapsing position: " + positionToCollapse);
         if (positionToCollapse == toCollapse.position1)
         {
             board.collapse(1);
         }
         else if (positionToCollapse == toCollapse.position2)
         {
             board.collapse(2);
         }
     }
 }
    public void collapse(int player, int turn, SpookyMark sm)
    {
        string p = "";

        if (player == 1)
        {
            p = "X";
            playerCollapsing = false;
        }
        else if (player == 2)
        {
            p = "O";
            playerCollapsing = true;
        }
        foreach (Transform square in board.transform)
        {
            square.gameObject.GetComponent <Square>().disableButton();
        }
        collapseText.text = "Select which square to collapse " + p + "<sub>" + turn.ToString() + "</sub>" + " into:";
        collapseButtons.SetActive(true);
        collapseButtons.transform.Find("Button1").Find("Text").GetComponent <Text>().text = "Square " + sm.position1;
        collapseButtons.transform.Find("Button2").Find("Text").GetComponent <Text>().text = "Square " + sm.position2;
    }
    public override bool Equals(object obj)
    {
        SpookyMark sm = (SpookyMark)obj;

        return(player == sm.player && turn == sm.turn && position1 == sm.position1 && position2 == sm.position2);
    }
    public void nextTurn()
    {
        int    lastPlayer      = currentPlayer;
        int    lastTurn        = turnNum;
        bool   switchedToBot   = false;
        bool   botSwitchedBack = false;
        string str             = "";

        if (currentPlayer == 1)
        {
            currentPlayer = 2;
            if (pvb)
            {
                str              = "Bot's turn";
                switchedToBot    = true;
                botThinking.text = "Bot is thinking...";
            }
            else
            {
                str = "Player O's turn";
            }
            playerCollapsing = false;
        }
        else if (currentPlayer == 2)
        {
            if (pvb)
            {
                botSwitchedBack  = true;
                botThinking.text = "";
            }
            currentPlayer = 1;
            str           = "Player X's turn";
        }
        turnNum++;
        playerTurn.text = str;
        foreach (Transform square in board.transform)
        {
            square.gameObject.GetComponent <Square>().reset();
        }
        SpookyMark s = board.GetComponent <Board>().addSpookyMark();

        if (s != null && !switchedToBot)
        {
            collapse(lastPlayer, lastTurn, s);
        }
        numMarks = 0;
        if (switchedToBot)
        {
            foreach (Transform square in board.transform)
            {
                square.gameObject.GetComponent <Square>().disableButton();
            }
            int actionType = 0;
            if (s != null)
            {
                actionType = 1;
            }
            StartCoroutine(botTurn(actionType, turnNum));
        }

        if (botSwitchedBack && !playerCollapsing)
        {
            foreach (Transform square in board.transform)
            {
                square.gameObject.GetComponent <Square>().enableButton();
            }
        }
    }
 public void addEdge(SpookyMark u, SpookyMark v)
 {
     adjlist[u].Add(v);
     adjlist[v].Add(u);
 }
 public void addVertex(SpookyMark v)
 {
     adjlist[v] = new HashSet <SpookyMark>();
 }