示例#1
0
    public void NewGame()
    {
        //WorldConstants.CurrentDifficulty = difficulty;

        switch (WorldConstants.CurrentDifficulty)
        {
        case WorldConstants.Difficulties.Medium:
            World = new GridWorld(16);
            break;

        case WorldConstants.Difficulties.Expert:
            World = new GridWorld(21);
            break;

        case WorldConstants.Difficulties.Easy:
            World = new GridWorld(9);
            break;

        default:
            World = new GridWorld(9);
            break;
        }

        WorldConstants.World = World;
    }
示例#2
0
    void Awake()
    {
        var grid = gameObject.GetComponent <RectGrid>();
        var para = gameObject.GetComponent <Parallelepiped>();

        GridWorld.InitializePuzzle(grid, para);
    }
示例#3
0
    // Start is called before the first frame update
    IEnumerator Start()
    {
        boxHealthState = BoxHealthState.Healthy;
        if (boxOrigin == BoxOrigin.Instantiate)
        {
            boxOccupiedState = BoxOccupiedState.Unoccupied;
        }
        float heightToFallTo = BOX_Y;

        if (boxOrigin == BoxOrigin.Instantiate)
        {
            //Debug.Log("instantiated boxes");
            obstaclesInColumn = GridWorld.GetColumnObjects(transform.position);
            if (obstaclesInColumn.Count > 0)
            {
                //Debug.Log("obstacles count greater than 0! " + obstaclesInColumn[0].transform.name);
                Box boxObstacle = obstaclesInColumn[0].GetComponent <Box>();
                if (boxObstacle != null && boxObstacle.countDownS.Elapsed() < (0.9f * boxObstacle.HEALTH))
                {
                    heightToFallTo = BOX_Y + obstaclesInColumn[0].GetComponent <SpriteRenderer>().bounds.size.y;
                    //Debug.Log("!setting height of fall " + BOX_Y);
                }
            }

            Tween boxFallTween = transform.DOLocalMoveY(heightToFallTo, FALL_SPEED).SetSpeedBased().SetEase(Ease.InExpo);
            //yield return boxFallTween.WaitForPosition(0.8f);

            yield return(boxFallTween.WaitForCompletion());

            SoundManager.instance.PlaySingle(SoundManager.instance.crash, 0.2f);
            //OnComplete(()=>
            //{
            if (obstaclesInColumn.Count > 0)
            {
                //Debug.Log("obstacles count greater than 0!");
                Box boxObstacle = obstaclesInColumn[0].GetComponent <Box>();
                if (boxObstacle != null)
                {
                    Debug.Log("setting boxOnTop variable");
                    boxObstacle.boxOnTop = gameObject;
                }
            }

            if (boxOccupiedState == BoxOccupiedState.Unoccupied)
            {
                //only broadcast event if first box on ground
                if (heightToFallTo > -11.5f && heightToFallTo < -11f)
                {
                    OnBoxEmpty?.Invoke(gameObject);
                }
            }
        }

        CountDown();
        //StartCoroutine(CountDown());
        //});
        GridWorld.RegisterObstacle(transform, false);
        //Debug.Log("box LOC: " + GridWorld.GetSquare(transform.position)[0] + " : " + GridWorld.GetSquare(transform.position)[1]);
    }
