Ejemplo n.º 1
0
        protected int TryGetCollissionTurn(Move move, Position _myPosition, Direction _myDirection, int[,] gameSurrond, int movestToStraight)
        {
            _score = 1;
            Direction simulateDirection = _myDirection;
            Position  simulatePosition  = _myPosition.Copy();

            int[,] simulateGameSurround = (int[, ])gameSurrond.Clone();

            simulateDirection = simulateDirection.GetNewDirection(move);
            simulatePosition.Update(simulateDirection);
            _walks.Add(new Walk(_round, move, simulateDirection, simulatePosition.Copy()));
            if (_score == movestToStraight)
            {
                move = Move.Straight;
            }

            while (!_ch.Collission(simulateDirection, simulateGameSurround, simulatePosition))
            {
                simulateGameSurround[simulatePosition.X, simulatePosition.Y] = _myId;
                simulateDirection = simulateDirection.GetNewDirection(move);
                simulatePosition.Update(simulateDirection);
                _score++;
                _round++;
                _walks.Add(new Walk(_round, move, simulateDirection, simulatePosition.Copy()));
                if (_score == movestToStraight)
                {
                    move = Move.Straight;
                }
            }
            return(_score);
        }
Ejemplo n.º 2
0
        internal void RepairSteps(int round, List <Walk> planedWalks, int[,] gameSurround)
        {
            int roundIndCollission = 0;

            foreach (Walk walk in planedWalks.Where(x => x.Round > round))
            {
                if (_ch.Collission(walk.Direction, gameSurround, walk.Position))
                {
                    roundIndCollission = walk.Round;
                    continue;
                }
            }

            if (roundIndCollission != 0)
            {
                var lastWalk = planedWalks.Where(x => x.Round == round - 1).First();
                planedWalks.Clear();
            }

            if (roundIndCollission == 0)
            {
                var lastWalk = planedWalks.OrderByDescending(x => x.Round).First();

                foreach (var walkSet in _walkSets)
                {
                    walkSet.Evaluate(lastWalk.Round, lastWalk.Position, lastWalk.Direction, gameSurround);
                }
                var best = _walkSets.OrderByDescending(x => x.Score).FirstOrDefault();
                if (best.Score < 20)
                {
                    RemovePosibbleWalks(round, 20, planedWalks);
                }
            }
        }