コード例 #1
0
        public void CheckSells(int x, int y)
        {
            PossiblePositions[] position = new PossiblePositions[8];
            position[0].X = new List <int>();
            position[0].Y = new List <int>();
            position[0].X.Add(x);
            position[0].Y.Add(y);

            int[] positionIndex = new int[8] {
                0, 0, 0, 0, 0, 0, 0, 0
            };
            int n = 1, countRecursionRuns = 0;

            while (n < 8)
            {
                position[n].X = new List <int>();
                position[n].Y = new List <int>();
                int countPosiblePositions = 0;

                ClearPossiblePosiitons(position, n);
                SetPossiblePositions(position, n, ref countPosiblePositions);

                if (countPosiblePositions > 0)
                {
                    PlaceQueen(position[n].X[0], position[n].Y[0]);
                    n++;
                }
                else
                {
                    PlaceAgain(position, ref n, ref countPosiblePositions, ref countRecursionRuns, positionIndex);
                }
            }
        }
コード例 #2
0
    private void fillPossiblePositionOnMove(PossiblePositions possibility, Action action, bool[,] islands, VisitedState[,] derivedVisisted)
    {
        var dX = -S.MoveX(action.direction);
        var dY = -S.MoveY(action.direction);

        for (int i = -1; i <= width; i++)
        {
            for (int j = -1; j <= height; j++)
            {
                var x = dX >= 0 ? i : width - 1 - i;
                var y = dY >= 0 ? j : height - 1 - j;
                if (S.isOutOfBoundsOrIsland(islands, x, y))
                {
                    if (!S.isOutOfBoundsOrIsland(islands, x + dX, y + dY) && possibility.map[x + dX, y + dY])
                    {
                        possibility.total -= 1;
                    }
                    continue;
                }
                if (S.isOutOfBoundsOrIsland(islands, x + dX, y + dY))
                {
                    possibility.map[x, y] = false;
                }
                else
                {
                    possibility.map[x, y] = possibility.map[x + dX, y + dY];
                }
                if (derivedVisisted[x, y] == VisitedState.fresh)
                {
                    derivedVisisted[x, y] = VisitedState.old;
                }
            }
        }
    }
コード例 #3
0
 public FootballPlayer(bool offense, bool defense, bool specialTeams, PossiblePositions positions)
 {
     Offense      = offense;
     Defense      = defense;
     SpecialTeams = specialTeams;
     Positions    = positions;
 }
コード例 #4
0
    public PossiblePositions Clone()
    {
        var result = new PossiblePositions();

        result.map   = map.Clone() as bool[, ];
        result.total = total;
        return(result);
    }
コード例 #5
0
 public void CheckNoPossibilityOverVisited(VisitedState[,] derivedVisited, PossiblePositions possibility)
 {
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             if (derivedVisited[x, y] == VisitedState.old && possibility.map[x, y])
             {
                 possibility.total--;
                 possibility.map[x, y] = false;
             }
         }
     }
 }
コード例 #6
0
    public void processEnemyMine(ProbableMines enemyProbableMines, PossiblePositions possibility, Action action)
    {
        var mine = new Mine();

        for (var x = 0; x < width; ++x)
        {
            for (var y = 0; y < width; ++y)
            {
                if (possibility.map[x, y])
                {
                }
            }
        }
    }
コード例 #7
0
    public void processSilence(Action action, bool[,] reachSilence, PossiblePositions possibility, bool[,] islands, PathMark[,] recordedPath)
    {
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                reachSilence[x, y] = false;
            }
        }

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (possibility.map[x, y])
                {
                    foreach (var dir in S.possibleDirections)
                    {
                        var dX = S.MoveX(dir);
                        var dY = S.MoveY(dir);
                        for (int k = 1; k <= 4; k++)
                        {
                            if (S.isOutOfBoundsOrIsland(islands, x + dX * k, y + dY * k) || recordedPath[S.pathCenterX + dX * k, S.pathCenterY + dY * k].visited)
                            {
                                break;
                            }
                            reachSilence[x + dX * k, y + dY * k] = true;
                        }
                    }
                }
            }
        }
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (reachSilence[x, y] && !possibility.map[x, y])
                {
                    possibility.map[x, y] = true;
                    ++possibility.total;
                }
            }
        }
        //TODO: implement branching instead of erasing memory here:
        S.EraseRecordedPath(recordedPath);
    }
コード例 #8
0
    private void MarkVisitedPath(VisitedState[,] possibleVisited, PathMark[,] path, PossiblePositions possibility)
    {
        var targetX = 0;
        var targetY = 0;
        var found   = false;

        for (int x = 0; x < height && !found; x++)
        {
            for (int y = 0; y < width && !found; y++)
            {
                if (possibility.map[x, y])
                {
                    targetX = x;
                    targetY = y;
                    found   = true;
                }
            }
        }
        MarkVisitedPathRecurs(possibleVisited, path, targetX, targetY, 0, 0);
        possibleVisited[targetX, targetY] = VisitedState.fresh;
    }
