public void LoadLevel(String path) { this.initialZhedBoard = new ZhedBoard(path); ResetLevel(); // Update Camera GameObject.Find("Main Camera").transform.position = new Vector3(0, zhedBoard.height, -zhedBoard.height / 5.0f); }
public void LoadLevel(ZhedBoard board) { this.initialZhedBoard = new ZhedBoard(board); ResetLevel(); //GameObject.Find("Main Camera").transform.position = new Vector3(0, zhedBoard.height, -zhedBoard.height / 5.0f); }
public void Play(Coords coords, Func <Coords, Coords> moveFunction) { if (gameOver) { return; } if (!this.zhedBoard.ValidMove(coords)) { Debug.Log("Invalid move: " + coords); return; } if (this.coolGraphics) { TileController tile = this.valueTiles[coords].GetComponent <TileController>(); Coords currentCoords = tile.coords; Destroy(tile.gameObject); StartCoroutine(MakeUsedTile(currentCoords, 0)); for (int tileValue = tile.tileValue, numUsedTiles = 1; tileValue > 0; tileValue--, numUsedTiles++) { currentCoords = moveFunction(currentCoords); if (!zhedBoard.inbounds(currentCoords)) { break; } switch (zhedBoard.TileValue(currentCoords)) { case ZhedBoard.EMPTY_TILE: StartCoroutine(MakeUsedTile(currentCoords, numUsedTiles * SPAWN_DELAY_SECS)); break; case ZhedBoard.FINISH_TILE: StartCoroutine(MakeWinnerTile(currentCoords, numUsedTiles * SPAWN_DELAY_SECS)); break; default: tileValue++; numUsedTiles--; break; } } } this.zhedBoard = ZhedBoard.SpreadTile(this.zhedBoard, coords, moveFunction); if (this.Winner()) { youWin.SetActive(true); youLose.SetActive(false); gameOver = true; } else if (this.Loser()) { youWin.SetActive(false); youLose.SetActive(true); gameOver = true; } }
public void ResetLevel() { if (this.initialZhedBoard == null) { return; } this.zhedBoard = this.initialZhedBoard; if (transform.Find("Board") != null) { Destroy(transform.Find("Board").gameObject); } this.board = new GameObject("Board"); this.board.transform.parent = this.gameObject.transform; this.gameOver = false; this.valueTiles = new Dictionary <Coords, GameObject>(); this.finishTiles = new Dictionary <Coords, GameObject>(); for (int y = 0; y < zhedBoard.height; y++) { for (int x = 0; x < zhedBoard.width; x++) { MakeTile(new Coords(x, y), emptyTilePrefab, Color.white); } } if (this.coolGraphics) { foreach (int[] tile in zhedBoard.GetValueTiles()) { Coords coords = new Coords(tile[0], tile[1]); GameObject valueTileObject = MakeTile(coords, valueTilePrefab, BoardTheme.idleColor); valueTileObject.GetComponent <TileController>().SetTileInfo(coords, tile[2]); this.valueTiles.Add(coords, valueTileObject); } foreach (int[] tile in zhedBoard.GetFinishTiles()) { Coords coords = new Coords(tile[0], tile[1]); this.finishTiles.Add(coords, MakeTile(coords, finishTilePrefab, Color.white)); } } }
public override void OnActionReceived(float[] vectorAction) { ZhedBoard board = gameManager.zhedBoard; if (board == null) { return; } //List<Coords> tiles = this.board.GetValueTilesCoords(); //if (tiles.Count == 0) // return; int direction = Mathf.FloorToInt(vectorAction[0]); Coords move = ToCoords(Mathf.FloorToInt(vectorAction[1])); // Coords move = new Coords(Mathf.FloorToInt(vectorAction[1]), Mathf.FloorToInt(vectorAction[2])); this.transform.position = this.gameManager.TilePos(move) + new Vector3(0, this.transform.position.y, 0); if (!board.ValidMove(move)) { // if (board.ValidMove(Coords.MoveUp(move)) || // board.ValidMove(Coords.MoveDown(move)) || // board.ValidMove(Coords.MoveLeft(move)) || // board.ValidMove(Coords.MoveRight(move))) // { // AddReward(this.moveMissReward / 2f); // } AddReward(this.moveMissReward); this.stats.OnMiss(); return; } else { this.stats.OnHit(); AddReward(this.moveHitReward); } switch (direction) { case 0: gameManager.Play(move, Coords.MoveUp); break; case 1: gameManager.Play(move, Coords.MoveLeft); break; case 2: gameManager.Play(move, Coords.MoveDown); break; case 3: gameManager.Play(move, Coords.MoveRight); break; default: Debug.LogError("Error: " + direction + " is not a valid dir"); break; } if (gameManager.Loser()) { this.SetColor(Color.red); AddReward(this.lossReward);// * Mathf.Max(0.5f, this.stats.MissRatio())); this.stats.OnLoss(); EndEpisode(); } else if (gameManager.Winner()) { this.SetColor(Color.green); AddReward(this.winReward); this.stats.OnWin(); EndEpisode(); } else if (board.ValidMove(move)) { // AddReward(gameManager.zhedBoard.getBoardTotalMaxValue() - ZhedSolver.Solver.Heuristic2(gameManager.zhedBoard) * 0.0075f); // AddReward(gameManager.zhedBoard.getBoardMaxValue() * this.moveValueRewardMultiplier); } }