/* Trying to eat all the checkers on the way
         * Control over the end result of the course
         */
        private void TryEatEnemyCheckers(BaseChecker previouslySelectedChecker, Point toPosition, Point fromPosition, Point moveDirection)
        {
            List <BaseChecker> eatenCheckers = new List <BaseChecker>(); // A list of all the eaten checkers

            for (int i = fromPosition.X + moveDirection.X; i != toPosition.X; i += moveDirection.X)
            {
                for (int j = fromPosition.Y + moveDirection.Y; j != toPosition.Y; j += moveDirection.Y)
                {
                    // Addition of all the opponent's checkers met in the course of the "eaten"
                    foreach (BaseChecker checker in previouslySelectedChecker.Side == CheckerSide.Black? state.WhiteCheckers: state.BlackCheckers)
                    {
                        if (checker.Position.BoardPosition.X == i &&
                            checker.Position.BoardPosition.Y == j)
                        {
                            eatenCheckers.Add(checker);
                        }
                    }
                }
            }

            // Destruction of all eaten checkers
            foreach (BaseChecker eatenChecker in eatenCheckers)
            {
                state.AllCheckers.Remove(eatenChecker);

                eatenChecker.Destroy();
            }
        }
示例#2
0
    void Awake()
    {
        Instance = this;
        _player  = GameObject.FindWithTag("Player");

        // TODO: liian vaikea luoda
        var go = new GameObject("Base Checker");

        go.transform.parent = _player.transform.parent;
        var checker = go.AddComponent <BaseChecker>();

        checker.CraftRange = CraftRange;
        _baseChecker       = go.GetComponent <BaseChecker>();

        _baseChecker.SetMask("Base"); // voisi olla parameter

        if (_player == null || _baseChecker == null)
        {
            Debug.LogWarning("WARNING: BaseManager.cs basechecker null");
        }

        var infoStoneGameObject = new GameObject("Info Stone Checker");

        infoStoneGameObject.transform.parent = _player.transform.parent;

        // var infoStoneChecker = go.AddComponent<BaseChecker>();
        checker.CraftRange = 5f;
        _InfoStoneChecker  = checker;
    }
示例#3
0
 private async Task <IList <BreachedEntry> > CheckBreaches(
     BaseChecker breachChecker,
     bool expireEntries,
     bool oldEntriesOnly,
     bool ignoreDeleted,
     IProgress <ProgressItem> progressIndicator)
 {
     return(await breachChecker.CheckDatabase(expireEntries, oldEntriesOnly, ignoreDeleted, progressIndicator));
 }
 private async Task <IList <BreachedEntry> > CheckBreaches(
     BaseChecker breachChecker,
     PwGroup group,
     bool expireEntries,
     bool oldEntriesOnly,
     bool ignoreDeleted,
     bool ignoreExpired,
     IProgress <ProgressItem> progressIndicator,
     Func <bool> canContinue)
 {
     return(await breachChecker.CheckGroup(group, expireEntries, oldEntriesOnly, ignoreDeleted, ignoreExpired, progressIndicator, canContinue));
 }
 /* Select a checker (highlighting it)
  */
 private void SelectChecker(BaseChecker selectedChecker)
 {
     foreach (BaseChecker checker in state.AllCheckers)
     {
         if (checker == selectedChecker)
         {
             checker.selected = true;
         }
         else
         {
             checker.selected = false;
         }
     }
 }
        /* Highlighting of all possible moves
         */
        private void HighlightPossibleTurns(BaseChecker currentSelectedChecker)
        {
            PathPoint turns = currentSelectedChecker.GetPossibleTurns();

            if (!turns.IsDeadEnd())
            {
                foreach (TurnDirection direction in DirectionHelper.GetAllDirections())
                {
                    foreach (PathPoint point in turns[direction])
                    {
                        board[point.Position.X, point.Position.Y].Highlighted = true;
                    }
                }
            }
        }
