private bool IsMonsterAvailable()
        {
            Cave cave          = new Cave();
            bool isALive       = m_world.isMonsterAlive;
            bool isArrowsExist = m_info.arrowCount > 0;

            return(isALive && isArrowsExist && GetMonsterCave(ref cave));
        }
예제 #2
0
        public int GetAttention(Cave cave)
        {
            Validate(cave);
            int row  = cave.row;
            int coll = cave.coll;

            int monsterChance = m_monsterChance[row, coll];
            int holeChance    = m_holeChance[row, coll];

            return(monsterChance * 2 + holeChance);
        }
예제 #3
0
 public bool GetMonsterCave(ref Cave monsterCave)
 {
     foreach (Cave cave in m_cavesMap)
     {
         if (cave.isMonster)
         {
             monsterCave = cave;
             return(true);
         }
     }
     return(false);
 }
        private bool GetMonsterCave(ref Cave monsterCave)
        {
            foreach (Cave cave in m_cavesMap.ToList())
            {
                if (m_cavesMap.GetMonsterChance(cave) < 2 || cave.isVisible)
                {
                    continue;
                }

                monsterCave = cave;
                return(true);
            }
            return(false);
        }
        private bool IsOnLineWithMonster(Cave currentCave)
        {
            Cave monsterCave = new Cave();

            if (!m_mapPhysics.GetMonsterCave(ref monsterCave))
            {
                return(false);
            }

            bool isCommonRow  = monsterCave.row == currentCave.row;
            bool isCommonColl = monsterCave.coll == currentCave.coll;

            return(isCommonRow || isCommonColl);
        }
        protected override bool AddToWayPredicate(SearchNode parent, Cave child)
        {
            Cave wayCave = m_cavesMap.GetCave(child.row, child.coll);

            if (wayCave.isVisible && !wayCave.isHole)
            {
                return(true);
            }
            bool isEmpty     = wayCave.isVisible && wayCave.isAvailable;
            bool isNoHole    = m_cavesMap.GetHoleChance(wayCave) < 2;
            bool isNoMonster = m_cavesMap.GetMonsterChance(wayCave) < 1;

            return(isEmpty || (isNoHole && isNoMonster));
        }
예제 #7
0
        public void AddCave(Cave cave, bool isMonsterAlive = false)
        {
            Validate(cave);
            m_caves[cave.row, cave.coll] = cave;

            MarkWings(cave);
            if (cave.isHole)
            {
                m_holeChance[cave.row, cave.coll] = 2;
            }
            if (isMonsterAlive && !IsMonsterDefined())
            {
                MarkBones(cave);
            }
        }
예제 #8
0
        public CavesMap(int rowsCount, int collsCount)
        {
            m_rowsCount     = rowsCount;
            m_collsCount    = collsCount;
            m_caves         = new Cave[rowsCount, collsCount];
            m_monsterChance = new int[rowsCount, collsCount];
            m_holeChance    = new int[rowsCount, collsCount];
            m_checkedBones  = new bool[rowsCount, collsCount];
            m_checkedWings  = new bool[rowsCount, collsCount];

            InitCaves();
            Utils.FillMatrix(ref m_monsterChance, 0);
            Utils.FillMatrix(ref m_holeChance, 0);
            Utils.FillMatrix(ref m_checkedBones, false);
            Utils.FillMatrix(ref m_checkedWings, false);
        }
예제 #9
0
        public void ClearMonsterLine(Cave cave, Direction dir)
        {
            int row  = cave.row;
            int coll = cave.coll;

            if (dir == Direction.LEFT || dir == Direction.RIGHT)
            {
                for (int i = 0; i < m_collsCount; i++)
                {
                    m_monsterChance[row, i] = 0;
                }
                return;
            }
            for (int i = 0; i < m_rowsCount; i++)
            {
                m_monsterChance[i, coll] = 0;
            }
        }
