예제 #1
0
        public static bool computerFirst;         //1 zaczyna komputer; 0 czlowiek

        static void Main(string[] args)
        {
            //Losowy start jak skoñczê heurystykê
            computerFirst = true;             //true jesli komputer zaczyna (pozniej zostanie zmienione)
            //Console.SetWindowSize(50,20);//wysokosc i szerokosc konsoli w razie czego zmienic lub usunac


            KeyAction     keyAction  = new KeyAction();
            Connect4State startState = new Connect4State();

            char[] playersMark = { 'o', 'x' };
            int    i           = 0;

            while (true)
            {
                Console.Clear();
                if (i % 2 == 0)
                {
                    Console.Write("Punkty: " + startState.ComputeHeuristicGrade() + "\n");
                    Console.Write("KKKK: " + playersMark[i] + "\n");

                    startState.Print();
                    int choosenColumn = keyAction.getColNum();

                    startState.insertToken(choosenColumn, playersMark[i]);
                }
                else
                {
                    Connect4Search search = new Connect4Search(startState, true, 1);
                    search.DoSearch();


                    Console.Write("Length: " + search.MovesMiniMaxes.Count + '\n');
                    foreach (KeyValuePair <string, double> kvp in search.MovesMiniMaxes)
                    {
                        Console.Write(kvp.Key.Length + "<- le ");
                        Console.Write(kvp.Key + " " + kvp.Value + '\n');
                    }
                    Console.ReadKey();
                }
                i = (++i) % 2;
            }


            //cki = Console.ReadKey();
            //Console.WriteLine(cki.Key.ToString());
            //if (cki.Key.ToString() == "LeftArrow")
            //{
            //	Console.WriteLine("dupa");
            //}

            Console.ReadKey();
        }
예제 #2
0
파일: Program.cs 프로젝트: oskarc35zut/WDSI
        static void Main(string[] args)
        {
            #region init



            Console.SetWindowPosition(0, 0);
            Console.Write(" Connect4");

            int who    = 2;
            int width  = 7;
            int heigth = 4;
            int deep   = 3;

            Console.Write("\nWysokosc planszy: ");
            heigth = Convert.ToInt32(Console.ReadLine());

            Console.Write("\nSzerokosc planszy: ");
            width = Convert.ToInt32(Console.ReadLine());

            Console.Write("\nJak gleboko szukac: ");
            deep = Convert.ToInt32(Console.ReadLine());
            Connect4State.Init(width, heigth, deep);

            DialogResult dialogResult_sudoku = MessageBox.Show("Komputer zaczyna? ( ͡° ͜ʖ ͡°)", "", MessageBoxButtons.YesNo);
            if (dialogResult_sudoku == DialogResult.Yes)
            {
                who++;
            }


            Console.Clear();
            Console.SetWindowPosition(0, 0);
            Console.Write(" Connect4");
            Console.CursorVisible = false;

            int[,] table = new int[Connect4State.Heigth, Connect4State.Width];



            //table 0 builder
            for (int i = 0; i < Connect4State.Heigth; i++)
            {
                for (int j = 0; j < Connect4State.Width; j++)
                {
                    table[i, j] = 0;
                }
            }
            #endregion //Init

            #region Gra


            while (true)
            {
                switch (who % 2)
                {
                case 0:
                    table = Connect4State.Move(table, Connect4State.GetChoise(table, who % 2 == 0 ? 1 : 2),
                                               who % 2 == 0 ? 1 : 2);

                    break;

                case 1:
                    Thread.Sleep(200);
                    table = Connect4State.ComputerChoiceTable(table, who % 2 == 0 ? 1 : 2);
                    //Thread.Sleep(300);
                    break;


                default:
                    break;
                }

                if (Connect4State.isWin(who % 2 == 0 ? 1 : 2, table) || Connect4State.isFull(table))
                {
                    break;
                }

                who++;
            }

            #endregion //Gra

            #region Wynik rozgrywki

            Connect4State.Print(table);
            if (!Connect4State.isFull(table))
            {
                if (who % 2 == 0)
                {
                    Console.WriteLine("\n\n\n\n\n\nGratulacje, wygrales!!!");
                }
                else
                {
                    Console.WriteLine("\n\n\n\n\n\nPrzegrana...");
                }
            }
            else
            {
                Console.WriteLine("\n\n\n\n\n\nRemis!");
            }
            Thread.Sleep(5000);
            #endregion //Wynik rozgrywki
        }