Click here to Skip to main content
15,897,273 members
Home / Discussions / C#
   

C#

 
GeneralRe: Working On Communication Protocols Pin
Eddy Vluggen12-Dec-11 6:04
professionalEddy Vluggen12-Dec-11 6:04 
Questionconflict of interest, COI...in systemwatcher and stream reader... Pin
beh760610-Dec-11 23:34
beh760610-Dec-11 23:34 
AnswerRe: conflict of interest, COI...in systemwatcher and stream reader... Pin
Eddy Vluggen11-Dec-11 12:26
professionalEddy Vluggen11-Dec-11 12:26 
AnswerRe: conflict of interest, COI...in systemwatcher and stream reader... Pin
Luc Pattyn11-Dec-11 13:10
sitebuilderLuc Pattyn11-Dec-11 13:10 
GeneralRe: conflict of interest, COI...in systemwatcher and stream reader... Pin
beh760611-Dec-11 15:48
beh760611-Dec-11 15:48 
Questionregular expressions groups Pin
benams10-Dec-11 22:20
benams10-Dec-11 22:20 
AnswerRe: regular expressions groups Pin
OriginalGriff11-Dec-11 0:50
mveOriginalGriff11-Dec-11 0:50 
AnswerRe: regular expressions groups Pin
PIEBALDconsult11-Dec-11 8:18
mvePIEBALDconsult11-Dec-11 8:18 
QuestionHow to set up Winforms app to avoid piracy? Pin
swampwiz10-Dec-11 5:34
swampwiz10-Dec-11 5:34 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
harold aptroot10-Dec-11 6:00
harold aptroot10-Dec-11 6:00 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
OriginalGriff10-Dec-11 21:46
mveOriginalGriff10-Dec-11 21:46 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
Not Active10-Dec-11 6:07
mentorNot Active10-Dec-11 6:07 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
PIEBALDconsult10-Dec-11 8:21
mvePIEBALDconsult10-Dec-11 8:21 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen10-Dec-11 13:16
professionalEddy Vluggen10-Dec-11 13:16 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Addy Tas11-Dec-11 1:49
Addy Tas11-Dec-11 1:49 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen11-Dec-11 12:27
professionalEddy Vluggen11-Dec-11 12:27 
QuestionCall to REST WCF service creating a file instead of string Pin
nitin_ion10-Dec-11 1:09
nitin_ion10-Dec-11 1:09 
AnswerRe: Call to REST WCF service creating a file instead of string Pin
Richard MacCutchan10-Dec-11 2:54
mveRichard MacCutchan10-Dec-11 2:54 
Question8 queens in c# Pin
Member 84662349-Dec-11 21:34
Member 84662349-Dec-11 21:34 
AnswerRe: 8 queens in c# PinPopular
Luc Pattyn10-Dec-11 0:15
sitebuilderLuc Pattyn10-Dec-11 0:15 
GeneralRe: 8 queens in c# Pin
Member 846623410-Dec-11 14:04
Member 846623410-Dec-11 14:04 
The reason I went graphic first is because I already had a algorithm code. The problem with the algorithm is that it runs perfectly on console but i do not know how to make it run on windows form. Here is what I have:
It is changed up because I tried to make it a form

C#
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConsoleApplication7
{
    class Program
    {
        public enum Square
        {
            size = 8
        }
        public class EightQueen
        {
            public static int count = 0;
            public static bool isValidMove(int[,] Array, int row, int col)
            {
                //Checks if there are more than one queen in that column.
                //returns a false boolean if there is more than one.
                for (int i = 0; i < Square.size.GetHashCode(); i++)
                    if (Array[row, i] == 1)
                        return false;
                //Checks if there are more than one queen in that row.
                //returns a false boolean if there is more than one.
                for (int i = 0; i < Square.size.GetHashCode(); i++)
                    if (Array[i, col] == 1)
                        return false;
                int tempCol = col + 1, tempRow = row;
                //checking more than one column/rows combined for more than one queen.
                for (int i = row + 1; i < Square.size.GetHashCode(); i++)
                {
                    if (tempCol < Square.size.GetHashCode())
                    {
                        if (Array[i, tempCol] == 1)
                            return false;
                        else
                            tempCol++;
                    }
                    else
                        break;
                }
                tempCol = col - 1;
                for (int i = row - 1; i >= 0; i--)
                {
                    if (tempCol >= 0)
                    {
                        if (Array[i, tempCol] == 1)
                            return false;
                        else
                            tempCol--;
                    }
                    else
                        break;
                }
                tempCol = col - 1;
                for (int i = row + 1; i < Square.size.GetHashCode(); i++)
                {
                    if (tempCol >= 0)
                    {
                        if (Array[i, tempCol] == 1)
                            return false;
                        else
                            tempCol--;
                    }
                    else
                        break;
                }
                tempCol = col + 1;
                for (int i = row - 1; i >= 0; i--)
                {
                    if (tempCol < Square.size.GetHashCode())
                    {
                        if (Array[i, tempCol] == 1)
                            return false;
                        else
                            tempCol++;
                    }
                    else
                        break;
                }

                return true;
            }

            public static void DisplayChessBoard(int[,] boardArr)
            {
                int count = 0;
                for (int i = 0; i < Square.size.GetHashCode(); i++)
                    for (int j = 0; j < Square.size.GetHashCode(); j++)
                        if (boardArr[i, j] == 1)
                            count++;
                if (count >= 8)
                    ShowBoard(boardArr);
            }
            public static void ShowBoard(int[,] boardArray)
            {
                for (int i = 0; i < Square.size.GetHashCode(); i++)
                {
                    for (int j = 0; j < Square.size.GetHashCode(); j++)
                        Console.Write("{0} ", boardArray[i, j]);
                    Console.WriteLine();
                }
                count++;
                Console.WriteLine();
                //Console.ReadKey();
            }
            public static void Chessboard(int[,] boardArr, int row, int col)
            {
                for (int i = row; i < Square.size.GetHashCode(); i++)
                {
                    for (int j = 0; j < Square.size.GetHashCode(); j++)
                    {
                        if (isValidMove(boardArr, i, j))
                        {
                            boardArr[i, j] = 1;
                            DisplayChessBoard(boardArr);
                            Chessboard(boardArr, i + 1, j + 1);
                            boardArr[i, j] = 0;
                        }

                    }
                }
            }
            static void Main()
            {
                Application.EnableVisualStyles();
                int[,] boardArr = new int[Square.size.GetHashCode(), Square.size.GetHashCode()];
                for (int i = 0; i < Square.size.GetHashCode(); i++)
                    for (int j = 0; j < Square.size.GetHashCode(); j++)
                        boardArr[i, j] = 0;
                Chessboard(boardArr, 0, 0);

                Console.WriteLine("Total Solutions {0}", count);
                //Console.ReadKey(); this was removed because I was trying to convert it to form
                Application.Run(new Form1());
            }
        }
    }
}

AnswerRe: 8 queens in c# Pin
Luc Pattyn10-Dec-11 14:29
sitebuilderLuc Pattyn10-Dec-11 14:29 
GeneralRe: 8 queens in c# Pin
Member 846623410-Dec-11 15:31
Member 846623410-Dec-11 15:31 
AnswerRe: 8 queens in c# Pin
Luc Pattyn10-Dec-11 22:10
sitebuilderLuc Pattyn10-Dec-11 22:10 
AnswerRe: 8 queens in c# Pin
PIEBALDconsult10-Dec-11 2:46
mvePIEBALDconsult10-Dec-11 2:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.