Beispiel #1
0
        public override CombatantAction GetAction(ref List <Direction> aMoves, ref int aBombTime)
        {
            // Check all directions
            m_RightTile   = UseSensor(Direction.Right);
            m_LeftTile    = UseSensor(Direction.Left);
            m_UpTile      = UseSensor(Direction.Up);
            m_DownTile    = UseSensor(Direction.Down);
            m_CurrentTile = UseSensor(Direction.Current);

            // Update the surrounding tiles
            UpdateSurroundingTiles();

            aBombTime = Random.Range(m_BombTime.min, m_BombTime.max + 1);

            // Managing Movement

            // For each node, check to make sure that the node was not yet visited and is not dangerous, or
            // check if the diamond is there
            // If so, then try to move to that position
            if (m_CurrentNode.left.visited == false && m_CurrentNode.left.tile.Contains(m_DangerousAreas) == false ||
                m_CurrentNode.left.tile.Contains(SensorData.Diamond))
            {
                // If an enemy is there, drop a bomb
                if (m_CurrentNode.left.tile.Contains(SensorData.Enemy))
                {
                    return(CombatantAction.DropBomb);
                }
                aMoves.Add(Direction.Left);
            }
            // Same logic as the first part, but for different nodes
            else if (m_CurrentNode.right.visited == false && m_CurrentNode.right.tile.Contains(m_DangerousAreas) == false ||
                     m_CurrentNode.right.tile.Contains(SensorData.Diamond))
            {
                if (m_CurrentNode.right.tile.Contains(SensorData.Enemy))
                {
                    return(CombatantAction.DropBomb);
                }
                aMoves.Add(Direction.Right);
            }
            else if (m_CurrentNode.up.visited == false && m_CurrentNode.up.tile.Contains(m_DangerousAreas) == false ||
                     m_CurrentNode.up.tile.Contains(SensorData.Diamond))
            {
                if (m_CurrentNode.up.tile.Contains(SensorData.Enemy))
                {
                    return(CombatantAction.DropBomb);
                }
                aMoves.Add(Direction.Up);
            }
            else if (m_CurrentNode.down.visited == false && m_CurrentNode.down.tile.Contains(m_DangerousAreas) == false ||
                     m_CurrentNode.down.tile.Contains(SensorData.Diamond))
            {
                if (m_CurrentNode.down.tile.Contains(SensorData.Enemy))
                {
                    return(CombatantAction.DropBomb);
                }
                aMoves.Add(Direction.Down);
            }
            else
            {
                // Go into a random direction if all tiles are already visited
                // keep re-rolling until we get a proper direction, or until we've tried 10 more times
                Direction  dir        = (Direction)Random.Range(0, 4);
                SensorData targetTile = UseSensor(dir);
                for (int i = 0; i < 10; i++)
                {
                    if (targetTile.Contains(m_DangerousAreas))
                    {
                        dir        = (Direction)Random.Range(0, 4);
                        targetTile = UseSensor(dir);
                    }
                    else
                    {
                        break;
                    }
                }
                // just pass if for some reason, our AI wants to walk into a wall
                if (targetTile.Contains(SensorData.OffGrid, SensorData.Wall))
                {
                    return(CombatantAction.Pass);
                }
                else if (targetTile.Contains(SensorData.Enemy))
                {
                    return(CombatantAction.DropBomb);
                }

                // Just move to the position
                aMoves.Add(dir);
            }

            // This will update the coordinates and return a movement action
            CombatantAction action = MoveAndUpdateCoords(ref aMoves);

            Debug.LogFormat("[{0}][{1}]", m_Horizontal, m_Vertical);
            return(action);
        }