Example #1
0
        private bool isWin()
        {
            // Tao mot ngan xep
            STACK <Po> stack = new STACK <Po>();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (buttons[i, j].Name == NAME_BUTTON)
                    {
                        stack.push(new Po(i, j));
                    }
                }
            }

            while (!stack.isEmpty())
            {
                Po p = stack.pop();
                if (checkPoint(p) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        private bool checkPoint(Po p)
        {
            char num = buttons[p.x, p.y].Text[0];

            if (num == '0')
            {
                return(false);
            }

            // Lay doc
            STACK <String> vetical = new STACK <string>();

            for (int i = 0; i < 9; i++)
            {
                if (i != p.y)
                {
                    vetical.push(buttons[p.x, i].Text);
                }
            }
            while (!vetical.isEmpty())
            {
                String item = vetical.pop();
                if (item == buttons[p.x, p.y].Text)
                {
                    return(false);
                }
            }

            // Lay ngang
            STACK <String> horizontal = new STACK <string>();

            for (int i = 0; i < 9; i++)
            {
                if (i != p.x)
                {
                    horizontal.push(buttons[i, p.y].Text);
                }
            }
            while (!horizontal.isEmpty())
            {
                String item = horizontal.pop();
                if (item == buttons[p.x, p.y].Text)
                {
                    return(false);
                }
            }

            // Lay block 3*3
            STACK <String> block  = new STACK <string>();
            int            startx = (p.x / 3) * 3;
            int            starty = (p.y / 3) * 3;

            for (int i = startx; i < startx + 3; i++)
            {
                for (int j = starty; j < starty + 3; j++)
                {
                    if (i == p.x && j == p.y)
                    {
                        continue;
                    }
                    block.push(buttons[i, j].Text);
                }
            }
            while (!block.isEmpty())
            {
                String item = block.pop();
                if (item == buttons[p.x, p.y].Text)
                {
                    return(false);
                }
            }


            return(true);
        }