Exemplo n.º 1
0
        public Form1(Settings settings)
        {
            InitializeComponent();
            typeof(Panel).InvokeMember("DoubleBuffered",                 // REFLECTION
                                       BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                       null, panel1, new object[] { true });
            this.settings = settings;
            for (int i = 0; i < Grid.Length; i++)
            {
                if (Grid[i] != 'X')
                {
                    if ((int)char.GetNumericValue(Grid[i]) < 3)
                    {
                        board[i % 8, i / 8] = new Figure((int)char.GetNumericValue(Grid[i]));
                    }

                    else
                    {
                        board[i % 8, i / 8] = new Damka((int)char.GetNumericValue(Grid[i]) - 2);
                    }
                }
            }
            FindAllAvailableMoves();
        }
Exemplo n.º 2
0
        public override void findKillMoves(Figure[,] board, Point selfPosition)
        {
            killMoves.Clear();



            if (Rules.LongMoves)
            {
                bool         canContinue;
                Damka        imaginaryDamka = new Damka(player);
                List <Point> killMovesTemp  = new List <Point>();
                Figure[,] boardTemp;
                int x = 1;
                int y = 1;
                boardTemp = (Figure[, ])board.Clone();
                killMovesTemp.Clear();
                canContinue = false;
                while (selfPosition.X + x < 8 && selfPosition.Y + y < 8 && board[selfPosition.X + x, selfPosition.Y + y] == null)   // bottom right
                {
                    x++;
                    y++;
                }
                if (selfPosition.X + x < 7 &&
                    selfPosition.Y + y < 7 &&
                    board[selfPosition.X + x, selfPosition.Y + y] != null &&
                    board[selfPosition.X + x, selfPosition.Y + y].player != player &&
                    board[selfPosition.X + x + 1, selfPosition.Y + y + 1] == null)     //killable enemy figure detected
                {
                    //the figure must land on a continuing spot if such exist
                    boardTemp[selfPosition.X + x, selfPosition.Y + y] = null;

                    x++;
                    y++;
                    while (selfPosition.X + x < 8 && selfPosition.Y + y < 8 && board[selfPosition.X + x, selfPosition.Y + y] == null)
                    {
                        imaginaryDamka.findKillMoves(boardTemp, new Point(selfPosition.X + x, selfPosition.Y + y));
                        if (imaginaryDamka.killMoves.Count > 0 && canContinue == false)
                        {
                            killMovesTemp.Clear();
                            canContinue = true;
                        }
                        if (!canContinue || (canContinue && imaginaryDamka.killMoves.Count > 0))
                        {
                            killMovesTemp.Add(new Point(selfPosition.X + x, selfPosition.Y + y));
                        }
                        x++;
                        y++;
                    }
                    killMoves.AddRange(killMovesTemp);
                }


                x         = 1;
                y         = 1;
                boardTemp = (Figure[, ])board.Clone();
                killMovesTemp.Clear();
                canContinue = false;
                while (selfPosition.X - x >= 0 && selfPosition.Y + y < 8 && board[selfPosition.X - x, selfPosition.Y + y] == null)   // bottom left
                {
                    x++;
                    y++;
                }
                if (selfPosition.X - x >= 1 &&
                    selfPosition.Y + y < 7 &&
                    board[selfPosition.X - x, selfPosition.Y + y] != null &&
                    board[selfPosition.X - x, selfPosition.Y + y].player != player &&
                    board[selfPosition.X - x - 1, selfPosition.Y + y + 1] == null)     //killable enemy figure detected
                {
                    //the figure must land on a continuing spot if such exist
                    boardTemp[selfPosition.X - x, selfPosition.Y + y] = null;
                    x++;
                    y++;
                    while (selfPosition.X - x >= 0 && selfPosition.Y + y < 8 && board[selfPosition.X - x, selfPosition.Y + y] == null)
                    {
                        imaginaryDamka.findKillMoves(boardTemp, new Point(selfPosition.X - x, selfPosition.Y + y));
                        if (imaginaryDamka.killMoves.Count > 0 && canContinue == false)
                        {
                            killMovesTemp.Clear();
                            canContinue = true;
                        }
                        if (!canContinue || (canContinue && imaginaryDamka.killMoves.Count > 0))
                        {
                            killMovesTemp.Add(new Point(selfPosition.X - x, selfPosition.Y + y));
                        }
                        x++;
                        y++;
                    }

                    killMoves.AddRange(killMovesTemp);
                }


                x         = 1;
                y         = 1;
                boardTemp = (Figure[, ])board.Clone();
                killMovesTemp.Clear();
                canContinue = false;
                while (selfPosition.X + x < 8 && selfPosition.Y - y >= 0 && board[selfPosition.X + x, selfPosition.Y - y] == null)   // top right
                {
                    x++;
                    y++;
                }
                if (selfPosition.X + x < 7 &&
                    selfPosition.Y - y >= 1 &&
                    board[selfPosition.X + x, selfPosition.Y - y] != null &&
                    board[selfPosition.X + x, selfPosition.Y - y].player != player &&
                    board[selfPosition.X + x + 1, selfPosition.Y - y - 1] == null)     //killable enemy figure detected
                {
                    //the figure must land on a continuing spot if such exist
                    boardTemp[selfPosition.X + x, selfPosition.Y - y] = null;
                    x++;
                    y++;
                    while (selfPosition.X + x < 8 && selfPosition.Y - y >= 0 && board[selfPosition.X + x, selfPosition.Y - y] == null)
                    {
                        imaginaryDamka.findKillMoves(boardTemp, new Point(selfPosition.X + x, selfPosition.Y - y));
                        if (imaginaryDamka.killMoves.Count > 0 && canContinue == false)
                        {
                            killMovesTemp.Clear();
                            canContinue = true;
                        }
                        if (!canContinue || (canContinue && imaginaryDamka.killMoves.Count > 0))
                        {
                            killMovesTemp.Add(new Point(selfPosition.X + x, selfPosition.Y - y));
                        }
                        x++;
                        y++;
                    }
                    killMoves.AddRange(killMovesTemp);
                }


                x         = 1;
                y         = 1;
                boardTemp = (Figure[, ])board.Clone();
                killMovesTemp.Clear();
                canContinue = false;
                while (selfPosition.X - x >= 0 && selfPosition.Y - y >= 0 && board[selfPosition.X - x, selfPosition.Y - y] == null)   // top left
                {
                    x++;
                    y++;
                }
                if (selfPosition.X - x >= 1 &&
                    selfPosition.Y - y >= 1 &&
                    board[selfPosition.X - x, selfPosition.Y - y] != null &&
                    board[selfPosition.X - x, selfPosition.Y - y].player != player &&
                    board[selfPosition.X - x - 1, selfPosition.Y - y - 1] == null)     //killable enemy figure detected
                {
                    //the figure must land on a continuing spot if such exist
                    boardTemp[selfPosition.X - x, selfPosition.Y - y] = null;
                    x++;
                    y++;
                    while (selfPosition.X - x >= 0 && selfPosition.Y - y >= 0 && board[selfPosition.X - x, selfPosition.Y - y] == null)
                    {
                        imaginaryDamka.findKillMoves(boardTemp, new Point(selfPosition.X - x, selfPosition.Y - y));
                        if (imaginaryDamka.killMoves.Count > 0 && canContinue == false)
                        {
                            killMovesTemp.Clear();
                            canContinue = true;
                        }
                        if (!canContinue || (canContinue && imaginaryDamka.killMoves.Count > 0))
                        {
                            killMovesTemp.Add(new Point(selfPosition.X - x, selfPosition.Y - y));
                        }
                        x++;
                        y++;
                    }
                    killMoves.AddRange(killMovesTemp);
                }
            }



            else
            {
                if (selfPosition.X + 2 < 8 && selfPosition.Y - 2 >= 0)
                {
                    if (board[selfPosition.X + 1, selfPosition.Y - 1] != null && board[selfPosition.X + 1, selfPosition.Y - 1].player != player && board[selfPosition.X + 2, selfPosition.Y - 2] == null)
                    {
                        killMoves.Add(new Point(selfPosition.X + 2, selfPosition.Y - 2));
                    }
                }

                if (selfPosition.X - 2 >= 0 && selfPosition.Y - 2 >= 0)
                {
                    if (board[selfPosition.X - 1, selfPosition.Y - 1] != null && board[selfPosition.X - 1, selfPosition.Y - 1].player != player && board[selfPosition.X - 2, selfPosition.Y - 2] == null)
                    {
                        killMoves.Add(new Point(selfPosition.X - 2, selfPosition.Y - 2));
                    }
                }


                if (selfPosition.X + 2 < 8 && selfPosition.Y + 2 < 8)
                {
                    if (board[selfPosition.X + 1, selfPosition.Y + 1] != null && board[selfPosition.X + 1, selfPosition.Y + 1].player != player && board[selfPosition.X + 2, selfPosition.Y + 2] == null)
                    {
                        killMoves.Add(new Point(selfPosition.X + 2, selfPosition.Y + 2));
                    }
                }

                if (selfPosition.X - 2 >= 0 && selfPosition.Y + 2 < 8)
                {
                    if (board[selfPosition.X - 1, selfPosition.Y + 1] != null && board[selfPosition.X - 1, selfPosition.Y + 1].player != player && board[selfPosition.X - 2, selfPosition.Y + 2] == null)
                    {
                        killMoves.Add(new Point(selfPosition.X - 2, selfPosition.Y + 2));
                    }
                }
            }
        }