示例#7
0
    private void OnGUI()
    {
        if (this.errorDirty)
        {
            this.errorDirty = false;
            this.RefreshErrorStatistics();
        }
        FieldInfo[] fields = typeof(CheckerType).GetFields();
        for (int i = 1; i < fields.Length; i++)
        {
            string      checkerName = fields[i].ToString().Split(' ')[1];
            CheckerType checkerType = (CheckerType)fields[i].GetValue(null);
            BaseChecker checker     = GetChecker(checkerType);
            checker.SetFileName(checkerName);

            GUILayout.BeginHorizontal();

            // 检查
            if (GUILayout.Button(checkerName + "Check"))
            {
                errorDirty = true;
                Debug.LogFormat("[AssetsChecker] Start Check {0}", checkerName);
                double start_time = EditorApplication.timeSinceStartup;
                checker.StartCheck();
                checker.Output();
                this.SaveCacheErrorCount(checkerName, checker.ErrorCount, checker.GetErrorDesc());

                Debug.LogFormat("[AssetsChecker] Check Complete, cost time{0}s, error count {1}",
                                Convert.ToInt32(EditorApplication.timeSinceStartup - start_time),
                                checker.ErrorCount);
            }

            // 修复
            if (this.GetCacheErrorCount(checkerName) > 0)
            {
                if (GUILayout.Button("Fix"))
                {
                    errorDirty = true;
                    checker.StartFix();
                }
            }

            GUILayout.EndHorizontal();
        }
    }
        /* The course of artificial intelligence
         * Calculation of moves, verification of conditions for winning and losing
         */
        public void AiTurn()
        {
            BaseChecker  selectedChecker = null;
            PathPoint    toPoint;
            AIController ai = new AIController(state.AiSide);

            // Trying to find the selected checker
            ai.GetAiTurn(out selectedChecker, out toPoint);

            // If the checker was selected
            if (selectedChecker != null)
            {
                // Attempt to move to a given position
                do
                {
                    PathPoint newPath = ai.RandomPath(toPoint);
                    if (newPath == null)
                    {
                        break;
                    }

                    Point toBoardPosition = newPath.Position;
                    DoMovement(selectedChecker, toBoardPosition);
                    toPoint = newPath;
                }while (state.ActiveChecker != null);
                // Checking the conditions of victory and defeat
                CheckVictoryConditions();
            }
            else
            {
                // Checking the conditions of victory and defeat
                CheckVictoryConditions();
            }

            // Redraw the scene
            Game.drawingController.PrioritizedDraw();

            // Clearing memory from objects generated by active computation of edible options
            GC.Collect();
        }
        /* Trying to find the selected checkers after clicking the mouse button
         */
        private bool TryFindSelectedCheckers(MouseEventArgs mouseArgs, ref BaseChecker previouslySelectedChecker, ref BaseChecker currentSelectedChecker)
        {
            bool anyoneSelected = false;

            foreach (BaseChecker checker in state.AllCheckers)
            {
                // Mark previously selected checker
                if (checker.selected)
                {
                    previouslySelectedChecker = checker;
                }

                // Marking the checker just selected
                Rectangle checkerCoord = new Rectangle(checker.Position.ScreenPosition, checker.Position.DrawableSize);
                if (checkerCoord.Contains(mouseArgs.Location))
                {
                    SelectChecker(checker);
                    currentSelectedChecker = checker;
                    anyoneSelected         = true;
                }
            }
            return(anyoneSelected);
        }
