コード例 #1
0
ファイル: TreeNode.cs プロジェクト: JakubKorcak/Rocnikac4
        public List<string> allRoutes(TreeNode root)
        {
            List<string> cesty = new List<string>();
            string cesta;

            if (root.childs.Count > 0)
            {
                foreach (TreeNode potomek in root.childs)
                {
                    List<string> vysledek = allRoutes(potomek);
                    foreach (string s in vysledek)
                    {
                        cesta = root.over + "-" + root.dest + "-" + s;
                        cesty.Add(cesta);
                    }
                }
            }
            else
            {
                cesta = root.over + "-" + root.dest;
                cesty.Add(cesta);
                return cesty;
            }
            return cesty;
        }
コード例 #2
0
ファイル: Rules.cs プロジェクト: korczis/Rocnikac4
        private TreeNode genWalJumpTree(Gameboard gb, Fairway fw)
        {
            var root = new TreeNode();
            int x = Convert.ToInt32(fw.Name.Substring(1)) - 1;
            int y = Convert.ToInt32(fw.Name[0]) - 'A';

            for (int i = 0; i < 8; i++)
            {
                if (checkPossibleJump(gb, fw, xs[i], ys[i]))
                {
                    Gameboard potomek = gb.gameboardCopy();
                    Fairway from = potomek.Board[x, y];
                    Fairway over = potomek.Board[x + xs[i], y + ys[i]];
                    Fairway to = potomek.Board[x + 2*xs[i], y + 2*ys[i]];

                    TreeNode jump;

                    bool bQ = from.Queen;
                    makeJump(from, over, to);
                    bool aQ = to.Queen;

                    if (bQ == aQ)
                        jump = genWalJumpTree(potomek, to);
                    else
                        jump = new TreeNode();

                    jump.over = over.Name;
                    jump.dest = to.Name;
                    root.childs.Add(jump);
                    jump.rank = over.Queen ? 3 : 2;
                }
            }
            return root;
        }
コード例 #3
0
ファイル: Rules.cs プロジェクト: korczis/Rocnikac4
        private TreeNode genQueJumpTree(Gameboard gb, Fairway fw)
        {
            var root = new TreeNode();
            var moves = new List<string>();
            int x = Convert.ToInt32(fw.Name.Substring(1)) - 1;
            int y = Convert.ToInt32(fw.Name[0]) - 'A';
            status playerOnMove = gb.PlayingWhite ? status.whitePlayer : status.blackPlayer;

            for (int i = 0; i < 8; i++)
            {
                bool jump = false;
                for (int j = 1;
                     x + j*xs[i] < GlobalVariables.size &&
                     x + j*xs[i] >= 0 &&
                     y + j*ys[i] < GlobalVariables.size &&
                     y + j*ys[i] >= 0;
                     j++)
                {
                    // pokud je vedle volno, pridej do moves
                    if (gb.Board[x + j*xs[i], y + j*ys[i]].Player == status.free && !jump)
                    {
                        string move = (char) (y + j*ys[i] + 'A') + "" + (x + j*xs[i] + 1);
                    }
                        // pokud je vedle tvoje vlastni figurka, prerus
                    else if (gb.Board[x + j*xs[i], y + j*ys[i]].Player == playerOnMove)
                    {
                        break;
                    }
                    else if (
                        x + (j + 1)*xs[i] < GlobalVariables.size &&
                        x + (j + 1)*xs[i] >= 0 &&
                        y + (j + 1)*ys[i] >= 0 &&
                        y + (j + 1)*ys[i] < GlobalVariables.size &&
                        (int) gb.Board[x + j*xs[i], y + j*ys[i]].Player == -(int) playerOnMove &&
                        gb.Board[x + (j + 1)*xs[i], y + (j + 1)*ys[i]].Player == status.free)
                    {
                        jump = true;
                        Gameboard potomek = gb.gameboardCopy();
                        Fairway from = potomek.Board[x, y];
                        Fairway over = potomek.Board[x + j*xs[i], y + j*ys[i]];
                        Fairway to = potomek.Board[x + (j + 1)*xs[i], y + (j + 1)*ys[i]];

                        makeJump(from, over, to);
                        List<Fairway> destinies = queAfterJumpDests(potomek, to, xs[i], ys[i]);
                        destinies.Insert(0, to);

                        foreach (var des in destinies)
                        {
                            TreeNode node = genQueJumpTree(potomek, des);
                            node.over = over.Name;
                            node.dest = des.Name;
                            node.rank = over.Queen ? 3 : 2;
                            root.childs.Add(node);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return root;
        }