Ejemplo n.º 1
0
        IPlayer white = new MinMaxCheckers(10); //new NeuralNetwork("jeden");

        #endregion Fields

        #region Constructors

        public MainForm()
        {
            InitializeComponent();

            konfig = new Konfiguracja();
            plansza = new Plansza();

            ruchy = new Ruchy();
            bicia = new Bicia();
            gracz = new Gracz(2);
            gracz.Prepare(plansza, this);
             //   gracz.IsComputer1 = true;
             //   gracz.IsComputer2 = false;
            nowaToolStripMenuItem_Click(null, null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Obsługuje klikniecie na planszy
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="p">Plansza</param>
        /// <param name="b">Bicia</param>
        /// <param name="gracz">Obecny gracz</param>
        /// <returns></returns>
        public void klikniecie(int x, int y, Plansza p, Bicia b, Gracz gracz, bool computer=false)
        {
            b.sprawdz_bicia(gracz, p);

            if (this.pole[x, y] == 0)//pierwszy klik
            {
                this.zerowanie();
                if (p.pole[x, y] > 1) //jezeli w polu znajduje sie pionek
                {
                    this.pole[x, y] = 1; // zaznaczam w ruchach miejsce

                    //jezeli jest to pionek gracza 1 i jest jego ruch
                    if (p.pole[x, y] == 2 && gracz.get_gracz() == 1)
                    {//dodajemy  do planszy ruchów 2 jak ruch bez bicia, 3 jak ruch z biciem
                        if (x > 0 && y > 0 && p.pole[x - 1, y - 1] == 1 && !b.przymus)
                        {
                            this.pole[x - 1, y - 1] = 2;
                            Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x - 1, y - 1));
                            p.possibleMoves.Add(m);
                        }

                        if (x < 7 && y > 0 && p.pole[x + 1, y - 1] == 1 && !b.przymus)
                        {
                            this.pole[x + 1, y - 1] = 2;
                            Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x + 1, y - 1));
                            p.possibleMoves.Add(m);
                        }

                        if (x > 1 && y > 1 && (p.pole[x - 1, y - 1] == 3
                            || p.pole[x - 1, y - 1] == 5) && p.pole[x - 2, y - 2] == 1)
                        {
                            this.pole[x - 2, y - 2] = 3;
                            Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x - 2, y - 2));
                            p.possibleBeats.Add(m);
                        }

                        if (x < 6 && y > 1 && (p.pole[x + 1, y - 1] == 3
                            || p.pole[x + 1, y - 1] == 5) && p.pole[x + 2, y - 2] == 1)
                        {
                            this.pole[x + 2, y - 2] = 3;
                            Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x + 2, y - 2));
                            p.possibleBeats.Add(m);
                        }

                        if (x > 1 && y < 6 && (p.pole[x - 1, y + 1] == 3
                            || p.pole[x - 1, y + 1] == 5) && p.pole[x - 2, y + 2] == 1)
                        {
                            this.pole[x - 2, y + 2] = 3;
                            Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x - 2, y + 2));
                            p.possibleBeats.Add(m);
                        }

                        if (x < 6 && y < 6 && (p.pole[x + 1, y + 1] == 3
                            || p.pole[x + 1, y + 1] == 5) && p.pole[x + 2, y + 2] == 1)
                        {
                            this.pole[x + 2, y + 2] = 3;
                             Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x + 2, y +2));
                            p.possibleBeats.Add(m);

                        }

                    }
                    //jezeli jest to pionek racza 2
                    else if (p.pole[x, y] == 3 && gracz.get_gracz() == 2)
                    {
                        if (x > 0 && y < 7 && p.pole[x - 1, y + 1] == 1 && !b.przymus)
                        {
                            this.pole[x - 1, y + 1] = 2;
                            Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x - 1, y + 1));
                            p.possibleMoves.Add(m);
                        }

                        if (x < 7 && y < 7 && p.pole[x + 1, y + 1] == 1 && !b.przymus)
                        {
                            this.pole[x + 1, y + 1] = 2;
                            Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x + 1, y + 1));
                            p.possibleMoves.Add(m);
                        }
                        if (x > 1 && y < 6 && (p.pole[x - 1, y + 1] == 2
                            || p.pole[x - 1, y + 1] == 4) && p.pole[x - 2, y + 2] == 1)
                        {
                            this.pole[x - 2, y + 2] = 3;
                             Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x - 2, y + 2));
                            p.possibleBeats.Add(m);
                        }

                        if (x < 6 && y < 6 && (p.pole[x + 1, y + 1] == 2
                            || p.pole[x + 1, y + 1] == 4) && p.pole[x + 2, y + 2] == 1)
                        {
                            this.pole[x + 2, y + 2] = 3;
                             Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x + 2, y + 2));
                            p.possibleBeats.Add(m);
                        }

                        if (x > 1 && y > 1 && (p.pole[x - 1, y - 1] == 2
                            || p.pole[x - 1, y - 1] == 4) && p.pole[x - 2, y - 2] == 1)
                        {
                            this.pole[x - 2, y - 2] = 3;
                             Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x - 2, y - 2));
                            p.possibleBeats.Add(m);
                        }

                        if (x < 6 && y > 1 && (p.pole[x + 1, y - 1] == 2
                            || p.pole[x + 1, y - 1] == 4) && p.pole[x + 2, y - 2] == 1)
                        {
                            this.pole[x + 2, y - 2] = 3;
                             Move m = new Move(new Point(x, y));
                            m.moves.Add(new Point(x + 2, y - 2));
                            p.possibleBeats.Add(m);
                        }
                    }
                    //jezeli jest to damka gracza 1 lub gracza 2 i to jest jego ruch
                    else if ((p.pole[x, y] == 4 && gracz.get_gracz() == 1) || (p.pole[x, y] == 5 && gracz.get_gracz() == 2))
                    {
                        int i = 0; int j = 0;
                        int add = (gracz.get_gracz() == 1) ? 1 : 0;

                        while (!b.przymus && x + i > 0 && y + j > 0)//markuje na 2 te pola na których może stanąć
                        {
                            if (p.pole[x + i - 1, y + j - 1] == 1)//puste pole na planszy
                            {
                                this.pole[x + i - 1, y + j - 1] = 2;
                                Move m = new Move(new Point(x, y));
                                m.moves.Add(new Point(x + i - 1, y + j - 1));
                                p.possibleMoves.Add(m);

                                --i;
                                --j;
                            }
                            else break;
                        }

                        i = 0; j = 0;

                        while (!b.przymus && x + i < 7 && y + j > 0)
                        {
                            if (p.pole[x + i + 1, y + j - 1] == 1)
                            {
                                this.pole[x + i + 1, y + j - 1] = 2;
                                Move m = new Move(new Point(x, y));
                                m.moves.Add(new Point(x + i + 1, y + j - 1));
                                p.possibleMoves.Add(m);
                                ++i;
                                --j;
                            }
                            else break;
                        }

                        i = 0; j = 0;

                        while (!b.przymus && x + i > 0 && y + j < 7)
                        {
                            if (p.pole[x + i - 1, y + j + 1] == 1)
                            {
                                this.pole[x + i - 1, y + j + 1] = 2;
                                Move m = new Move(new Point(x, y));
                                m.moves.Add(new Point(x + i - 1, y + j + 1));
                                p.possibleMoves.Add(m);
                                --i;
                                ++j;
                            }
                            else break;
                        }

                        i = 0; j = 0;

                        while (!b.przymus && x + i < 7 && y + j < 7)
                        {
                            if (p.pole[x + i + 1, y + j + 1] == 1)
                            {
                                this.pole[x + i + 1, y + j + 1] = 2;
                                Move m = new Move(new Point(x, y));
                                m.moves.Add(new Point(x + i + 1, y + j + 1));
                                p.possibleMoves.Add(m);
                                ++i;
                                ++j;
                            }
                            else break;
                        }

                        bool bij = false; i = 0; j = 0;

                        while (x + i > 0 && y + j > 0)//jak jest bicie markuje na 3 pola na których może stanąć po biciu
                        {
                            if (p.pole[x + i - 1, y + j - 1] == 1)
                            {
                                if (bij)
                                {
                                    this.pole[x + i - 1, y + j - 1] = 3;
                                    Move m = new Move(new Point(x, y));
                                    m.moves.Add(new Point(x + i - 1, y + j - 1));
                                    p.possibleBeats.Add(m);
                                }
                                --i;
                                --j;
                            }
                            else if (p.pole[x + i - 1, y + j - 1] == 2 + add || p.pole[x + i - 1, y + j - 1] == 4 + add)
                            {
                                if (!bij)
                                {
                                    bij = true;
                                    --i;
                                    --j;
                                }
                                else break;
                            }
                            else break;
                        }

                        bij = false; i = 0; j = 0;

                        while (x + i < 7 && y + j > 0)
                        {
                            if (p.pole[x + i + 1, y + j - 1] == 1)
                            {
                                if (bij)
                                {
                                    this.pole[x + i + 1, y + j - 1] = 3;
                                    Move m = new Move(new Point(x, y));
                                    m.moves.Add(new Point(x + i + 1, y + j - 1));
                                    p.possibleBeats.Add(m);
                                }
                                ++i;
                                --j;
                            }
                            else if (p.pole[x + i + 1, y + j - 1] == 2 + add || p.pole[x + i + 1, y + j - 1] == 4 + add)
                            {
                                if (!bij)
                                {
                                    bij = true;
                                    ++i;
                                    --j;
                                }
                                else break;
                            }
                            else break;
                        }

                        bij = false; i = 0; j = 0;

                        while (x + i > 0 && y + j < 7)
                        {
                            if (p.pole[x + i - 1, y + j + 1] == 1)
                            {
                                if (bij)
                                {
                                    this.pole[x + i - 1, y + j + 1] = 3;
                                    Move m = new Move(new Point(x, y));
                                    m.moves.Add(new Point(x + i - 1, y + j + 1));
                                    p.possibleBeats.Add(m);
                                }
                                --i;
                                ++j;
                            }
                            else if (p.pole[x + i - 1, y + j + 1] == 2 + add || p.pole[x + i - 1, y + j + 1] == 4 + add)
                            {
                                if (!bij)
                                {
                                    bij = true;
                                    --i;
                                    ++j;
                                }
                                else break;
                            }
                            else break;
                        }

                        bij = false; i = 0; j = 0;

                        while (x + i < 7 && y + j < 7)
                        {
                            if (p.pole[x + i + 1, y + j + 1] == 1)
                            {
                                if (bij)
                                {
                                    this.pole[x + i + 1, y + j + 1] = 3;
                                    Move m = new Move(new Point(x, y));
                                    m.moves.Add(new Point(x + i + 1, y + j + 1));
                                    p.possibleBeats.Add(m);
                                }
                                ++i;
                                ++j;
                            }
                            else if (p.pole[x + i + 1, y + j + 1] == 2 + add || p.pole[x + i + 1, y + j + 1] == 4 + add)
                            {
                                if (!bij)
                                {
                                    bij = true;
                                    ++i;
                                    ++j;
                                }
                                else break;
                            }
                            else break;
                        }
                    }

              //      this.wyswietlanie();
                }

                old_x = x;
                old_y = y;
            }/*
            else if (this.pole[x,y] == 1)
            {
                this.zerowanie();
            }*/
            else if (this.pole[x, y] == 2)//wykonanie ruchu, bo na pole można się ruszyć bez bicia
            {
                p.pole[x, y] = p.pole[old_x, old_y];
                p.pole[old_x, old_y] = 1;
                this.zerowanie();
                p.zamien_pionki_na_damki(gracz);
            //        gracz.zmiana_gracza(computer);
            }
            else if (this.pole[x, y] == 3)//wykonanie bicia
            {
                p.pole[x, y] = p.pole[old_x, old_y];
                int i = old_x;
                int j = old_y;
                int add_i = (old_x < x) ? 1 : -1;
                int add_j = (old_y < y) ? 1 : -1;
                int kill_x = i + add_i;
                int kill_y = j + add_j;
                while (kill_x != x && kill_y != y)
                {
                    p.pole[kill_x, kill_y] = 1;
                    kill_x += add_i;
                    kill_y += add_j;
                    //			System.out.println("kiler : " + kill_x + " " + kill_y);
                }
                p.pole[old_x, old_y] = 1;

                this.zerowanie();
                b.sprawdz_bicia(gracz, p, x, y);//zmiana gracza po biciu
                if (!b.przymus)
                {
                    p.zamien_pionki_na_damki(gracz);
            //        gracz.zmiana_gracza(computer);
                }
                else//kolejny ruch
                {
                    klikniecie(x, y, p, b, gracz,computer);
                }
            }

            b.sprawdz_bicia(gracz, p);
        }