コード例 #1
0
        protected TaquinNode Build(TaquinGame gameRef, TaquinNode targetState, int n)
        {
            int sz = gameRef.Size;

            if (this.w < 1 || this.h < 1)
            {
                this.x = this.y = 0;
                this.w = this.h = sz;
            }

            if (n == 0)
            {
                int[,] r = new int[sz, sz];
                for (int i = 0; i < sz; i++)
                {
                    for (int j = 0; j < sz; j++)
                    {
                        r[i, j] = -1;
                    }
                }
                return(new TaquinNode(r));
            }
            else if (n == 2 * sz - 3)
            {
                return(targetState);
            }

            if (n % 2 == 1)
            {
                int[,] r1 = this.saved?.Grid ?? this.Build(gameRef, targetState, n - 1).Grid;

                if (!this.IsGapIn(targetState.Grid, x, 0))
                {
                    for (int k = y; k < y + h; k++)
                    {
                        r1[x, k] = targetState.Grid[x, k];
                    }
                    x++;
                }
                else
                {
                    for (int k = y; k < y + h; k++)
                    {
                        r1[x + w - 1, k] = targetState.Grid[x + w - 1, k];
                    }
                }
                w--;

                return(new TaquinNode(r1));
            }
            else
            {
                int[,] r2 = this.saved?.Grid ?? this.Build(gameRef, targetState, n - 1).Grid;

                if (!this.IsGapIn(targetState.Grid, y, 1))
                {
                    for (int k = x; k < x + w; k++)
                    {
                        r2[k, y] = targetState.Grid[k, y];
                    }
                    y++;
                }
                else
                {
                    for (int k = x; k < x + w; k++)
                    {
                        r2[k, y + h - 1] = targetState.Grid[k, y + h - 1];
                    }
                }
                h--;

                return(new TaquinNode(r2));
            }
        }
コード例 #2
0
 protected override ANode <TaquinGame.Move> BuildSolutionStep(AGame <TaquinGame.Move> gameRef, ANode <TaquinGame.Move> targetState, int n)
 {
     this.filter = this.saved ?? this.Build(gameRef as TaquinGame, targetState as TaquinNode, 0);
     this.saved  = this.Build(gameRef as TaquinGame, targetState as TaquinNode, n);
     return(this.saved);
 }