예제 #10
0
        private void MarkBones(Cave newCave)
        {
            if (!newCave.isBone || m_checkedBones[newCave.row, newCave.coll])
            {
                return;
            }

            List <Pair <int, int> > brothers = GetBroCoords(newCave);

            foreach (Pair <int, int> coord in brothers)
            {
                m_checkedBones[newCave.row, newCave.coll] = true;
                if (m_monsterChance[coord.first, coord.second] < 2 &&
                    !m_caves[coord.first, coord.second].isVisible)
                {
                    m_monsterChance[coord.first, coord.second]++;
                }
            }
        }
        private Move GetKillMonsterMove()
        {
            Cave monsterCave = new Cave();

            if (!GetMonsterCave(ref monsterCave))
            {
                throw new GameException("GetKillMonsterMove", "Monster cave not found.");
            }

            Direction dir   = m_info.currentDir;
            int       row   = m_mapPhysics.cave.row;
            int       coll  = m_mapPhysics.cave.coll;
            int       mRow  = monsterCave.row;
            int       mColl = monsterCave.coll;

            PassiveAct roll = GetRollTo(row, coll, dir, mRow, mColl);

            return(new Move(roll, ActiveAct.SHOOT));
        }
예제 #12
0
        protected bool GetPossibleCaves(ref List <Cave> possibleCaves)
        {
            Cave start = m_mapPhysics.cave;

            possibleCaves.Clear();
            m_searchQueue.Clear();
            m_processHashes.Clear();
            m_searchQueue.Enqueue(new SearchNode(start.row, start.coll));

            while (m_searchQueue.Count != 0)
            {
                SearchNode queueTop = m_searchQueue.Dequeue();
                AddToPossibleList(queueTop, Direction.UP, ref possibleCaves);
                AddToPossibleList(queueTop, Direction.DOWN, ref possibleCaves);
                AddToPossibleList(queueTop, Direction.LEFT, ref possibleCaves);
                AddToPossibleList(queueTop, Direction.RIGHT, ref possibleCaves);
            }

            return(possibleCaves.Count != 0);
        }
예제 #13
0
        public List <Cave> GetSemilineCaves(Cave cave)
        {
            Validate(cave);
            int         row    = cave.row;
            int         coll   = cave.coll;
            List <Cave> result = new List <Cave>();

            for (int i = 0; i < m_rowsCount; i++)
            {
                for (int j = 0; j < m_collsCount; j++)
                {
                    if (i == row && j == coll)
                    {
                        continue;
                    }
                    result.Add(m_caves[i, j]);
                }
            }

            return(result);
        }
        private Move ScoutTactic()
        {
            Cave             cave = m_mapPhysics.cave;
            Direction        dir  = m_info.currentDir;
            List <Direction> way  = null;

            if ((m_isScout || GetBestCave(ref m_scoutCell)) &&
                GetBestWay(cave, m_scoutCell, ref way, freeLives))
            {
                PassiveAct rotation = GetRollTo(dir, way[0]);
                return(new Move(rotation, ActiveAct.GO));
            }

            try
            {
                PassiveAct scoutPass = GetRollTo(cave, dir, m_scoutCell);
                return(new Move(scoutPass, ActiveAct.GO));
            } catch (GameException) {}

            return(GetRandomMove());
        }
        private Move TryDoFinalShoot(Move finalMove)
        {
            Cave        currCave    = m_mapPhysics.cave;
            List <Cave> caves       = m_cavesMap.GetSemilineCaves(currCave);
            Cave        monsterCave = caves[0];

            foreach (Cave cave in caves)
            {
                int       currentChance = m_cavesMap.GetMonsterChance(cave);
                int       newChance     = m_cavesMap.GetMonsterChance(cave);
                Direction dir           = m_info.currentDir;

                if (newChance != 0 && currentChance >= newChance && !cave.isVisible)
                {
                    PassiveAct roll = GetRollTo(currCave, dir, cave);
                    finalMove = new Move(roll, ActiveAct.SHOOT);
                }
            }

            return(finalMove);
        }
