コード例 #1
0
    public string gridToString(int playerNumber)
    {
        string saida = "";

        for (int y = gridSizeY - 1; y >= 0; --y)
        {
            for (int x = 0; x < gridSizeX; ++x)
            {
                BinaryNode node          = grid[x, y];
                StateType  nodeStateType = adjustAgentStateTypeForBinaryNode(node, playerNumber);

                if (gridViewType == GridViewType.GVT_Binary)
                {
                    saida += StateTypeExtension.getIntBinaryString(nodeStateType) + " | ";
                }
                else if (gridViewType == GridViewType.GVT_Hybrid)
                {
                    string hybridString = convertBinaryToHybridString(nodeStateType);

                    saida += hybridString;
                }
            }
            saida += "\n";
        }

        return(saida);
    }
コード例 #2
0
ファイル: BinaryNode.cs プロジェクト: MeLL-UFF/pip
 public void removeFlag(StateType stateType)
 {
     if (StateTypeExtension.existsFlag(stateType))
     {
         binary = binary & (~stateType);
     }
 }
コード例 #3
0
ファイル: BinaryNode.cs プロジェクト: MeLL-UFF/pip
 public void addFlag(StateType stateType)
 {
     if (StateTypeExtension.existsFlag(stateType))
     {
         binary = binary | stateType;
     }
 }
コード例 #4
0
ファイル: BinaryNode.cs プロジェクト: MeLL-UFF/pip
    //função não testa ST_Empty
    public bool hasSomeFlag(StateType flags)
    {
        if (StateTypeExtension.existsFlag(flags))
        {
            return((binary & flags) != 0 ? true : false);
        }

        return(false);
    }
