コード例 #1
0
    bool SafeNode(GameManager.SensorData data)
    {
        bool val = false;

        if ((data & GameManager.SensorData.OffGrid) == 0 && (data & GameManager.SensorData.Wall) == 0 && (data & GameManager.SensorData.Bomb) == 0)
        {
            val = true;
        }
        return(val);
    }
コード例 #2
0
ファイル: AI_Character.cs プロジェクト: dcarrigg/TestRepo
 /// <summary>
 /// Does the tile we just looked at contain the <see cref="data"/> passed in?
 /// </summary>
 /// <param name="self"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static bool Contains(this SensorData self, params SensorData[] data)
 {
     // If self contains a bit from ANY of the values passed in, return true
     for (int i = 0; i < data.Length; i++)
     {
         if ((self & data[i]) != 0)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #3
0
ファイル: TileInfo.cs プロジェクト: dcarrigg/TestRepo
    public TileInfo(SensorData m_TileData)
    {
        tileData = m_TileData;

        if ((tileData & SensorData.Diamond) != 0)
        {
            isDiamond = true;
        }
        if ((tileData & SensorData.Goal) != 0)
        {
            isGoal = true;
        }
    }
コード例 #4
0
ファイル: TileInfo.cs プロジェクト: dcarrigg/TestRepo
 /// <summary>
 /// Updates information in the direction of an adjacent tile
 /// </summary>
 /// <param name="m_Direction">Direction of the tile to update (Up, Down, Left, Right)</param>
 /// <param name="m_AdjacentTileData">SensorData of the adjacent tile</param>
 public void UpdateAdjacentTileData(Direction m_Direction, SensorData m_AdjacentTileData)
 {
     adjacentTiles[m_Direction].SetTileData(m_AdjacentTileData);
 }
コード例 #5
0
ファイル: TileInfo.cs プロジェクト: dcarrigg/TestRepo
 public void SetTileData(SensorData m_TileData)
 {
     tileData = m_TileData;
 }
コード例 #6
0
ファイル: AI_Character.cs プロジェクト: dcarrigg/TestRepo
        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);
        }