Exemplo n.º 1
0
        private void MakeTurnNodes(TurnNode currentNode, Lib.PlayersSide whoseTurn, int recurciveLevel)
        {
            if (recurciveLevel <= NumberOfRecurciveLevels)
            {
                List <TurnNode> TurnNodes = new List <TurnNode>();
                if (recurciveLevel == 0)
                {
                    currentNode = new TurnNode(boardState, -1, 0); // корень дерева
                }

                List <IChecker> allies  = GetAllies(whoseTurn, currentNode.state);
                List <IChecker> enemies = GetEnemies(whoseTurn, currentNode.state);

                foreach (var checker in allies)
                {
                    if (checker.IsKing)
                    {
                        CheckKingKilling(currentNode, whoseTurn, checker, recurciveLevel);
                        CheckKingMovement(currentNode, whoseTurn, checker, recurciveLevel);
                    }
                    else
                    {
                        CheckKilling(currentNode, whoseTurn, checker, recurciveLevel);
                        CheckMovement(currentNode, whoseTurn, checker, recurciveLevel);
                    }
                }
            }
        }
Exemplo n.º 2
0
    public void ReplaceTurnNode(TurnNode newObject)
    {
        var index     = GameComponentsLookup.TurnNode;
        var component = CreateComponent <TurnNodeComponent>(index);

        component.Object = newObject;
        ReplaceComponent(index, component);
    }
Exemplo n.º 3
0
    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Turn")
        {
            _triggerTransform = other.gameObject.GetComponent <Transform>();
            _lastDistance     = Calc2DDistance();

            TurnNode edge = other.gameObject.GetComponent <TurnNode>();
            _moveLeftAngle      = edge.MoveLeftAngle;
            _moveRightAngle     = edge.MoveRightAngle;
            _moveWithTransition = edge.MoveWithTransition;
        }
    }
Exemplo n.º 4
0
        private void CheckKingKilling(TurnNode currentNode, Lib.PlayersSide whoseTurn, IChecker checker, int level)
        {
            int i = checker.CurrentCoord.Row;
            int j = checker.CurrentCoord.Column;

            while ((i <= 8) && (j <= 8))
            {
                if (checker.CheckPossibilityToKill(new Coord(i, j), gameField))
                {
                    currentNode.AddChild(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(i, j), level));
                }
                i++;
                j++;
            }

            i = checker.CurrentCoord.Row;
            j = checker.CurrentCoord.Column;
            while ((i <= 8) && (j >= 1))
            {
                if (checker.CheckPossibilityToKill(new Coord(i, j), gameField))
                {
                    currentNode.AddChild(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(i, j), level));
                }
                i++;
                j--;
            }

            i = checker.CurrentCoord.Row;
            j = checker.CurrentCoord.Column;
            while ((i >= 1) && (j <= 8))
            {
                if (checker.CheckPossibilityToKill(new Coord(i, j), gameField))
                {
                    currentNode.AddChild(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(i, j), level));
                }
                i--;
                j++;
            }

            i = checker.CurrentCoord.Row;
            j = checker.CurrentCoord.Column;
            while ((i >= 1) && (j >= 1))
            {
                if (checker.CheckPossibilityToKill(new Coord(i, j), gameField))
                {
                    currentNode.AddChild(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(i, j), level));
                }
                i--;
                j--;
            }
        }
Exemplo n.º 5
0
        private void Mixer(ref List <TurnNode> nodes)
        {
            int a = (new Random()).Next(0, nodes.Count);

            for (int i = 0; i < a; i++)
            {
                int      b    = (new Random()).Next(0, nodes.Count);
                int      c    = (new Random()).Next(0, nodes.Count);
                TurnNode temp = nodes[b];
                nodes[b] = nodes[c];
                nodes[c] = temp;
            }
            if (nodes.Count > 0)
            {
                nodes[0] = nodes[a];
            }
        }
Exemplo n.º 6
0
        private TurnNode MovingRecurcion(TurnNode currentNode, Lib.PlayersSide whoseTurn, IChecker checker, Coord destination, int level)
        {
            IChecker[][] state = CreateStateCopy(currentNode.state);
            state = ExecuteOperationToMove(state, state[checker.CurrentCoord.Row][checker.CurrentCoord.Column], destination);
            TurnNode newNode = new TurnNode(state, EstimatingFunction(state), level);

            bool a = (side == Lib.PlayersSide.BLACK && checker is BlackChecker) || (side == Lib.PlayersSide.WHITE && checker is WhiteChecker);

            if (level == 0 && a)
            {
                MovingCommand command = new MovingCommand(game, checker, destination);
                newNode.turnCommand = command; //присваеваем команду на первом уровне рекурсии
                TurnNodes.Add(newNode);
            }
            MakeTurnNodes(newNode, AnotherPlayer(whoseTurn), level + 1);
            return(newNode);
        }