예제 #16
0
        protected bool GetBestWay(Cave from, Cave to, ref List <Direction> way, int lives)
        {
            if (lives > 0 && GetWay(from, to, ref way, 0))
            {
                return(true);
            }

            m_bestWayQueue.Clear();
            m_processHashes.Clear();
            m_bestWayQueue.Add(new SearchNode(from.row, from.coll, lives));

            while (m_bestWayQueue.Count != 0)
            {
                SearchNode queueTop   = m_bestWayQueue[0];
                Cave       cave       = m_cavesMap.GetCave(queueTop.row, queueTop.coll);
                int        bestChance = m_cavesMap.GetAttention(cave);
                foreach (SearchNode node in m_bestWayQueue)
                {
                    Cave newCave   = m_cavesMap.GetCave(queueTop.row, queueTop.coll);
                    int  newChance = m_cavesMap.GetAttention(newCave);
                    if (newChance < bestChance)
                    {
                        bestChance = newChance;
                        queueTop   = node;
                    }
                }
                m_bestWayQueue.Remove(queueTop);
                if (queueTop.hash == to.hash)
                {
                    way = queueTop.way;
                    return(true);
                }
                AddToBestWaySearch(queueTop, Direction.UP);
                AddToBestWaySearch(queueTop, Direction.DOWN);
                AddToBestWaySearch(queueTop, Direction.LEFT);
                AddToBestWaySearch(queueTop, Direction.RIGHT);
            }

            return(false);
        }
        private Move TakeTactic()
        {
            if (m_mapPhysics.cave.isGold)
            {
                Move move = new Move(PassiveAct.NONE, ActiveAct.TAKE);
                move = TryDoFinalShoot(move);
                m_cavesMap.ClearMonsterMarks();
                return(move);
            }

            Cave             goldCave = new Cave();
            List <Direction> way      = new List <Direction>();

            if (m_cavesMap.GetGoldCave(ref goldCave) &&
                GetWay(m_mapPhysics.cave, goldCave, ref way, freeLives))
            {
                PassiveAct rotation = GetRollTo(m_info.currentDir, way[0]);
                return(new Move(rotation, ActiveAct.GO));
            }

            return(GetRandomMove());
        }
예제 #18
0
        private void AddToBestWaySearch(SearchNode parent, Direction dir)
        {
            int row  = parent.row;
            int coll = parent.coll;

            CalcCoordinates(ref row, ref coll, dir);

            if (m_cavesMap.IsExist(row, coll))
            {
                string newHash     = Utils.CaveHash(row, coll);
                bool   isHashValid = !m_processHashes.Contains(newHash);
                Cave   nextCave    = m_cavesMap.GetCave(row, coll);

                if (isHashValid && AddToWayPredicate(parent, nextCave))
                {
                    List <Direction> way  = parent.way;
                    SearchNode       node = new SearchNode(row, coll, way, dir);
                    node.lives = (nextCave.isHole) ? parent.lives - 1 : parent.lives;
                    m_processHashes.Add(node.hash);
                    m_bestWayQueue.Add(node);
                }
            }
        }
예제 #19
0
        protected bool GetBestCave(ref Cave bestCave)
        {
            List <Cave> possibleCaves = new List <Cave>();

            if (GetPossibleCaves(ref possibleCaves))
            {
                bestCave = possibleCaves[0];
                int bestAttention = m_cavesMap.GetAttention(bestCave);

                foreach (Cave cave in possibleCaves)
                {
                    int newAttention = m_cavesMap.GetAttention(cave);
                    if (newAttention < bestAttention)
                    {
                        bestAttention = newAttention;
                        bestCave      = cave;
                    }
                }

                m_isScout = true;
                return(true);
            }
            return(false);
        }
예제 #20
0
 public int GetMonsterChance(Cave cave)
 {
     Validate(cave);
     return(m_monsterChance[cave.row, cave.coll]);
 }
예제 #21
0
 protected static PassiveAct GetRollTo(Cave current, Direction currDir, Cave next)
 {
     return(GetRollTo(current.row, current.coll, currDir, next.row, next.coll));
 }
예제 #22
0
 protected virtual bool AddToWayPredicate(SearchNode parent, Cave child)
 {
     return(child.IsAvailable(parent.lives));
 }
예제 #23
0
 public bool GetMonsterCave(ref Cave monsterCave)
 {
     return(m_data.GetMonsterCave(ref monsterCave));
 }
예제 #24
0
 public int GetHoleChance(Cave cave)
 {
     Validate(cave);
     return(m_holeChance[cave.row, cave.coll]);
 }