Exemple #1
0
        private static async Task <bool> _EnableNorthWest(IEnumerable <Button> board, Player player, int index)
        {
            var enemyColor = player.PlayerSide == Color.Black ? Color.White : Color.Black;

            var northWestPanels = DirectionUtility.GetNorthWestPanels(board, index, enemyColor).Result;
            int count           = northWestPanels.Count();

            if (count == 0)
            {
                return(false);
            }

            var lastPanelIndex = int.Parse(northWestPanels.Last().Name) - 8;

            if (lastPanelIndex < 0)
            {
                return(false);
            }

            var modWest = (lastPanelIndex % 8) - 1;

            if (modWest < 0)
            {
                return(false);
            }
            else
            {
                lastPanelIndex -= 1;
            }

            var lastPanel = board.ElementAt(lastPanelIndex);

            if (lastPanel.BackColor != Color.Lime)
            {
                return(false);
            }

            if (!(player is GreedyAI))
            {
                lastPanel.Enabled = true;
            }
            lastPanel.ForeColor = player.PlayerSide;
            if (string.IsNullOrEmpty(lastPanel.Text))
            {
                lastPanel.Text = count.ToString();
            }
            else
            {
                count          = count + int.Parse(lastPanel.Text);
                lastPanel.Text = count.ToString();
            }
            return(true);
        }
Exemple #2
0
        public static async Task TryFlipEnemyDisks(IEnumerable <Button> board, Player player, Player enemy, int index)
        {
            var  enemyColor = enemy.PlayerSide;
            bool isValid;

            //north
            var northPanels = await DirectionUtility.GetNorthPanels(board, index, enemyColor);

            if (northPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(northPanels.Last().Name) - 8).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in northPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            //east
            var eastPanels = await DirectionUtility.GetEastPanels(board, index, enemyColor);

            if (eastPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(eastPanels.Last().Name) + 1).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in eastPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            //south
            var southPanels = await DirectionUtility.GetSouthPanels(board, index, enemyColor);

            if (southPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(southPanels.Last().Name) + 8).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in southPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            //west
            var westPanels = await DirectionUtility.GetWestPanels(board, index, enemyColor);

            if (westPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(westPanels.Last().Name) - 1).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in westPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            //north east
            var northEasPanels = await DirectionUtility.GetNorthEastPanels(board, index, enemyColor);

            if (northEasPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(northEasPanels.Last().Name) + 1 - 8).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in northEasPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            //south east
            var southEastPanels = await DirectionUtility.GetSouthEastPanels(board, index, enemyColor);

            if (southEastPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(southEastPanels.Last().Name) + 1 + 8).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in southEastPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            //south west
            var southWestPanels = await DirectionUtility.GetSouthWestPanels(board, index, enemyColor);

            if (southWestPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(southWestPanels.Last().Name) - 1 + 8).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in southWestPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            //north west
            var northWestPanels = await DirectionUtility.GetNorthWestPanels(board, index, enemyColor);

            if (northWestPanels.Count() == 0)
            {
                isValid = false;
            }
            else
            {
                isValid = board.ElementAt(int.Parse(northWestPanels.Last().Name) - 1 - 8).BackColor == player.PlayerSide;
            }
            if (isValid)
            {
                foreach (var panel in northWestPanels)
                {
                    player.AcquirePanel(panel, enemy);
                }
            }

            return;
        }