示例#4
0
    private void Awake()//Ran once the program starts
    {
        instance = this;

        GameObject player2 = GameObject.Find("Lumberjack2");

        player2.SetActive(false);
        GameObject player3 = GameObject.Find("Lumberjack3");

        player3.SetActive(false);

        fNodeDiameter = fNodeRadius * 2;                                    //Double the radius to get diameter
        iGridSizeX    = Mathf.RoundToInt(vGridWorldSize.x / fNodeDiameter); //Divide the grids world co-ordinates by the diameter to get the size of the graph in array units.
        iGridSizeY    = Mathf.RoundToInt(vGridWorldSize.y / fNodeDiameter); //Divide the grids world co-ordinates by the diameter to get the size of the graph in array units.
        CreateGrid();                                                       //Draw the grid

        if (scenario == Scenario.Known && algorithm == Algorithm.AStar)
        {
            print("Scenario : " + scenario + ", Algorithm = " + algorithm);
            PathfindingA PAscript   = this.gameObject.AddComponent(typeof(PathfindingA)) as PathfindingA;
            GameObject   player     = GameObject.Find("Agent");
            Unit         unitScript = player.gameObject.AddComponent(typeof(Unit)) as Unit;
            unitScript.enabled = true;
            PAscript.enabled   = true;
        }
        else if (scenario == Scenario.Known && algorithm == Algorithm.Dijkstra)
        {
            print("Scenario : " + scenario + ", Algorithm = " + algorithm);
            Dijkstra     DIJscript          = this.gameObject.AddComponent(typeof(Dijkstra)) as Dijkstra;
            GameObject   player             = GameObject.Find("Agent");
            UnitDijkstra unitDijkstraScript = player.gameObject.AddComponent(typeof(UnitDijkstra)) as UnitDijkstra;
            unitDijkstraScript.enabled = true;
            DIJscript.enabled          = true;
        }
        else if (scenario == Scenario.Unknown && searchMode == SearchMode.CellByCell)
        {
            print("Scenario : " + scenario + ", Search Mode : " + searchMode + " , Algorithm = " + algorithm);
            GameObject        player           = GameObject.Find("Agent");
            UnitSearchUnkCell UnitSearchscript = player.gameObject.AddComponent(typeof(UnitSearchUnkCell)) as UnitSearchUnkCell;
            UnitSearchscript.enabled = true;
        }
        else if (scenario == Scenario.Unknown && searchMode == SearchMode.Randomly)
        {
            print("Scenario : " + scenario + ", Search Mode : " + searchMode + " , Algorithm = " + algorithm);

            GameObject player           = GameObject.Find("Agent");
            UnitRandom UnitRandomscript = player.gameObject.AddComponent(typeof(UnitRandom)) as UnitRandom;
            UnitRandomscript.enabled = true;
        }
        else if (scenario == Scenario.ThreeAgents)
        {
            player2.SetActive(true);
            player3.SetActive(true);

            print("Scenario : " + scenario + ", Algorithm = " + algorithm);
            ThreeAgents CompThreeAgents = this.gameObject.AddComponent(typeof(ThreeAgents)) as ThreeAgents;
            CompThreeAgents.enabled = true;
        }
    }
示例#5
0
        private const double GAMMA           = 0.99; // The value of gamma to use in the Q-Learning rule

        public QLearning(GridWorld gridWorld, Cell startingCell, Cell rewardCell)
        {
            this.currentCell = startingCell;
            this.rewardCell  = rewardCell;
            this.gridWorld   = gridWorld;

            this.qTable = new double[gridWorld.GetCells().GetLength(0), gridWorld.GetCells().GetLength(1), NUMBER_OF_MOVES];
        }
示例#6
0
 public MovingArea(GridWorld gridWorld, Position origin, int width, int height)
 {
     this.gridWorld = gridWorld;
     this.x         = origin.x - width / 2;
     this.y         = origin.y - height / 2;
     this.width     = width;
     this.height    = height;
 }
        private bool training = true; // boolean flag to indicate training versus testing

        #endregion Fields

        #region Constructors

        public QLearning(GridWorld gridWorld, Cell startingCell, Cell rewardCell)
        {
            this.currentCell = startingCell;
            this.rewardCell = rewardCell;
            this.gridWorld = gridWorld;

            this.qTable = new double[gridWorld.GetCells().GetLength(0),gridWorld.GetCells().GetLength(1),NUMBER_OF_MOVES];
        }
        public void RegionIndexesAndBorders1()
        {
            var topLeftCorner = new Vector { X = 1, Y = 1 };
            var bottomRightCorner = new Vector { X = 99, Y = 999 };
            var tileDimensions = new Vector { X = 10, Y = 10 };
            var world = new GridWorld(topLeftCorner, bottomRightCorner, tileDimensions, new MmoItemCache());

            RegionIndexesAndBorders(world);
        }
示例#9
0
 public InvalidCellPositionException(CellPosition position, GridWorld world)
     : base(position == null ? "Position is null." : String.Format(
                "Grid position ({0},{1}) is outside the bounds of ({2},{3})",
                position.x,
                position.z,
                world.width,
                world.length
                ))
 {
 }
示例#10
0
    private void Awake()//When the program starts
    {
        GameObject GameManager = GameObject.Find("GameManager");

        speed = GridWorld.instance.speed * 3;

        if (GameManager != null)
        {
            GridReference = GameManager.GetComponent <GridWorld>();
        }
    }
示例#11
0
 // Use this for initialization
 void Start()
 {
     //gameController = GameObject.Find("GameController").GetComponent<GameController>();
     cursorSelection = GameObject.Find("Cursor").GetComponent<CursorSelection>();
     grid = GameObject.Find("Grid").GetComponent<GridWorld>();
     gameController = GameObject.Find("GameController").GetComponent<GameController>();
     //gridTile = null;
     charStatus = null;
     charMove = null;
     calculateAttackRange = false;
 }
