public static void Main()
    {
        int[,] board = new int[,]{
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
            {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
        };

        board = Flip(board);

        ThreatSearcher searcher = new ThreatSearcher();

        ThreatList threats = searcher.investigate(board, new Coordinate(0, 13), 1);

        foreach (Threat t in threats)
            Console.WriteLine(t.ToString());
    }
    public static void Main()
    {
        int[,] board = new int[, ] {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
        };

        board = Flip(board);

        ThreatSearcher searcher = new ThreatSearcher();

        ThreatList threats = searcher.investigate(board, new Coordinate(0, 13), 1);

        foreach (Threat t in threats)
        {
            Console.WriteLine(t.ToString());
        }
    }
Ejemplo n.º 3
0
    public void UpdateThreatLists(int[,] board, Coordinate move, int attacker)
    {
        // 0. Initialized the removelists
        ownremovedthreatlist = new ThreatList();
        oppremovedthreatlist = new ThreatList();
        ownaddedthreatlist   = new ThreatList();
        oppaddedthreatlist   = new ThreatList();

        // 1. Remove blocked threats from both lists.
        ThreatList lookup = new ThreatList();

        foreach (Threat t in oppthreatlist)
        {
            foreach (Coordinate c in t.fields)
            {
                if (c.X == move.X && c.Y == move.Y)
                {
                    oppremovedthreatlist.Add(t);
                    lookup.Add(t.cause);
                }
            }
        }
        foreach (Threat t in oppremovedthreatlist)
        {
            oppthreatlist.Remove(t);
        }
        foreach (Threat t in ownthreatlist)
        {
            foreach (Coordinate c in t.fields)
            {
                if (c.X == move.X && c.Y == move.Y)
                {
                    ownremovedthreatlist.Add(t);
                    lookup.Add(t.cause);
                }
            }
        }
        foreach (Threat t in ownremovedthreatlist)
        {
            ownthreatlist.Remove(t);
        }

        //Lookup if "causes" still cause threats
        foreach (Coordinate c in lookup)
        {
            if (board[c.X, c.Y] == 1)
            {
                ThreatList curthreats = searcher.investigate(board, c, 1);

                ownaddedthreatlist = Merge(ownthreatlist, curthreats);
            }
            if (board[c.X, c.Y] == -1)
            {
                ThreatList curthreats = searcher.investigate(board, c, -1);

                oppaddedthreatlist = Merge(oppthreatlist, curthreats);
            }
        }

        if (attacker == 1)
        {
            // We are attacking
            // 2. Add our threats we build to our list

            ThreatList curthreats = searcher.investigate(board, move, attacker, true);

            Merge(ownaddedthreatlist, Merge(ownthreatlist, curthreats));
        }
        else
        {
            // The opponent is attacking
            // 2. Add his threats to his list
            ThreatList curthreats = searcher.investigate(board, move, attacker, true);

            Merge(oppaddedthreatlist, Merge(oppthreatlist, curthreats));
        }
    }