Example #1
0
 public Action(int position1, int position2)
 {
     actionType = 0;
     this.p1    = position1;
     this.p2    = position2;
     sqBot      = null;
 }
    public BoardBot(Board b, GameManagerBot gameManager)
    {
        this.gameManager = gameManager;
        Square[] s = b.squares;
        SquareBot[] sb = new SquareBot[s.Length];
        for (int i = 0; i < s.Length; i++)
        {
            sb[i] = new SquareBot(gameManager, s[i]);
        }
        List<SpookyMarkBot> smb = new List<SpookyMarkBot>();
        foreach (SpookyMark sm in b.spookyMarks)
        {
            smb.Add(new SpookyMarkBot(sm));
        }
        List<MarkBot> mb = new List<MarkBot>();
        foreach (Mark m in b.currentSpookyMark)
        {
            mb.Add(new MarkBot(m));
        }
        List<int> collapsed = new List<int>(b.collapsed);

        if (b.toCollapse == null)
        {
            this.init(new GraphBot(b.entGraph, gameManager), sb, smb, collapsed,
            null, mb, b.nextAction);
        } else
        {
            this.init(new GraphBot(b.entGraph, gameManager), sb, smb, collapsed,
                new SpookyMarkBot(b.toCollapse), mb, b.nextAction);
        }
    }