示例#10
0
        /* Calculating the computer's move
         */
        public void GetAiTurn(out BaseChecker selectedChecker, out PathPoint toPosition)
        {
            selectedChecker = null;
            toPosition      = null;
            List <PathPoint> possibleTurns = new List <PathPoint>(); // List of possible moves

            // Building a list of possible moves
            foreach (BaseChecker checker in Side == CheckerSide.White ? Game.gameplayController.state.WhiteCheckers :
                     Game.gameplayController.state.BlackCheckers)
            {
                PathPoint turn = checker.GetPossibleTurns();
                if (!turn.IsDeadEnd()) // If not a dead-end point, add a route to the list
                {
                    possibleTurns.Add(turn);
                }
            }

            // If no moves are found - a loss
            if (possibleTurns.Count == 0)
            {
                selectedChecker = null;
                toPosition      = null;
                return;
            }

            // Trying to find aggressive moves
            foreach (PathPoint chain in possibleTurns)
            {
                List <int> eatableDirections = chain.TryGetAggresiveDirections();
                if (eatableDirections.Count > 0)
                {
                    // Aggressive move found
                    toPosition = chain;

                    // We find out the path belonging to the checker and leave the method
                    foreach (BaseChecker checker in Side == CheckerSide.White ? Game.gameplayController.state.WhiteCheckers :
                             Game.gameplayController.state.BlackCheckers)
                    {
                        PathPoint turn = checker.GetPossibleTurns();
                        if (turn.Position == chain.Position)
                        {
                            selectedChecker = checker;
                            return;
                        }
                    }
                }
            }
            // There are no "edible" moves, we are looking for peaceful ones in a random way
            Random rnd = new Random();

            toPosition = possibleTurns[rnd.Next(possibleTurns.Count - 1)];
            // Matching the move with the checker
            foreach (BaseChecker checker in Side == CheckerSide.White ? Game.gameplayController.state.WhiteCheckers :
                     Game.gameplayController.state.BlackCheckers)
            {
                PathPoint turn = checker.GetPossibleTurns();
                if (turn.Position == toPosition.Position)
                {
                    selectedChecker = checker;
                }
            }

            return;
        }
        /* Trying to move checker
         * Calculating the movement
         * ------------------------------------------------------------------------------
         */
        private void DoMovement(BaseChecker previouslySelectedChecker, Point toPosition)
        {
            string    logMessage = Constants.localized.logTurn + ' ';
            PathPoint turns;

            // Erase highlighting on all checkers
            DeselectAllCheckers();

            // If the move does not start
            if (state.ActiveCheckerPathPoint == null)
            {
                turns = previouslySelectedChecker.GetPossibleTurns(); // Calculation of all possible chains of moves for a checker
                state.ActiveCheckerPathPoint = turns;
            }
            else
            {
                turns = state.ActiveCheckerPathPoint; // Continuation of the movement
            }
            // If the position is not a deadlock
            if (!turns.IsDeadEnd())
            {
                state.ActiveChecker = previouslySelectedChecker;

                // Movement
                for (int i = 0; i < 4; i++)
                {
                    foreach (PathPoint point in turns[i])
                    {
                        if (toPosition == point.Position)
                        {
                            Point fromPosition = new Point()
                            {
                                X = previouslySelectedChecker.Position.BoardPosition.X,
                                Y = previouslySelectedChecker.Position.BoardPosition.Y
                            };
                            logMessage += previouslySelectedChecker.GetPrintablePosition() + $" {Constants.localized.logMoveTo} ";
                            // Moving the checker to the selected position
                            previouslySelectedChecker.MoveTo(new Point(toPosition.X, toPosition.Y));
                            logMessage += previouslySelectedChecker.GetPrintablePosition();
                            Game.userLogController.WriteMessage(logMessage);
                            // Defining the direction of movement
                            Point moveDirection = new Point()
                            {
                                X = toPosition.X - fromPosition.X > 0 ? 1 : -1,
                                Y = toPosition.Y - fromPosition.Y > 0 ? 1 : -1
                            };

                            // Determination of the eaten checkers
                            TryEatEnemyCheckers(previouslySelectedChecker, toPosition, fromPosition, moveDirection);

                            // If the checker can become a king
                            if (previouslySelectedChecker is Pawn && previouslySelectedChecker.Position.BoardPosition.Y ==
                                (previouslySelectedChecker.Direction == CheckerMoveDirection.Upstairs ? 0 : 7))
                            {
                                // Replacement of a checker by a king
                                King newKing = new King(previouslySelectedChecker.Side, previouslySelectedChecker.Position);
                                state.AllCheckers.Remove(previouslySelectedChecker);
                                state.AllCheckers.Add(newKing);

                                // Adding to the list of drawings
                                Game.drawingController.AddToDrawingList(newKing);
                                previouslySelectedChecker.Destroy();

                                // Calculation of the further path for a king
                                state.ActiveChecker = newKing;
                                if (state.ActiveCheckerPathPoint.afterAggression)
                                {
                                    state.ActiveCheckerPathPoint = newKing.GetPossibleTurns(DirectionHelper.GetOppositeDirection(DirectionHelper.GetDirection(moveDirection)));
                                    if (state.ActiveCheckerPathPoint.TryGetAggresiveDirections().Count == 0)
                                    {
                                        // End of turn
                                        EndTurn();
                                        return;
                                    }
                                    else
                                    {
                                        DeselectAllCheckers();
                                        state.ActiveChecker.selected = true;
                                        HighlightPossibleTurns(state.ActiveChecker);
                                    }
                                }
                                else
                                {
                                    EndTurn();
                                    return;
                                }
                            }

                            // Find the point he went to
                            // Calculate whether it is possible to continue the movement
                            foreach (PathPoint waypoint in state.ActiveCheckerPathPoint[DirectionHelper.GetDirection(moveDirection)])
                            {
                                if (waypoint.Position == toPosition)
                                {
                                    if (!waypoint.IsOnlyFinalTraces())
                                    {
                                        // Continuation of the movement
                                        state.ActiveCheckerPathPoint = waypoint;
                                        DeselectAllCheckers();
                                        state.ActiveChecker.selected = true;
                                        HighlightPossibleTurns(state.ActiveChecker);
                                    }
                                    else
                                    {
                                        // End of turn
                                        EndTurn();
                                    }
                                }
                            }
                            return;
                        }
                    }
                }
            }
            else
            {
                // Deadlock position, end of turn
                if (state.ActiveChecker != null || state.ActiveCheckerPathPoint != null)
                {
                    state.ActiveChecker          = null;
                    state.ActiveCheckerPathPoint = null;
                }
            }
        }
        /* When you click on the game board, this method is called
         */
        public void OnClick(MouseEventArgs mouseArgs)
        {
            bool        anyoneSelected            = false;
            BaseChecker previouslySelectedChecker = null;
            BaseChecker currentSelectedChecker    = null;

            // Trying to find the selected checker
            anyoneSelected = TryFindSelectedCheckers(mouseArgs, ref previouslySelectedChecker, ref currentSelectedChecker);

            // If the checker was not selected
            if (!anyoneSelected)
            {
                // If the checker was selected at the last step
                if (previouslySelectedChecker != null)
                {
                    // Attempt to move to a given position
                    Point toBoardPosition = new Point()
                    {
                        X = mouseArgs.X / cellSize.Width,
                        Y = mouseArgs.Y / cellSize.Height
                    };
                    DoMovement(previouslySelectedChecker, toBoardPosition);

                    // Checking the conditions of victory and defeat
                    CheckVictoryConditions();
                }
                else
                {
                    // Clicked on an empty field
                    DeselectAllCheckers();
                    state.ActiveChecker          = null;
                    state.ActiveCheckerPathPoint = null;
                }
            }
            else
            {
                // The checker is selected
                // Prevent the move by another checker (other than the selected one)
                if (state.ActiveChecker != null)
                {
                    if (state.ActiveChecker != currentSelectedChecker)
                    {
                        currentSelectedChecker = null;
                        return;
                    }
                }

                List <BaseChecker> turnList = new List <BaseChecker>();
                bool aggressive             = false;
                bool turnFound = false;
                foreach (BaseChecker checker in currentSelectedChecker.Side == CheckerSide.White ? state.WhiteCheckers : state.BlackCheckers)
                {
                    PathPoint turns = checker.GetPossibleTurns();
                    if (turns.IsDeadEnd())
                    {
                        continue;
                    }
                    if (turns.TryGetAggresiveDirections().Count > 0)
                    {
                        turnList.Add(checker);
                        aggressive = true;
                    }
                }

                // Filtering moves (if you can eat something, block "inedible" moves)
                if (!aggressive)
                {
                    ClearHighlighting();
                    HighlightPossibleTurns(currentSelectedChecker); // Highlight it
                }
                else
                {
                    foreach (BaseChecker checker in turnList)
                    {
                        if (checker == currentSelectedChecker)
                        {
                            turnFound = true;
                        }
                    }

                    ClearHighlighting();
                    if (turnFound)
                    {
                        HighlightPossibleTurns(currentSelectedChecker);
                    }
                    else
                    {
                        DeselectAllCheckers();
                    }
                }
            }

            // Redraw the scene
            Game.drawingController.PrioritizedDraw();

            // Clearing memory from objects generated by active computation of edible options
            GC.Collect();
        }