Ejemplo n.º 1
0
        /// <summary>
        /// Create new instance that is copy of old instance and delete one charakter from rack.
        /// </summary>
        /// <param name='del'>
        /// Char to delete from rack.
        /// </param>
        public TmpMove Copy(char del)
        {
            TmpMove pm2 = new TmpMove(this);

            pm2.rack = new List <char>(pm2.rack);
            pm2.rack.Remove(del);
            pm2.node = this.node.getSon(del);
            switch (pm2.direct)
            {
            case Direction.left:
                pm2.Word        = del + this.Word;
                pm2.ActualPoint = new Point(ActualPoint.X - 1, ActualPoint.Y);
                break;

            case Direction.right:
                pm2.Word        = this.Word + del;
                pm2.ActualPoint = new Point(ActualPoint.X + 1, ActualPoint.Y);
                break;

            case Direction.up:
                pm2.Word        = del + this.Word;
                pm2.ActualPoint = new Point(ActualPoint.X, ActualPoint.Y - 1);
                break;

            case Direction.down:
                pm2.Word        = this.Word + del;
                pm2.ActualPoint = new Point(ActualPoint.X, ActualPoint.Y + 1);
                break;
            }
            return(pm2);
        }
Ejemplo n.º 2
0
 public TmpMove(TmpMove pm)
 {
     LeftStart   = pm.LeftStart;
     StartPoint  = pm.StartPoint;
     direct      = pm.direct;
     rack        = pm.rack;
     Word        = pm.Word;
     ActualPoint = pm.ActualPoint;
 }
Ejemplo n.º 3
0
        public TmpMove TurnDown()
        {
            TmpMove pm2 = new TmpMove(this);

            pm2.direct      = Direction.down;
            pm2.LeftStart   = new Point(ActualPoint.X, ActualPoint.Y);
            pm2.ActualPoint = new Point(StartPoint.X, StartPoint.Y);
            pm2.node        = this.node.getSon('>');
            return(pm2);
        }
Ejemplo n.º 4
0
        private static bool cross(TmpMove m, char c)
        {
            int x = m.ActualPoint.X;
            int y = m.ActualPoint.Y;

            switch (m.direct)
            {
            case Direction.left:
            case Direction.right:
                // Alone stone
                try {
                    if (desk[x, y + 1] == '_' &&
                        desk[x, y - 1] == '_')
                    {
                        return(true);
                    }
                } catch {}
                // Go to begin of word
                while (true)
                {
                    y--;
                    if (y < 0 || desk[x, y] == '_')
                    {
                        y++;
                        break;
                    }
                }
                return(gaddag.Content(desk, x, y, true, x, y, c));

            case Direction.up:
            case Direction.down:
                // Alone stone
                try {
                    if (desk[x + 1, y] == '_' &&
                        desk[x - 1, y] == '_')
                    {
                        return(true);
                    }
                } catch {}
                // Go to begin of word
                while (true)
                {
                    x--;
                    if (x < 0 || desk[x, y] == '_')
                    {
                        x++;
                        break;
                    }
                }
                return(gaddag.Content(desk, x, y, false, x, y, c));

            default:
                return(true);
            }
        }