Example #3
0
    private List <Action> getLegalActions(BoardBot board, int actionType, int agent, int turnNum)
    {
        // Generate all possible actions

        List <Action> result = new List <Action>();

        if (actionType == 1)
        {
            // return the two possible squares we can collapse into.
            SpookyMarkBot sm = board.toCollapse;
            if (sm == null)
            {
                //log error
                Debug.Log("ERROR: Illegal action requested from bot.");
                return(null);
            }
            int pos1 = sm.position1;
            int pos2 = sm.position2;
            Debug.Log("Will collapse position: " + board.squares[pos1].position);
            result.Add(new Action(board.squares[pos1]));
            result.Add(new Action(board.squares[pos2]));
            return(result);
        }

        // Otherwise we return all the possible spookyMarks to add
        // First find all possible squares we can put marks on.
        List <int> validSquares = new List <int>();

        for (int i = 0; i < 9; i++)
        {
            SquareBot sq = board.squares[i];
            if (!sq.classicallyMarked && sq.filledMarks < 8)
            {
                validSquares.Add(i);
            }
        }
        // If no valid squares, return null
        if (validSquares.Count == 0)
        {
            return(null);
        }
        // If only one valid square, duplicate it so combinations(2, count) doesn't freak out
        if (validSquares.Count == 1)
        {
            validSquares.Add(validSquares[0]);
        }

        foreach (int first in validSquares)
        {
            foreach (int second in validSquares)
            {
                if (second <= first)
                {
                    continue;
                }
                result.Add(new Action(first, second));
            }
        }
        return(result);
    }
    public void collapseHelper(int position, int player, int turn)
    {
        if (collapsed.Contains(position))
        {
            return;
        }
        SquareBot square = squares[position];
        square.setBigMark(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 (MarkBot mark in square.getMarks())
        {
            SpookyMarkBot sm = mark.sm;
            int spookyPosition;
            if (sm.position1 == position)
            {
                spookyPosition = sm.position2;
            }
            else
            {
                spookyPosition = sm.position1;
            }
            collapseHelper(spookyPosition, sm.player, sm.turn);
        }
    }
    public void deleteEdgeSQ(SquareBot u, SquareBot v)
    {
        if (adjlistSQ[u].Contains(v))
        {
            adjlistSQ[u].Remove(v);
        }

        if (adjlistSQ[v].Contains(u))
        {
            adjlistSQ[v].Remove(u);
        }
    }
 public bool removeCycleSQ(SquareBot v)
 {
     if (getCycleSQ(v) != null)
     {
         foreach (SquareBot j in getCycleSQ(v))
         {
             deleteEdgeSQ(v, j);
         }
         return(true);
     }
     return(false);
 }
    public HashSet <SquareBot> getCycleSQ(SquareBot i)
    {
        HashSet <SquareBot> visited = new HashSet <SquareBot>();

        if (dfsSQ(i, visited, null))
        {
            HashSet <SquareBot> newVisited = new HashSet <SquareBot>(visited);
            foreach (SquareBot j in visited)
            {
                dfsComplete(j, newVisited, null);
            }
            return(newVisited);
        }
        return(null);
    }
 public bool dfsComplete(SquareBot i, HashSet <SquareBot> visited, SquareBot parent)
 {
     visited.Add(i);
     foreach (SquareBot j in adjlistSQ[i])
     {
         if (visited.Contains(j))
         {
             continue;
         }
         else if (dfsSQ(j, visited, i))
         {
             return(true);
         }
     }
     return(false);
 }
    public GraphBot(GraphBot g, GameManagerBot gameManager)
    {
        Dictionary <SquareBot, HashSet <SquareBot> > adjlistSQ = new Dictionary <SquareBot, HashSet <SquareBot> >();
        Dictionary <SquareBot, HashSet <SquareBot> > gList     = g.adjlistSQ;

        foreach (KeyValuePair <SquareBot, HashSet <SquareBot> > kvp in gList)
        {
            SquareBot           sb = new SquareBot(gameManager, kvp.Key);
            HashSet <SquareBot> h  = new HashSet <SquareBot>();
            foreach (SquareBot sq in kvp.Value)
            {
                h.Add(new SquareBot(gameManager, sq));
            }
            adjlistSQ.Add(sb, h);
        }
        this.init(adjlistSQ);
    }
    public SquareBot(GameManagerBot gmb, SquareBot sq)
    {
        List <MarkBot> pms = new List <MarkBot>();

        foreach (MarkBot m in sq.presentMarks)
        {
            if (m.sm != null)
            {
                pms.Add(new MarkBot(m.player, m.turn, m.position, new SpookyMarkBot(m.sm)));
            }
            else
            {
                pms.Add(new MarkBot(m.player, m.turn, m.position, null));
            }
        }
        this.init(gmb, pms, sq.position, sq.alreadyMarked, sq.classicallyMarked,
                  sq.finalPlayer, sq.finalTurn, sq.filledMarks);
    }
    // Returns true if there is a cycle
    public bool addEdgeSQ(SquareBot u, SquareBot v)
    {
        HashSet <SquareBot> m = null;

        if (!adjlistSQ.TryGetValue(u, out m))
        {
            adjlistSQ[u] = new HashSet <SquareBot>();
        }
        if (!adjlistSQ.TryGetValue(v, out m))
        {
            adjlistSQ[v] = new HashSet <SquareBot>();
        }

        // Two Square cycle case
        if (adjlistSQ[u].Contains(v) && adjlistSQ[v].Contains(u))
        {
            return(true);
        }
        adjlistSQ[u].Add(v);
        adjlistSQ[v].Add(u);
        return(false);
    }
Example #12
0
 public Action(SquareBot toCollapse)
 {
     actionType = 1;
     sqBot      = toCollapse;
 }
Example #13
0
    private int evalplayer(BoardBot board, int agent)
    { // return Score
        int score = 0;

        agent++;
        // Look through every square
        for (int i = 0; i < 9; i++)
        {
            //Debug.Log("Square " + i + ": ");
            SquareBot sq = board.squares[i];
            if (sq.classicallyMarked && sq.finalPlayer != agent)
            {
                continue;
            }

            List <int> neighbors = getNeighbor(i);

            // Look into every neighbor
            foreach (int k in neighbors)
            {
                int       gain  = 0;
                SquareBot neigh = board.squares[k];

                // Always good to be next to your own classical mark
                if (neigh.classicallyMarked && neigh.finalPlayer == agent)
                {
                    gain += 100;
                }
                // Always good to have empty neighbor. More chance for expansion.
                else if (neigh.filledMarks == 0)
                {
                    gain += 5;
                }

                // Last case is when neighbor has spooky marks
                else
                {
                    // more marks means more competition. Gotta win!
                    gain += 10 * neigh.presentMarks.Count;

                    // Penalize if spooky mark is the opponent
                    foreach (MarkBot m in neigh.presentMarks)
                    {
                        if (m.player == agent)
                        {
                            gain += 2;
                        }
                        if (m.player != agent)
                        {
                            gain -= 5;
                        }
                    }
                }
                if (sq.classicallyMarked)
                {
                    gain *= 2;
                }
                score += gain;
            }
        }
        return(score);
    }