Exemple #1
0
            internal static void FindKills(Board board, bool isWhite, int x, int y, ref KillItem kills)
            {
                for (int i = 0; i < 4; i++)
                {
                    int xN  = x + _moveDirections[i, 0];
                    int yN  = y + _moveDirections[i, 1];
                    int xN2 = x + 2 * _moveDirections[i, 0];
                    int yN2 = y + 2 * _moveDirections[i, 1];

                    if (!InBounds(xN) || !InBounds(yN) || !InBounds(xN2) || !InBounds(yN2))
                    {
                        continue;
                    }

                    if (board[xN2, yN2] != FigureEnum.NONE)
                    {
                        continue;
                    }

                    if (CheckersHasDifferentColor(board, x, y, xN, yN))
                    {
                        var beated = new Point(xN, yN);

                        if (kills.BranchContaintsValue(beated))
                        {
                            continue;
                        }

                        if (kills.Move == null)
                        {
                            kills.Move = new Point(x, y);
                        }

                        var beat = new KillItem
                        {
                            Move   = new Point(xN2, yN2),
                            Killed = beated
                        };

                        kills.AddChild(ref beat);

                        var boardCopy = (Board)board.Clone();

                        boardCopy[xN2, yN2] = boardCopy[x, y];
                        boardCopy[x, y]     = FigureEnum.NONE;

                        FindKills(boardCopy, isWhite, xN2, yN2, ref beat);
                    }
                }
            }
Exemple #2
0
            private static void FindKills(Board board, bool isWhite, int x, int y, ref KillItem kills)
            {
                int[,] _whiteDirections = new int[, ]  {
                    { -1, -1 }, { 1, -1 }
                };
                int[,] _blackDirections = new int[, ] {
                    { 1, 1 }, { -1, 1 }
                };

                var dir = isWhite ? _whiteDirections : _blackDirections;

                for (int i = 0; i < 2; i++)
                {
                    int xN  = x + dir[i, 0];
                    int yN  = y + dir[i, 1];
                    int xN2 = x + 2 * dir[i, 0];
                    int yN2 = y + 2 * dir[i, 1];

                    if (!InBounds(xN) || !InBounds(yN) || !InBounds(xN2) || !InBounds(yN2))
                    {
                        continue;
                    }

                    if (board[xN2, yN2] != FigureEnum.NONE)
                    {
                        continue;
                    }

                    if (CheckersHasDifferentColor(board, x, y, xN, yN) && !board.IsSenior(xN, yN))
                    {
                        var killed = new Point(xN, yN);

                        if (kills.BranchContaintsValue(killed))
                        {
                            continue;
                        }

                        if (kills.Move == null)
                        {
                            kills.Move = new Point(x, y);
                        }

                        var beat = new KillItem
                        {
                            Move   = new Point(xN2, yN2),
                            Killed = killed
                        };

                        kills.AddChild(ref beat);

                        var boardCopy = (Board)board.Clone();

                        boardCopy[xN2, yN2] = boardCopy[x, y];
                        boardCopy[x, y]     = FigureEnum.NONE;

                        if (ShouldBecomeSenior(yN2, isWhite))
                        {
                            Senior.FindKills(boardCopy, isWhite, xN2, yN2, ref beat);
                        }
                        else
                        {
                            FindKills(boardCopy, isWhite, xN2, yN2, ref beat);
                        }
                    }
                }
            }