コード例 #5
0
ファイル: BinaryNode.cs プロジェクト: MeLL-UFF/pip
 public bool hasFlag(StateType stateType)
 {
     if (stateType != StateType.ST_Empty)
     {
         if (StateTypeExtension.existsFlag(stateType))
         {
             return((binary & stateType) == stateType ? true : false);
         }
     }
     else
     {
         if (binary == stateType)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #6
0
    private string convertBinaryToHybridString(StateType nodeStateType)
    {
        float[] binaryArray = StateTypeExtension.convertStateTypeToHybrid(nodeStateType);

        return(StateTypeExtension.convertBinaryArrayToString(binaryArray));
    }
コード例 #7
0
ファイル: Player.cs プロジェクト: MeLL-UFF/pip
    private void AddVectorObsForGrid()
    {
        if (myGridViewType == GridViewType.GVT_Hybrid)
        {
            for (int y = grid.GetGridSizeY() - 1; y >= 0; --y)
            {
                for (int x = 0; x < grid.GetGridSizeX(); ++x)
                {
                    BinaryNode node          = grid.NodeFromPos(x, y);
                    StateType  nodeStateType = grid.adjustAgentStateTypeForBinaryNode(node, playerNumber);
                    float[]    temp          = StateTypeExtension.convertStateTypeToHybrid(nodeStateType);
                    AddVectorObs(temp);
                }
            }
        }
        else if (myGridViewType == GridViewType.GVT_Binary)
        {
            for (int y = grid.GetGridSizeY() - 1; y >= 0; --y)
            {
                for (int x = 0; x < grid.GetGridSizeX(); ++x)
                {
                    BinaryNode node          = grid.NodeFromPos(x, y);
                    StateType  nodeStateType = grid.adjustAgentStateTypeForBinaryNode(node, playerNumber);
                    int        cell          = (int)nodeStateType;

                    AddVectorObs(cell);
                }
            }
        }
        else if (myGridViewType == GridViewType.GVT_ICAART)
        {
            List <float> freeBreakableObstructedCells = new List <float>();
            List <float> positionAgentCells           = new List <float>();
            List <float> positionEnemyCells           = new List <float>();
            List <float> dangerLevelOfPositionsCells  = new List <float>();

            for (int y = grid.GetGridSizeY() - 1; y >= 0; --y)
            {
                for (int x = 0; x < grid.GetGridSizeX(); ++x)
                {
                    BinaryNode node          = grid.NodeFromPos(x, y);
                    StateType  nodeStateType = grid.adjustAgentStateTypeForBinaryNode(node, playerNumber);

                    //enviar grid que representa posições livres, com blocos ou com paredes
                    freeBreakableObstructedCells.Add(node.getFreeBreakableObstructedCell());

                    //enviar grid que representa posição do agente
                    int hasAgent = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_Agent) ? 1 : 0;
                    positionAgentCells.Add(hasAgent);

                    //enviar grid que representa posição dos inimigos
                    hasAgent = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_EnemyAgent) ? 1 : 0;
                    positionEnemyCells.Add(hasAgent);

                    //enviar grid que representa áreas de perigo
                    bool hasDanger = grid.NodeFromPos(x, y).getDangerPosition();
                    if (!hasDanger)
                    {
                        dangerLevelOfPositionsCells.Add(0.0f);
                    }
                    else
                    {
                        float dangerLevel = myBombManager.getDanger(x, y, this);
                        dangerLevelOfPositionsCells.Add(dangerLevel);
                    }
                }
            }

            AddVectorObs(freeBreakableObstructedCells);
            AddVectorObs(positionAgentCells);
            AddVectorObs(positionEnemyCells);
            AddVectorObs(dangerLevelOfPositionsCells);

            freeBreakableObstructedCells.Clear();
            positionAgentCells.Clear();
            positionEnemyCells.Clear();
            dangerLevelOfPositionsCells.Clear();
        }
        else if (myGridViewType == GridViewType.GVT_BinaryDecimal)
        {
            for (int y = grid.GetGridSizeY() - 1; y >= 0; --y)
            {
                for (int x = 0; x < grid.GetGridSizeX(); ++x)
                {
                    BinaryNode node          = grid.NodeFromPos(x, y);
                    StateType  nodeStateType = grid.adjustAgentStateTypeForBinaryNode(node, playerNumber);

                    string cellString = StateTypeExtension.getIntBinaryString(nodeStateType);
                    int    cell       = Convert.ToInt32(cellString);

                    AddVectorObs(cell);
                }
            }
        }
        else if (myGridViewType == GridViewType.GVT_BinaryNormalized)
        {
            for (int y = grid.GetGridSizeY() - 1; y >= 0; --y)
            {
                for (int x = 0; x < grid.GetGridSizeX(); ++x)
                {
                    BinaryNode node          = grid.NodeFromPos(x, y);
                    StateType  nodeStateType = grid.adjustAgentStateTypeForBinaryNode(node, playerNumber);

                    float cell = StateTypeExtension.normalizeBinaryFlag(nodeStateType);
                    AddVectorObs(cell);
                }
            }
        }
        else if (myGridViewType == GridViewType.GVT_ZeroOrOneForeachStateType)
        {
            List <float> freeCells          = new List <float>();
            List <float> destructibleCells  = new List <float>();
            List <float> positionAgentCells = new List <float>();
            List <float> positionEnemyCells = new List <float>();
            List <float> bombCells          = new List <float>();
            List <float> dangerCells        = new List <float>();
            List <float> fireCells          = new List <float>();

            for (int y = grid.GetGridSizeY() - 1; y >= 0; --y)
            {
                for (int x = 0; x < grid.GetGridSizeX(); ++x)
                {
                    BinaryNode node          = grid.NodeFromPos(x, y);
                    StateType  nodeStateType = grid.adjustAgentStateTypeForBinaryNode(node, playerNumber);

                    freeCells.Add(node.getFreeCell());

                    int hasThis = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_Block) ? 1 : 0;
                    destructibleCells.Add(hasThis);

                    hasThis = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_Agent) ? 1 : 0;
                    positionAgentCells.Add(hasThis);

                    hasThis = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_EnemyAgent) ? 1 : 0;
                    positionEnemyCells.Add(hasThis);

                    hasThis = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_Bomb) ? 1 : 0;
                    bombCells.Add(hasThis);

                    hasThis = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_Danger) ? 1 : 0;
                    dangerCells.Add(hasThis);

                    hasThis = StateTypeExtension.stateTypeHasFlag(nodeStateType, StateType.ST_Fire) ? 1 : 0;
                    fireCells.Add(hasThis);
                }
            }

            AddVectorObs(freeCells);
            AddVectorObs(destructibleCells);
            AddVectorObs(positionAgentCells);
            AddVectorObs(positionEnemyCells);
            AddVectorObs(bombCells);
            AddVectorObs(dangerCells);
            AddVectorObs(fireCells);

            freeCells.Clear();
            destructibleCells.Clear();
            positionAgentCells.Clear();
            positionEnemyCells.Clear();
            bombCells.Clear();
            dangerCells.Clear();
            fireCells.Clear();
        }
    }
コード例 #8
0
ファイル: BinaryNode.cs プロジェクト: MeLL-UFF/pip
    public string getStringBinaryArray()
    {
        string s = StateTypeExtension.getIntBinaryString(binary);

        return(s);
    }