Click here to Skip to main content
15,887,585 members
Home / Discussions / C#
   

C#

 
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 
QuestionTimezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
devvvy8-Dec-11 17:06
devvvy8-Dec-11 17:06 
AnswerRe: Timezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
Richard MacCutchan8-Dec-11 22:28
mveRichard MacCutchan8-Dec-11 22:28 
AnswerRe: Timezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
jschell9-Dec-11 11:23
jschell9-Dec-11 11:23 
QuestionList<T>.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus8-Dec-11 15:42
Firo Atrum Ventus8-Dec-11 15:42 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
PIEBALDconsult8-Dec-11 16:06
mvePIEBALDconsult8-Dec-11 16:06 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus8-Dec-11 16:19
Firo Atrum Ventus8-Dec-11 16:19 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
Luc Pattyn8-Dec-11 22:02
sitebuilderLuc Pattyn8-Dec-11 22:02 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus9-Dec-11 4:58
Firo Atrum Ventus9-Dec-11 4:58 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
BobJanova8-Dec-11 22:37
BobJanova8-Dec-11 22:37 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus9-Dec-11 5:07
Firo Atrum Ventus9-Dec-11 5:07 
QuestionPorting VS 2005 => 2010: "Could not load file or assembly..." [SOLVED] Pin
Alan Balkany8-Dec-11 12:14
Alan Balkany8-Dec-11 12:14 
AnswerRe: Porting VS 2005 => 2010: "Could not load file or assembly..." Pin
Richard MacCutchan8-Dec-11 22:22
mveRichard MacCutchan8-Dec-11 22:22 
GeneralRe: Porting VS 2005 => 2010: "Could not load file or assembly..." Pin
Alan Balkany9-Dec-11 4:55
Alan Balkany9-Dec-11 4:55 

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.