Exemplo n.º 7
0
        private void CheckKilling(TurnNode currentNode, Lib.PlayersSide whoseTurn, IChecker checker, int level)
        {
            List <TurnNode> turnNodes = new List <TurnNode>();

            if (checker.CheckPossibilityToKill(new Coord(checker.CurrentCoord.Row + 2, checker.CurrentCoord.Column + 2), gameField))
            {
                turnNodes.Add(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row + 2, checker.CurrentCoord.Column + 2), level));
            }
            if (checker.CheckPossibilityToKill(new Coord(checker.CurrentCoord.Row - 2, checker.CurrentCoord.Column + 2), gameField))
            {
                turnNodes.Add(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row - 2, checker.CurrentCoord.Column + 2), level));
            }
            if (checker.CheckPossibilityToKill(new Coord(checker.CurrentCoord.Row + 2, checker.CurrentCoord.Column - 2), gameField))
            {
                turnNodes.Add(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row + 2, checker.CurrentCoord.Column - 2), level));
            }
            if (checker.CheckPossibilityToKill(new Coord(checker.CurrentCoord.Row - 2, checker.CurrentCoord.Column - 2), gameField))
            {
                turnNodes.Add(KillingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row - 2, checker.CurrentCoord.Column - 2), level));
            }

            currentNode.AddChild(turnNodes);
        }
Exemplo n.º 8
0
        private void CheckMovement(TurnNode currentNode, Lib.PlayersSide whoseTurn, IChecker checker, int level)
        {
            List <TurnNode> turnNodes = new List <TurnNode>();

            if (checker.CheckPossibilityToMove(new Coord(checker.CurrentCoord.Row + 1, checker.CurrentCoord.Column + 1), gameField))
            {
                turnNodes.Add(MovingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row + 1, checker.CurrentCoord.Column + 1), level));
            }
            if (checker.CheckPossibilityToMove(new Coord(checker.CurrentCoord.Row - 1, checker.CurrentCoord.Column + 1), gameField))
            {
                turnNodes.Add(MovingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row - 1, checker.CurrentCoord.Column + 1), level));
            }
            if (checker.CheckPossibilityToMove(new Coord(checker.CurrentCoord.Row + 1, checker.CurrentCoord.Column - 1), gameField))
            {
                turnNodes.Add(MovingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row + 1, checker.CurrentCoord.Column - 1), level));
            }
            if (checker.CheckPossibilityToMove(new Coord(checker.CurrentCoord.Row - 1, checker.CurrentCoord.Column - 1), gameField))
            {
                turnNodes.Add(MovingRecurcion(currentNode, whoseTurn, checker, new Coord(checker.CurrentCoord.Row - 1, checker.CurrentCoord.Column - 1), level));
            }

            currentNode.AddChild(turnNodes);
        }
Exemplo n.º 9
0
        private TurnNode KillingRecurcion(TurnNode currentNode, Lib.PlayersSide whoseTurn, IChecker checker, Coord destination, int level)
        {
            int killingValue = (whoseTurn == Lib.PlayersSide.BLACK) ? 100 : 0;

            IChecker[][] state   = CreateStateCopy(currentNode.state);
            TurnNode     newNode = new TurnNode(state, killingValue, level);//чем больше уровень рекурсии, тем меньше

            if (checker.CurrentCoord.Row == 4 && checker.CurrentCoord.Column == 3 && level == 0)
            {
            }

            bool a = (side == Lib.PlayersSide.BLACK && checker is BlackChecker) || (side == Lib.PlayersSide.WHITE && checker is WhiteChecker);

            if (level == 0 && a)
            {
                KillingCommand command = new KillingCommand(game, checker, checker.GetVictim(destination, gameField), destination);
                newNode.turnCommand = command; //присваеваем команду на первом уровне рекурсии
                TurnNodes.Add(newNode);
            }
            state = ExecuteOperationToKill(state, state[checker.CurrentCoord.Row][checker.CurrentCoord.Column], checker.GetVictim(destination, gameField), destination);
            MakeTurnNodes(newNode, AnotherPlayer(whoseTurn), level + 1);
            return(newNode);
        }