Ejemplo n.º 5
0
        private static void SearchRek(HashSet <Move> pool, TmpMove m)
        {
            // 1. check cross
            if (!cross(m, m.node.Content))
            {
                return;
            }

            // 2. this is full word - add
            if (m.node.Finite)
            {
                pool.Add(m.Convert2Move());
            }

            // 3. turn direction of movement
            if (m.node.isSon('>'))
            {
                if (m.direct == Direction.left)
                {
                    SearchRek(pool, m.TurnRight( ));
                }
                else
                {
                    SearchRek(pool, m.TurnDown( ));
                }
            }

            // 4. End of desk
            if (EndOfDesk(m))
            {
                return;                         // nothing to do
            }

            // 5. Go to next char
            char ch = NextChar(m);

            if ('_' != ch)                      // there are already puted some stone
            {
                if (m.node.isSon(ch))
                {
                    SearchRek(pool, m.Copy(ch));
                }
            }
            else                                        // blank desk (I can put own stone)
            {
                foreach (char c in m.rack)
                {
                    if (m.node.isSon(c))
                    {
                        SearchRek(pool, m.Copy(c));
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void StartOfRecursionLeftRight(HashSet <Move> pool, Node root, int x, int y, List <char> rack)
        {
            string s      = "";
            int    actual = x;

            // Go over the already puted stone to first '_'
            try {
                while (desk[actual, y] != '_')
                {
                    root = root.getSon(desk[actual, y]);
                    s    = desk[actual, y].ToString() + s;
                    actual--;
                }
                TmpMove tmp = new TmpMove(new Point(x, y), new Point(actual + 1, y),
                                          Direction.left, s, root, rack);
                SearchRek(pool, tmp);
            } catch (System.IndexOutOfRangeException) {}
        }
Ejemplo n.º 7
0
        private static char NextChar(TmpMove m)
        {
            switch (m.direct)
            {
            case Direction.left:
                return(desk[m.ActualPoint.X - 1, m.ActualPoint.Y]);

            case Direction.right:
                return(desk[m.ActualPoint.X + 1, m.ActualPoint.Y]);

            case Direction.up:
                return(desk[m.ActualPoint.X, m.ActualPoint.Y - 1]);

            case Direction.down:
                return(desk[m.ActualPoint.X, m.ActualPoint.Y + 1]);

            default:
                return('_');
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Availables the shift.
        /// </summary>
        /// <returns>
        /// Is shift posible?
        /// </returns>
        /// <param name='m'>
        /// Point at desk.
        /// </param>
        private static bool EndOfDesk(TmpMove m)
        {
            switch (m.direct)
            {
            case Direction.left:
                return(m.ActualPoint.X - 1 < 0 ? true : false);

            case Direction.right:
                return(m.ActualPoint.X + 1 >= SearchAlgorithm.desk.GetLength(0) ? true : false);

            case Direction.up:
                return(m.ActualPoint.Y - 1 < 0 ? true : false);

            case Direction.down:
                return(m.ActualPoint.Y + 1 >= SearchAlgorithm.desk.GetLength(1) ? true : false);

            default:
                return(true);
            }
        }
Ejemplo n.º 9
0
 public TmpMove TurnRight()
 {
     TmpMove pm2 = new TmpMove( this );
     pm2.direct = Direction.right;
     pm2.LeftStart = new Point( ActualPoint.X, ActualPoint.Y );
     pm2.ActualPoint = new Point( StartPoint.X, StartPoint.Y );
     pm2.node = this.node.getSon('>');
     return pm2;
 }
Ejemplo n.º 10
0
 public TmpMove( TmpMove pm )
 {
     LeftStart = pm.LeftStart;
     StartPoint = pm.StartPoint;
     direct = pm.direct;
     rack = pm.rack;
     Word = pm.Word;
     ActualPoint = pm.ActualPoint;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Create new instance that is copy of old instance and delete one charakter from rack.
 /// </summary>
 /// <param name='del'>
 /// Char to delete from rack.
 /// </param>
 public TmpMove Copy( char del )
 {
     TmpMove pm2 = new TmpMove( this );
     pm2.rack = new List<char>( pm2.rack );
     pm2.rack.Remove( del );
     pm2.node = this.node.getSon( del );
     switch( pm2.direct ) {
     case Direction.left:
         pm2.Word = del + this.Word;
         pm2.ActualPoint = new Point( ActualPoint.X -1, ActualPoint.Y );
         break;
     case Direction.right:
         pm2.Word = this.Word + del;
         pm2.ActualPoint = new Point( ActualPoint.X +1, ActualPoint.Y );
         break;
     case Direction.up:
         pm2.Word = del + this.Word;
         pm2.ActualPoint = new Point( ActualPoint.X, ActualPoint.Y -1 );
         break;
     case Direction.down:
         pm2.Word = this.Word + del;
         pm2.ActualPoint = new Point( ActualPoint.X, ActualPoint.Y +1 );
         break;
     }
     return pm2;
 }
Ejemplo n.º 12
0
 private static void StartOfRecursionLeftRight(HashSet<Move> pool, Node root, int x, int y, List<char> rack )
 {
     string s = "";
     int actual = x;
     // Go over the already puted stone to first '_'
     try {
         while( desk[actual,y] != '_' ) {
             root = root.getSon( desk[actual,y] );
             s = desk[actual,y].ToString() + s;
             actual--;
         }
         TmpMove tmp = new TmpMove( new Point(x,y), new Point(actual+1,y),
                                         Direction.left, s,root, rack );
         SearchRek( pool, tmp );
     } catch (System.IndexOutOfRangeException) {}
 }
Ejemplo n.º 13
0
        private static void SearchRek(HashSet<Move> pool, TmpMove m )
        {
            // 1. check cross
            if( ! cross( m , m.node.Content ) ) {
                return;
            }

            // 2. this is full word - add
            if( m.node.Finite ) {
                pool.Add( m.Convert2Move() );
            }

            // 3. turn direction of movement
            if( m.node.isSon('>') ) {
                if( m.direct == Direction.left )
                    SearchRek( pool, m.TurnRight( ) );
                else
                    SearchRek( pool, m.TurnDown( ) );
            }

            // 4. End of desk
            if( EndOfDesk( m ) ) {
                return;		// nothing to do
            }

            // 5. Go to next char
            char ch = NextChar(m);
            if( '_' !=  ch ) {	// there are already puted some stone
                if( m.node.isSon( ch ) )	{
                    SearchRek( pool, m.Copy( ch ) );
                }
            } else {			// blank desk (I can put own stone)
                foreach( char c in m.rack ) {
                    if( m.node.isSon( c ) ) {
                        SearchRek( pool, m.Copy( c ) );
                    }
                }
            }
        }
Ejemplo n.º 14
0
 private static char NextChar(TmpMove m)
 {
     switch( m.direct ) {
     case Direction.left :
         return desk[ m.ActualPoint.X -1, m.ActualPoint.Y];
     case Direction.right :
         return desk[ m.ActualPoint.X +1, m.ActualPoint.Y];
     case Direction.up :
         return desk[ m.ActualPoint.X , m.ActualPoint.Y -1];
     case Direction.down :
         return desk[ m.ActualPoint.X , m.ActualPoint.Y +1];
     default :
         return '_';
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Availables the shift.
 /// </summary>
 /// <returns>
 /// Is shift posible?
 /// </returns>
 /// <param name='m'>
 /// Point at desk.
 /// </param>
 private static bool EndOfDesk(TmpMove m)
 {
     switch( m.direct ) {
     case Direction.left :
         return m.ActualPoint.X -1 < 0 ? true : false;
     case Direction.right :
         return m.ActualPoint.X +1 >= SearchAlgorithm.desk.GetLength(0) ? true : false;
     case Direction.up :
         return m.ActualPoint.Y -1 < 0 ? true : false;
     case Direction.down :
         return m.ActualPoint.Y +1 >= SearchAlgorithm.desk.GetLength(1) ? true : false;
     default :
         return true;
     }
 }
Ejemplo n.º 16
0
 private static bool cross(TmpMove m, char c)
 {
     int x = m.ActualPoint.X;
     int y = m.ActualPoint.Y;
     switch( m.direct ) {
     case Direction.left :
     case Direction.right :
         // Alone stone
         try {
             if( desk[x,y+1] == 	'_' &&
                 desk[x,y-1] == 	'_' ) return true;
         } catch{}
         // Go to begin of word
         while( true ) {
             y--;
             if( y < 0 || desk[x,y] == '_' ) {
                 y++;
                 break;
             }
         }
         return gaddag.Content(desk, x, y, true, x, y, c);
     case Direction.up :
     case Direction.down :
         // Alone stone
         try {
             if( desk[x+1,y] == 	'_' &&
                 desk[x-1,y] == 	'_' ) return true;
         } catch{}
         // Go to begin of word
         while( true ) {
             x--;
             if( x < 0 || desk[x,y] == '_' ) {
                 x++;
                 break;
             }
         }
         return gaddag.Content(desk, x, y, false, x, y,c);
     default :
         return true;
     }
 }