示例#12
0
        public static void Run()
        {
            var world    = new GridWorld();
            var policy   = new UniformRandomGridWorldPolicy();
            var rewarder = new NegativeAtNonTerminalStatesGridWorldRewarder();

            var gridValues = new GridWorldValueTable(world);

            gridValues.Evaluate(policy, rewarder);
            gridValues.Print();
        }
示例#13
0
        /// <summary>
        /// The tester.
        /// </summary>
        /// <param name="world">
        /// The world.
        /// </param>
        private static void RegionIndexesAndBorders(GridWorld world)
        {
            Region region;
            var    current = new Vector();

            for (current.X = world.Area.Min.X; current.X < world.Area.Max.X; current.X++)
            {
                for (current.Y = world.Area.Min.Y; current.Y < world.Area.Max.Y; current.Y++)
                {
                    Assert.IsNotNull(world.GetRegion(current), current.ToString());
                }
            }

            try
            {
                for (current.Y = world.Area.Min.Y; current.Y <= world.Area.Max.Y; current.Y += world.TileDimensions.Y)
                {
                    // current.Y = (float)Math.Round(current.Y, 2);
                    for (current.X = world.Area.Min.X; current.X <= world.Area.Max.X; current.X += world.TileDimensions.X)
                    {
                        // current.X = (float)Math.Round(current.X, 2);
                        Assert.IsNotNull(region = world.GetRegion(current), "null at {0}", current);
                        Assert.AreEqual(current, region.Coordinate, current.ToString());
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine(current);
                throw;
            }

            current.X = world.Area.Min.X - 1;
            Assert.IsNull(world.GetRegion(current));
            current.Y = world.Area.Min.Y - 1;
            Assert.IsNull(world.GetRegion(current));
            current.X = world.Area.Min.X;
            Assert.IsNull(world.GetRegion(current));

            current.Y = world.Area.Max.Y + 1;
            Assert.IsNull(world.GetRegion(current));
            current.X = world.Area.Max.X + 1;
            Assert.IsNull(world.GetRegion(current));
            current.Y = world.Area.Max.Y;
            Assert.IsNull(world.GetRegion(current));

            Assert.NotNull(world.GetRegion(world.Area.Min));
            Assert.NotNull(world.GetRegion(world.Area.Max));

            world.GetRegions(world.Area);
        }
示例#14
0
        public void RegionIndexesAndBorders5()
        {
            var topLeftCorner = new Vector {
                X = 0, Y = 0
            };
            var bottomRightCorner = new Vector {
                X = 100, Y = 100
            };
            var tileDimensions = new Vector {
                X = -1, Y = -1
            };
            var world = new GridWorld(topLeftCorner, bottomRightCorner, tileDimensions, new MmoItemCache());

            RegionIndexesAndBorders(world);
        }
示例#15
0
    void Awake()
    {
        /// We need to put this in Awake() because GridDwellers will try and place themselves on the
        /// grid with Start(), so the arrays that hold that data needs to be initialized before any
        /// Start() methods run.

        instance           = this;
        playerSideContents = new List <GridDweller> [width, length];
        enemySideContents  = new List <GridDweller> [width, length];
        for (uint x = 0; x < width; x++)
        {
            for (uint z = 0; z < length; z++)
            {
                playerSideContents[x, z] = new List <GridDweller>();
                enemySideContents[x, z]  = new List <GridDweller>();
            }
        }
    }
示例#16
0
        private LinkedList<Cell> visitedCells; // The set of visited cells in the grid simulation

        #endregion Fields

        #region Constructors

        public AStar(GridWorld gridWorld, Cell startingCell, Cell rewardCell)
        {
            visitedCells = new LinkedList<Cell>();
            unvisitedCells = new LinkedList<Cell>();
            bestPath = new LinkedList<Cell>();
            this.currentCell = startingCell;
            this.rewardCell = rewardCell;
            this.gridWorld = gridWorld;

            this.currentCell.SetHScore(GetHeuristicEstimate(this.currentCell, rewardCell));

            this.currentCell.SetGScore(0);

            double fScore = this.currentCell.GetGScore() + this.currentCell.GetHScore();

            this.currentCell.SetFScore(fScore);

            unvisitedCells.AddFirst(this.currentCell);
        }
示例#17
0
    void Start()
    {
        gridWorld = GridWorld.getInstance();
        allCells  = gridWorld.ListAllCells();
        foreach (CellPosition cell in allCells)
        {
            PhysicalCell physicalCell = new PhysicalCell();
            physicalCell.position = gridWorld.GetRealPosition(cell);
            Instantiate(cellPrefab, physicalCell.position);

            /*
             * if (optionalPlayerEffect != null) {
             * GameObject playerEffect = Instantiate(optionalPlayerEffect, physicalCell.position);
             * physicalCell.playerEffect = playerEffect.GetComponentInChildren<ParticleSystem>();
             * physicalCell.playerEffect.Stop();
             * }
             *
             * if (optionalEnemyEffect != null) {
             * GameObject enemyEffect = Instantiate(optionalEnemyEffect, physicalCell.position);
             * physicalCell.enemyEffect = enemyEffect.GetComponentInChildren<ParticleSystem>();
             * physicalCell.enemyEffect.Stop();
             * }
             */

            foreach (DwellerInfo info in dwellerInfoSet)
            {
                physicalCell.data.Add(info.type, new PhysicalCell.TypeSpecificData());

                if (info.optionalEffect != null)
                {
                    GameObject effect = Instantiate(info.optionalEffect, physicalCell.position);
                    physicalCell.data[info.type].effect = effect.GetComponentInChildren <ParticleSystem>();
                    physicalCell.data[info.type].effect.Stop();
                }
            }

            physicalCells.Add(physicalCell);
        }
    }
示例#18
0
    //fall from top of one box to the floor
    public void DropDown()
    {
        if (fallDownTween == null)
        {
            //remove from grid
            Debug.Log("remove from: " + transform.position);
            //Debug.DrawLine(transform.position, new Vector3(0f, 5f, 0f), Color.white, 2.5f);
            GridWorld.RegisterObstacle(transform, true);
            fallDownTween = transform.DOLocalMoveY(BOX_Y, FALL_SPEED).SetSpeedBased().SetEase(Ease.InExpo).SetDelay(.2f);


            fallDownTween.OnComplete(() =>
            {
                //add to grid
                //Debug.Log("add to: " + transform.position);
                //Debug.DrawLine(transform.position, new Vector3(0f, 5f, 0f), Color.white, 2.5f);
                GridWorld.RegisterObstacle(transform, false);
                SoundManager.instance.PlaySingle(SoundManager.instance.smallCrack, 0.25f);
                fallDownTween.Kill();
                fallDownTween = null;
            });
        }
    }
        public void GetRegionsExcept()
        {
            var topLeftCorner = new Vector { X = 1, Y = 1 };
            var bottomRightCorner = new Vector { X = 100, Y = 100 };
            var tileDimensions = new Vector { X = 10, Y = 10 };
            var world = new GridWorld(topLeftCorner, bottomRightCorner, tileDimensions, new MmoItemCache());

            var a = new BoundingBox { Min = new Vector { X = 5, Y = 5 }, Max = new Vector { X = 15, Y = 15 } };
            a = world.GetRegionAlignedBoundingBox(a);
            Assert.AreEqual(topLeftCorner, a.Min);
            Assert.AreEqual(tileDimensions * 2, a.Max);

            var b = new BoundingBox { Min = new Vector { X = 12, Y = 12 }, Max = new Vector { X = 22, Y = 22 } };
            b = world.GetRegionAlignedBoundingBox(b);
            Assert.AreEqual(tileDimensions + topLeftCorner, b.Min);
            Assert.AreEqual(tileDimensions * 3, b.Max);

            HashSet<Region> regionsA = world.GetRegions(a);
            Assert.AreEqual(4, regionsA.Count);
            HashSet<Region> regionsB = world.GetRegions(b);
            Assert.AreEqual(4, regionsB.Count);
            HashSet<Region> regions = world.GetRegionsExcept(a, b);
            Assert.AreEqual(3, regions.Count);
            Region region = world.GetRegion(topLeftCorner);
            Assert.IsTrue(regions.Contains(region));
            region = world.GetRegion(topLeftCorner + new Vector { X = world.TileDimensions.X });
            Assert.IsTrue(regions.Contains(region));
            region = world.GetRegion(topLeftCorner + new Vector { Y = world.TileDimensions.Y });
            Assert.IsTrue(regions.Contains(region));
            region = world.GetRegion(topLeftCorner + world.TileDimensions);
            Assert.IsFalse(regions.Contains(region));

            b = new BoundingBox { Min = new Vector { X = 30, Y = 30 }, Max = new Vector { X = 40, Y = 40 } };
            b = world.GetRegionAlignedBoundingBox(b);
            regions = world.GetRegionsExcept(a, b);
            Assert.AreEqual(4, regions.Count);
        }
        /// <summary>
        /// The tester.
        /// </summary>
        /// <param name="world">
        /// The world.
        /// </param>
        private static void RegionIndexesAndBorders(GridWorld world)
        {
            Region region;
            var current = new Vector();
            for (current.X = world.Area.Min.X; current.X < world.Area.Max.X; current.X++)
            {
                for (current.Y = world.Area.Min.Y; current.Y < world.Area.Max.Y; current.Y++)
                {
                    Assert.IsNotNull(world.GetRegion(current), current.ToString());
                }
            }

            try
            {
                for (current.Y = world.Area.Min.Y; current.Y <= world.Area.Max.Y; current.Y += world.TileDimensions.Y)
                {
                    // current.Y = (float)Math.Round(current.Y, 2);
                    for (current.X = world.Area.Min.X; current.X <= world.Area.Max.X; current.X += world.TileDimensions.X)
                    {
                        // current.X = (float)Math.Round(current.X, 2);
                        Assert.IsNotNull(region = world.GetRegion(current), "null at {0}", current);
                        Assert.AreEqual(current, region.Coordinate, current.ToString());
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine(current);
                throw;
            }

            current.X = world.Area.Min.X - 1;
            Assert.IsNull(world.GetRegion(current));
            current.Y = world.Area.Min.Y - 1;
            Assert.IsNull(world.GetRegion(current));
            current.X = world.Area.Min.X;
            Assert.IsNull(world.GetRegion(current));

            current.Y = world.Area.Max.Y + 1;
            Assert.IsNull(world.GetRegion(current));
            current.X = world.Area.Max.X + 1;
            Assert.IsNull(world.GetRegion(current));
            current.Y = world.Area.Max.Y;
            Assert.IsNull(world.GetRegion(current));

            Assert.NotNull(world.GetRegion(world.Area.Min));
            Assert.NotNull(world.GetRegion(world.Area.Max));

            world.GetRegions(world.Area);
        }
示例#21
0
    //int movePathCounter;
    // Use this for initialization
    void Start()
    {
        //gameController = GameObject.Find("GameController").GetComponent<GameController>();
        enemyAI = GameObject.Find("GameController").GetComponent<EnemyAIController>();
        charStat = gameObject.GetComponent<CharacterStatus>();
        gridWorld = GameObject.Find("Grid").GetComponent<GridWorld>();
        gameController = GameObject.Find("GameController").GetComponent<GameController>();
        //battleController = GameObject.Find("GameController").GetComponent<Battle>();

        curRow = startRow;
        curCol = startCol;
        moveCounter = charStat.GetMovementRange();
        target = null;
        //endTurn = false;
        performActions = false;
        hasMoved = false;
        finishedAction = false;
        targetFound = false;
        //prevRow = curRow;
        //prevCol = curCol;
        //grid = GameObject.Find("Grid").GetComponent<GridWorld>();
        //cursorMove = GameObject.Find("Cursor").GetComponent<CursorMovement>();
        //cursorSelection = GameObject.Find("Cursor").GetComponent<CursorSelection>();
        //charStats = this.GetComponent<CharacterStatus>();
        //moveConfirmMenu = GameObject.Find("Main Camera").GetComponent<MoveConfirmMenu>();
        //gameController = GameObject.Find("GameController").GetComponent<GameController>();
        //gridTile = null;
        //moveCounter = charStats.GetMovementRange();
        //showMoveCounterText = false;
        performMovement = false;
        //hasMoved = false;
        movePathCounter = 0;
        reassign = false;

        transform.position = gridWorld.row[startRow].column[startCol].transform.position;
    }
示例#22
0
 // Use this for initialization
 void Start()
 {
     cursorSel = GameObject.Find("Cursor").GetComponent<CursorSelection>();
     cursorMove = GameObject.Find("Cursor").GetComponent<CursorMovement>();
     gridWorld = GameObject.Find("Grid").GetComponent<GridWorld>();
     moveConfirmMenu = GameObject.Find("Main Camera").GetComponent<MoveConfirmMenu>();
     gameController = GameObject.Find("GameController").GetComponent<GameController>();
     battle = GameObject.Find("GameController").GetComponent<Battle>();
     //actionMenuOptionsBool = new bool[actionMenuOptions.Length];
     selectIndex = 0;
     showCharActionMenu = false;
     waitChoosen = false;
     //selectedCharacterName = "";
 }