Ejemplo n.º 1
0
    public CellData GetBestCell(CellData currentPosition, CellData goal, int range)
    {
        int             initialRange  = range;
        CellData        bestCell      = null;
        float           bestDistance  = float.MaxValue;
        CellData        cell          = goal;
        List <CellData> possibleCells = new List <CellData>();
        BoardData       boardData     = BoardData.Get();

        while (range > 0)
        {
            foreach (CellData c in cell.Expand())
            {
                if (!(c is null))
                {
                    if (c.IsEmpty() && bestDistance > CalculateEuclideanGeometry(currentPosition, goal))
                    {
                        bestCell     = c;
                        bestDistance = CalculateEuclideanGeometry(currentPosition, goal);
                    }

                    if (!possibleCells.Contains(c) && c.IsEmpty())
                    {
                        possibleCells.Add(c);
                    }
                }
            }

            if (!(bestCell is null) && cell != bestCell)
            {
                cell = bestCell;
                --range;
            }
Ejemplo n.º 2
0
    public CellData [] Expand()
    {
        CellData[] toReturn  = new CellData[8];
        BoardData  boardData = BoardData.Get();
        int        columns   = boardData.GetColumns();
        int        rows      = boardData.GetRows();

        //Up
        toReturn[0] = this.GetX() < (columns - 1) ? boardData.GetCellDataAt(this.GetX() + 1, this.GetY()) : null;
        //Right
        toReturn[1] = this.GetY() < (rows - 1)    ? boardData.GetCellDataAt(this.GetX(), this.GetY() + 1) : null;
        //Down
        toReturn[2] = this.GetX() > 0           ? boardData.GetCellDataAt(this.GetX() - 1, this.GetY()) : null;
        //Left
        toReturn[3] = this.GetY() > 0           ? boardData.GetCellDataAt(this.GetX(), this.GetY() - 1) : null;
        //UpRight
        toReturn[4] = !(toReturn[0] is null) && !(toReturn[1] is null) ? boardData.GetCellDataAt(this.GetX() + 1, this.GetY() + 1) : null;
        //RightDown
        toReturn[5] = !(toReturn[1] is null) && !(toReturn[2] is null) ? boardData.GetCellDataAt(this.GetX() - 1, this.GetY() + 1) : null;
        //LeftDown
        toReturn[6] = !(toReturn[2] is null) && !(toReturn[3] is null) ? boardData.GetCellDataAt(this.GetX() - 1, this.GetY() - 1) : null;
        //UpLeft
        toReturn[7] = !(toReturn[0] is null) && !(toReturn[3] is null) ? boardData.GetCellDataAt(this.GetX() + 1, this.GetY() - 1) : null;

        return(toReturn);
    }
Ejemplo n.º 3
0
    private Unit[] CreatePossibleUnits()
    {
        int maxX = (BoardData.Get().GetColumns() >> 1);
        int maxY = BoardData.Get().GetRows();
        int maxT = System.Enum.GetNames(typeof(UnitType)).Length;

        Unit        [] possibleUnits    = new Unit[maxX * maxY * maxT];
        UnitData    [] possibleUnitData = new UnitData[maxT];

        for (int t = 0; t < maxT; ++t)
        {
            possibleUnitData[t] = new UnitData((UnitType)t);
        }

        for (int x = 0; x < maxX; ++x)
        {
            for (int y = 0; y < maxY; ++y)
            {
                for (int t = 0; t < maxT; ++t)
                {
                    int index = t + (maxT * y) + (maxT * maxY * x);
                    possibleUnits[index] = new Unit(BoardData.Get().GetCellDataAt(x, y), possibleUnitData[t]);
                }
            }
        }

        return(possibleUnits);
    }
Ejemplo n.º 4
0
    void InterpretatePlayerFormation()
    {
        ArmyAction formation = GameController.Get().playerController.GetPlayerFormation();

        foreach (Unit unit in formation.GetUnits())
        {
            int cellDataRelativeX = unit.GetPosition().GetX();
            int cellDataRelativeY = unit.GetPosition().GetY();

            CellData relativeCellData      = BoardData.Get().GetCellDataAt(cellDataRelativeX, cellDataRelativeY);
            Vector3  cellDataWorldPosition = boardBehaviour.GetWorldPositionOfCell(relativeCellData);

            UnitType   AI_unitUnitType = unit.GetUnitData().GetType();
            GameObject AI_unit         = GameController.Get().unitsPool.GetUnitInstance(AI_unitUnitType);

            relativeCellData.SetEmpty(false);

            AI_unit.SetActive(true);

            Soldier  AI_unitSoldier = AI_unit.GetComponent <Soldier>();
            TeamData team           = GameController.Get().GetPlayerTeamData();

            AI_unitSoldier.SetUnitType(AI_unitUnitType);
            team.AddSoldier(AI_unitSoldier);
            AI_unitSoldier.SetTeam(team);
            AI_unitSoldier.SetUnit(new Unit(unit));
            AI_unitSoldier.Start();
            AI_unit.GetComponent <DraggeableUnit>().enabled = false;

            AI_unit.transform.position = new Vector3(cellDataWorldPosition.x, cellDataWorldPosition.y + 0.5f, cellDataWorldPosition.z);
        }
    }
Ejemplo n.º 5
0
    private void CreateFormationVariablesXml()
    {
        string UCB1XmlFilePath           = "Assets/XMLData/";
        string RegretMatchingXmlFilePath = "Assets/XMLData/";
        string formationVariablesPath    = "Assets/XMLData/";

        byte rows           = (byte)BoardData.Get().GetRows();
        byte columns        = (byte)BoardData.Get().GetColumns();
        byte maxUnitsInTeam = (byte)aiController.GetMaxUnitsInTeam();
        byte unitTypesCount = (byte)System.Enum.GetNames(typeof(UnitType)).Length;
        uint actionsCount   = aiController.GetPossibleActionsCount();

        UCB1XmlFilePath           += $"UCB1_{rows}x{columns}_{maxUnitsInTeam}_of_{unitTypesCount}_fake.xml";
        RegretMatchingXmlFilePath += $"RM_{rows}x{columns}_{maxUnitsInTeam}_of_{unitTypesCount}.xml";
        formationVariablesPath    += $"FormationVariables_{rows}x{columns}_{maxUnitsInTeam}_of_{unitTypesCount}.xml";

        formationVariablesXMLData = new XmlFormationVariables
                                    (
            rows,
            columns,
            maxUnitsInTeam,
            unitTypesCount,
            actionsCount,
            UCB1XmlFilePath,
            RegretMatchingXmlFilePath
                                    );

        XmlManaging.CreateFile <XmlFormationVariables>(formationVariablesXMLData, formationVariablesPath);
    }
Ejemplo n.º 6
0
    private void MoveRight(CellData currentPosition)
    {
        BoardData boardData   = BoardData.Get();
        CellData  desiredCell = boardData.GetCellDataAt(currentPosition.GetY(), currentPosition.GetX() + 1);

        MoveTo(desiredCell, currentPosition);
    }
Ejemplo n.º 7
0
    private void MoveDown(CellData currentPosition)
    {
        BoardData boardData   = BoardData.Get();
        CellData  desiredCell = boardData.GetCellDataAt(currentPosition.GetY() - 1, currentPosition.GetX());

        MoveTo(desiredCell, currentPosition);
    }
Ejemplo n.º 8
0
    private BigInteger CalculateCount()
    {
        uint size       = (uint)BoardData.Get().GetTotalCells() >> 1;
        uint typesCount = (uint)System.Enum.GetNames(typeof(UnitType)).Length;
        uint n          = size * typesCount;

        return((factorial(n)) / (factorial(n - (uint)maxUnits) * factorial((uint)maxUnits)) - factorial(typesCount));
    }
Ejemplo n.º 9
0
    public void OnStartBattle()
    {
        //-----------------------------------------------------------------------------------------------------------------------------------------------
        // FOR AUTOMATIC KNOWLEDGE
        if (currentGameMode == GameMode.AivsAi)
        {
            AIController.Get().DecideFormations();
        }
        //-----------------------------------------------------------------------------------------------------------------------------------------------
        callToEnd = false;

        // Center the camera in the board
        BoardData boardData = BoardData.Get();
        Vector3   boardCenterCellPosition = boardBehaviour.GetWorldPositionOfCell(boardData.GetBoardCenterCell());

        cameraBehaviour.CenterToPosition(boardCenterCellPosition);

        // Show the hiden cells
        ShowCells();

        uint j = 0;

        for (
            j = 0;
            j < AIController.Get().GetPossibleActions().GetCount() &&
            AIController.Get().GetPossibleActions().GetAt((uint)j) != playerController.GetPlayerFormation();
            ++j
            )
        {
            ;
        }

        playerController.GetPlayerFormation().Index = j;

        AIController.Get().OnBattleStart();


        for (int i = 0; i < AITeamData.GetSoldiers().Count; ++i)
        {
            playerTeamData.GetSoldiers()[i].ApplyBuff();
            AITeamData.GetSoldiers()[i].ApplyBuff();
        }

        foreach (Soldier soldier in playerTeamData.GetSoldiers())
        {
            soldier.SetReadyToFight(true);
        }
        foreach (Soldier soldier in AITeamData.GetSoldiers())
        {
            soldier.SetReadyToFight(true);
        }
    }
Ejemplo n.º 10
0
    public void OnPlayerDecideFormation()
    {
        playerController.ResetChoosenUnits();
        boardBehaviour.ResetCells();
        // Center the camera in the player board
        BoardData boardData = BoardData.Get();
        Vector3   playerCenterCellPosition = boardBehaviour.GetWorldPositionOfCell(boardData.GetPlayerCellsCenterCell());

        cameraBehaviour.CenterToPosition(playerCenterCellPosition);

        // Hide all cells but player's
        HideCells();
    }
Ejemplo n.º 11
0
    public static CellData operator --(CellData thisCell)
    {
        BoardData boardData = BoardData.Get();
        int       columns   = boardData.GetColumns();
        int       rows      = boardData.GetRows();
        int       newX      = thisCell.GetX();
        int       newY      = thisCell.GetY();

        --newY;
        if (newY < 0)
        {
            newY = rows - 1;
            --newX;
        }

        return(boardData.GetCellDataAt(newX, newY));
    }
Ejemplo n.º 12
0
    private void HideCells()
    {
        BoardData boardData  = BoardData.Get();
        int       maxColumns = boardData.GetColumns();
        int       maxRows    = boardData.GetRows();

        CellData firstNonPlayerCell = boardData.GetBoardCenterCell();
        CellData lastCellOnBoard    = boardData.GetCellDataAt(maxColumns - 1, maxRows - 1);

        --firstNonPlayerCell;

        while (firstNonPlayerCell != lastCellOnBoard)
        {
            firstNonPlayerCell.GetVisibleItem().Hide();
            ++firstNonPlayerCell;
        }

        lastCellOnBoard.GetVisibleItem().Hide();
    }
Ejemplo n.º 13
0
 public void CellDataInitializer(int x, int y) => cellData = BoardData.Get().GetCellDataAt(x, y);