// Return true if there is some valid path from the specified source
        // position to the specified target position; otherwise return false.
        public bool IsValidPath(TzaarBoard board, int fromCol, int fromRow, int toCol, int toRow)
        {
            if (!board.IsValidPosition(fromCol, fromRow) || !board.IsValidPosition(toCol, toRow))
                // Parameters are out of range.
                return false;

            Node fromNode = paths[fromCol][fromRow];
            Node toNode = paths[toCol][toRow];

            if (fromCol == toCol)
            {
                if (fromRow == toRow)
                    // We can't move to ourselves!
                    return false;

                // The target is in the same column as the source.  So, we are
                // either going north or south.
                if (fromRow < toRow)
                    // Go north!
                    return ExplorePath(board, fromNode, toNode, "n");
                else
                    // Go south!
                    return ExplorePath(board, fromNode, toNode, "s");
            }
            else if (toCol > fromCol)
            {
                // Go east!

                // Try northeast first.
                if (ExplorePath(board, fromNode, toNode, "ne"))
                    return true;
                else
                    // Try southeast.
                    return ExplorePath(board, fromNode, toNode, "se");
            }
            else
            {
                // Go west!

                // Try northwest first.
                if (ExplorePath(board, fromNode, toNode, "nw"))
                    return true;
                else
                    // Try southwest.
                    return ExplorePath(board, fromNode, toNode, "sw");
            }
        }
        // Scan the board and update the counts for each piece still remaining.
        private static void UpdatePieceCount(TzaarBoard board)
        {
            // The entire board is scanned for the update, so destroy the old
            // count values.
            board.blackTzaarCount = 0;
            board.blackTzarraCount = 0;
            board.blackTottCount = 0;

            board.whiteTzaarCount = 0;
            board.whiteTzarraCount = 0;
            board.whiteTottCount = 0;

            // Scan each space of the board to update.
            for (int i = 0; i < 9; i++)
                for (int j = 0; j < 9; j++)
                {
                    // If the position is not valid, we have passed the end of
                    // the column. Move to the next column.
                    if (!board.IsValidPosition(i, j))
                        break;

                    // Otherwise, find the color and number of pieces at the
                    // current position and update accordingly.
                    Stack<TzaarPiece> S = board.board[i][j].Query();
                    if (S.Count == 0)
                        continue;

                    TzaarPiece topPiece = S.Peek();
                    if (topPiece.Color == TzaarColor.WHITE)
                    {
                        if (topPiece.GetType() == typeof(TzaarPiece.Tzaar))
                            board.whiteTzaarCount++;
                        else if (topPiece.GetType() == typeof(TzaarPiece.Tzarra))
                            board.whiteTzarraCount++;
                        else
                            board.whiteTottCount++;
                    }
                    else
                    {
                        if (topPiece.GetType() == typeof(TzaarPiece.Tzaar))
                            board.blackTzaarCount++;
                        else if (topPiece.GetType() == typeof(TzaarPiece.Tzarra))
                            board.blackTzarraCount++;
                        else
                            board.blackTottCount++;
                    }
                }
        }