コード例 #9
0
 public void processSurface(PossiblePositions posibility, Action action, PathMark[,] recordedPath, bool[,] islands, VisitedState[,] derivedPath)
 {
     posibility.total = 0;
     S.SectorToCoord(action.sector, out int minX, out int maxX, out int minY, out int maxY);
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             if (x < minX || x > maxX || y < minY || y > maxY || S.isOutOfBoundsOrIsland(islands, x, y))
             {
                 posibility.map[x, y] = false;
             }
             else if (posibility.map[x, y])
             {
                 posibility.total += 1;
             }
             derivedPath[x, y] = VisitedState.unknow;
         }
     }
     S.EraseRecordedPath(recordedPath);
 }
コード例 #10
0
    private void processMove(PossiblePositions possibility, Action action, bool[,] islands, PathMark[,] recordedPath, VisitedState[,] derivedVisisted)
    {
        fillPossiblePositionOnMove(possibility, action, islands, derivedVisisted);
        var dX = S.MoveX(action.direction);
        var dY = S.MoveY(action.direction);

        for (int x = dX >= 0 ? 0 : S.pathWidth - 1; dX >= 0 ? x < S.pathWidth : x >= 0; x += (dX >= 0 ? 1 : -1))
        {
            for (int y = dY >= 0 ? 0 : S.pathHeight - 1; dY >= 0 ? y < S.pathHeight : y >= 0; y += (dY >= 0 ? 1 : -1))
            {
                if (x + dX < 0 || x + dX >= S.pathWidth - 1 || y + dY < 0 || y + dY >= S.pathHeight - 1)
                {
                    recordedPath[x, y].visited   = false;
                    recordedPath[x, y].processed = false;
                }
                else
                {
                    recordedPath[x, y] = recordedPath[x + dX, y + dY];
                }
            }
        }
        recordedPath[width - 1, height - 1].visited   = true;
        recordedPath[width - 1, height - 1].processed = false;
    }
コード例 #11
0
    private void processDamageImpact(List <Action> damageActions, int targetOldHealth, int targetNewHealth, List <Action> targetActions, PossiblePositions targetPossibility)
    {
        if (targetOldHealth != -1)
        {
            var surface = targetActions.Any(a => a.type == ActionType.surface);
            var dif     = targetNewHealth - targetOldHealth - (surface ? 1 : 0);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    var shouldErase = false;
                    if (damageActions.Count == 1)
                    {
                        if (dif == 2 && (x != damageActions[0].x || y != damageActions[0].y))
                        {
                            shouldErase = true;
                        }
                        else if (dif == 1 && (Math.Abs(x - damageActions[0].x) > 1 || Math.Abs(y - damageActions[0].y) > 1)) //hit, but it's too far
                        {
                            shouldErase = true;
                        }
                        else if (dif == 1 && x == damageActions[0].x && y == damageActions[0].y)//hit but not a direct center
                        {
                            shouldErase = true;
                        }
                        else if (dif == 0 && Math.Abs(x - damageActions[0].x) <= 1 && Math.Abs(y - damageActions[0].y) <= 1) //didn't hit
                        {
                            shouldErase = true;
                        }
                    }
                    else
                    {
                        if (dif == 4 && (x != damageActions[0].x || y != damageActions[0].y)) //double direct hit. should be the same spot
                        {
                            shouldErase = true;
                        }
                        else if (dif == 3 && (x != damageActions[0].x || y != damageActions[0].y) && (x != damageActions[1].x || y != damageActions[1].y)) // at least on direct hit, should be on the spot of 1 action
                        {
                            shouldErase = true;
                        }
                        else if (dif == 2 && (x != damageActions[0].x || y != damageActions[0].y) && (x != damageActions[1].x || y != damageActions[1].y))//not direct hit
                        {
                            shouldErase = true;
                        }
                        else if (dif == 2 && !(Math.Abs(x - damageActions[0].x) <= 1 && Math.Abs(y - damageActions[0].y) <= 1 && Math.Abs(x - damageActions[1].x) <= 1 && Math.Abs(y - damageActions[1].y) <= 1))//and not close to both shots simulteniously
                        {
                            shouldErase = true;
                        }
                        else if (dif == 1 && (Math.Abs(x - damageActions[0].x) > 1 || Math.Abs(y - damageActions[0].y) > 1) && (Math.Abs(x - damageActions[1].x) > 1 || Math.Abs(y - damageActions[1].y) > 1)) // not close to any
                        {
                            shouldErase = true;
                        }
                        else if (dif == 0 && (Math.Abs(x - damageActions[0].x) <= 1 && Math.Abs(y - damageActions[0].y) <= 1) && (Math.Abs(x - damageActions[1].x) <= 1 || Math.Abs(y - damageActions[1].y) <= 1)) // no hit, but it's close to some damage center
                        {
                            shouldErase = true;
                        }
                    }
                    if (shouldErase)
                    {
                        if (targetPossibility.map[x, y])
                        {
                            targetPossibility.total -= 1;
                        }
                        targetPossibility.map[x, y] = false;
                    }
                }
            }
        }
    }
コード例 #12
0
 private void processFireTorpedo(bool[,] islands, int[,] reachTorpedo, Action action, PossiblePositions atackerPossibility)
 {
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             reachTorpedo[x, y] = 0;
         }
     }
     fillPossibleFireTorpedoPositions(islands, reachTorpedo, action.x, action.y, 5);
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             if (reachTorpedo[x, y] == 0)
             {
                 if (atackerPossibility.map[x, y])
                 {
                     atackerPossibility.total -= 1;
                 }
                 atackerPossibility.map[x, y] = false;
             }
         }
     }
 }