Beispiel #1
0
        /// <summary>
        /// If checker can beat others checkers.
        /// </summary>
        private bool FindBeatCheckersForSpecificChecker(int checkerId)
        {
            ClearAvailableSquares();

            Checker checker = _checkersData[checkerId];

            if (checker.Color == CurrentMoveColor)
            {
                if (checker.IsSuperChecker)
                {
                    return(FindAvailableSquareForSuperMultiBeat(checker));
                }
                else
                {
                    foreach (var neighbourSquarePosition in checker.Square.Neighbours(true, _currentMoveCollor, Client.instance.lobbyInfo.GameMode))
                    {
                        if (IsOnBoard(neighbourSquarePosition))
                        {
                            Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                            if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                            {
                                Square secondNextSquare = GetSecondNextSquare(checker.Square, neighbourSquare);
                                if (secondNextSquare != null && !secondNextSquare.HasChecker())
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Find checkers for beat.
        /// </summary>
        private List <Checker> FindBeatCheckers()
        {
            List <Checker> beatCheckers = new List <Checker>();

            foreach (var checker in _checkersData.Values)
            {
                if (_currentChecker == null || checker == _currentChecker)
                {
                    if (checker.Color == CurrentMoveColor)
                    {
                        if (checker.IsSuperChecker)
                        {
                            var listBeatSuper = FindBeatCheckersForSuper(checker);

                            if (listBeatSuper.Count > 0)
                            {
                                beatCheckers.AddRange(listBeatSuper);
                            }
                        }
                        else
                        {
                            foreach (var neighbourSquarePosition in checker.Square.Neighbours(true, _currentMoveCollor, Client.instance.lobbyInfo.GameMode))
                            {
                                if (IsOnBoard(neighbourSquarePosition))
                                {
                                    Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                                    if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                                    {
                                        Square secondNextSquare = GetSecondNextSquare(checker.Square, neighbourSquare);
                                        if (secondNextSquare != null && !secondNextSquare.HasChecker())
                                        {
                                            beatCheckers.Add(checker);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(beatCheckers);
        }
Beispiel #3
0
        /// <summary>
        /// Update lists with checkers by color.
        /// </summary>
        public void FindAvailableSquaresForColor()
        {
            if (GameEnd)
            {
                return;
            }

            //AvailableSquaresForBlack.Clear();
            AvailableSquares.Clear();
            //_currentChecker = null;

            foreach (var item in _checkersData.Values)
            {
                foreach (var neighbourSquarePosition in item.Square.Neighbours(false, _currentMoveCollor, Client.instance.lobbyInfo.GameMode))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (!neighbourSquare.HasChecker())
                        {
                            AvailableSquares.Add(neighbourSquare);
                        }
                    }
                }
            }

            if (AvailableSquares.Count == 0)
            {
                int checkersForBeat = FindBeatCheckers().Count;
                if (checkersForBeat == 0)
                {
                    //UiViewController.Instance.ShowPlayerNoMovesMessage();
                    //AudioController.Instance.PlayOneShotAudio(AudioController.AudioType.Lose);
                    //AdsController.Instance.ShowRewardBasedVideo();
                    GameEnd = true;
                }
            }
        }
Beispiel #4
0
        public List <Checker> FindBeatCheckersForSuper(Checker checker)
        {
            List <Checker> beatCheckers = new List <Checker>();

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperRightTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    beatCheckers.Add(checker);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperLeftTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    beatCheckers.Add(checker);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperRightBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    beatCheckers.Add(checker);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperLeftBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    beatCheckers.Add(checker);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            i = 8;
                            break;
                        }
                    }
                }
            }
            return(beatCheckers);
        }
Beispiel #5
0
        public bool FindAvailableSquareForSuperMultiBeat(Checker checker)
        {
            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperRightTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    return(true);
                                }
                                else
                                {
                                    break;
                                }
                            }


                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperLeftTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    return(true);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }


                        i = 8;
                        break;
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperRightBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    return(true);
                                }
                                else
                                {
                                    break;
                                }
                            }


                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in checker.Square.NeighboursSuperLeftBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(checker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    return(true);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            i = 8;
                            break;
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #6
0
        public void FindAvailableSquaresForSuperBeat(Checker choosenChecker)
        {
            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperRightTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(choosenChecker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    _allAvailableSquares.Add(item);
                                }
                                else
                                {
                                    i = 8;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperLeftTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(choosenChecker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    _allAvailableSquares.Add(item);
                                }
                                else
                                {
                                    i = 8;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperRightBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(choosenChecker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    _allAvailableSquares.Add(item);
                                }
                                else
                                {
                                    i = 8;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperLeftBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                        if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                        {
                            var NextSquares = NextSquaresList(choosenChecker.Square, neighbourSquare);

                            foreach (var item in NextSquares)
                            {
                                if (item != null && !item.HasChecker())
                                {
                                    _allAvailableSquares.Add(item);
                                }
                                else
                                {
                                    i = 8;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public void FindAvailableSquaresForSuperTurn(Checker choosenChecker)
        {
            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperRightTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];

                        if (!neighbourSquare.HasChecker())
                        {
                            _allAvailableSquares.Add(neighbourSquare);
                        }
                        else
                        {
                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperLeftTop(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];

                        if (!neighbourSquare.HasChecker())
                        {
                            _allAvailableSquares.Add(neighbourSquare);
                        }
                        else
                        {
                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperRightBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];

                        if (!neighbourSquare.HasChecker())
                        {
                            _allAvailableSquares.Add(neighbourSquare);
                        }
                        else
                        {
                            i = 8;
                            break;
                        }
                    }
                }
            }

            for (int i = 1; i < 8; i++)
            {
                foreach (var neighbourSquarePosition in choosenChecker.Square.NeighboursSuperLeftBottom(i))
                {
                    if (IsOnBoard(neighbourSquarePosition))
                    {
                        Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];

                        if (!neighbourSquare.HasChecker())
                        {
                            _allAvailableSquares.Add(neighbourSquare);
                        }
                        else
                        {
                            i = 8;
                            break;
                        }
                    }
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// When checker is chosen we need to find empty squares to move on.
        /// </summary>
        public void FindAvailableSquares(int checkerId)
        {
            if (GameEnd)
            {
                return;
            }

            //If user do not beat checkers yet
            if (!IsBeatProcessActive || IsEnemyMove && BoardController.Instance.GameControllerComponent.Mode == GameMode.Mining)
            {
                _currentChecker = null;
                ClearAvailableSquares();
            }

            Checker        choosenChecker = _checkersData[checkerId];
            List <Checker> beatCheckers   = FindBeatCheckers();


            if (choosenChecker.Color == CurrentMoveColor && beatCheckers.Count == 0)
            {
                if (choosenChecker.IsSuperChecker)
                {
                    FindAvailableSquaresForSuperTurn(choosenChecker);
                }
                else
                {
                    foreach (var neighbourSquarePosition in choosenChecker.Square.Neighbours(false, _currentMoveCollor, Client.instance.lobbyInfo.GameMode))
                    {
                        if (IsOnBoard(neighbourSquarePosition))
                        {
                            Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];

                            if (!neighbourSquare.HasChecker())
                            {
                                _allAvailableSquares.Add(neighbourSquare);
                            }
                        }
                    }
                }
            }
            else if (choosenChecker.Color == CurrentMoveColor && beatCheckers.Count != 0 && beatCheckers.Contains(choosenChecker))
            {
                if (choosenChecker.IsSuperChecker)
                {
                    FindAvailableSquaresForSuperBeat(choosenChecker);
                }
                else
                {
                    foreach (var neighbourSquarePosition in choosenChecker.Square.Neighbours(true, _currentMoveCollor, Client.instance.lobbyInfo.GameMode))
                    {
                        if (IsOnBoard(neighbourSquarePosition))
                        {
                            Square neighbourSquare = _boardSquares[neighbourSquarePosition.X, neighbourSquarePosition.Y];
                            if (neighbourSquare.HasChecker() && neighbourSquare.Checker.Color != CurrentMoveColor)
                            {
                                Square secondNextSquare = GetSecondNextSquare(choosenChecker.Square, neighbourSquare);
                                if (secondNextSquare != null && !secondNextSquare.HasChecker())
                                {
                                    _allAvailableSquares.Add(secondNextSquare);
                                }
                            }
                        }
                    }
                }
            }

            if ((BoardController.Instance.GameControllerComponent.Mode == GameMode.Mining &&
                 choosenChecker.Color == CheckerColor.White) || BoardController.Instance.GameControllerComponent.Mode == GameMode.PVP)
            {
                if (_allAvailableSquares.Count == 0)
                {
                    BoardController.Instance.ShakeChecker(choosenChecker);
                }
                else
                {
                    if (!IsBeatProcessActive)
                    {
                        _currentChecker = choosenChecker;
                    }

                    BoardController.Instance.MarkSquares(_allAvailableSquares);
                }
            }
        }