public void OnTriggerEnter(Collider other) { if (other.tag == "Player") { isActive = true; if (isActive == false) { currentState = tileState.eIdle; } else { currentState = tileState.eActive; } if (gameObject.GetComponent <PulseTile>().m_levelVal == 0) { currentState = tileState.eWrong; } else { game.counter++; } StateManager(); game.Progression(); } }
//Animate to the desired position private void AnimateToDesired() { //If not animating already, set state to animating and store start info if (state != tileState.animating) { state = tileState.animating; animStartPosition = transform.position; animStartTime = Time.time; startToDesired = desiredLocation - animStartPosition;//Vector from start pos to desired for reference during anim } //Calculate move speed for this frame, smooth step makes it ease in and out float moveSpeed = Mathf.SmoothStep(0, startToDesired.magnitude, (Time.time - animStartTime) / 0.5f); //Calculate future position based on move speed Vector3 futurePos = transform.position + (startToDesired.normalized * moveSpeed); //If the future position will go past the desired location or is exactly on, end animation if (Vector3.Dot(desiredLocation - futurePos, startToDesired) < 0 || futurePos == desiredLocation) { transform.position = desiredLocation; //Snap position to desired state = tileState.idle; //Change state from animating subtractNumbers(); //Subtract numbers with other tile if necessary } //Otherwise, change position as usual else { transform.position = futurePos; } }
public void GenerateRessource() { this.state = tileState.HARVESTABLE; Transform res = Instantiate(pickablePrefab, Vector3.zero, Quaternion.identity); res.GetComponent <PickableBehavior>().Init(this.posX, this.posY, RandomResType()); }
public Tile(float x, float y, float width, float height, tileState state) { shape = new RectangleShape(new Vector2f(width, height)); shape.Position = new Vector2f(x, y); shape.OutlineThickness = 1; shape.OutlineColor = Color.White; SetState(state); }
void Explore(bool bStartingTile = false) { // set variables this.exploration = 1.0f; this.state = tileState.IDLE; this.ressourceSpawnTime = GetSpawnTime(); GameObject.Find("Board").GetComponent <BoardBehavior>().bExploring = false; // update type if (bStartingTile) { this.type = tileType.PLAIN; } else { this.type = getRandomType(); this.progressBar.gameObject.SetActive(false); } // update material switch (this.type) { case tileType.FOREST: this.GetComponent <Renderer>().material = matForest; break; case tileType.HILL: this.GetComponent <Renderer>().material = matHill; break; case tileType.ROCKY: this.GetComponent <Renderer>().material = matRocky; break; case tileType.MOUNTAIN: this.GetComponent <Renderer>().material = matMountain; break; case tileType.PLAIN: this.GetComponent <Renderer>().material = matPlain; break; default: this.GetComponent <Renderer>().material = matUnexplored; break; } // create new neighbor if necessary foreach (location loc in location.GetValues(typeof(location))) { int x = GetNeighborX(loc); int y = GetNeighborY(loc); if (GameObject.Find("Tile_" + x + "_" + y) == null) { GameObject.Find("Board").GetComponent <BoardBehavior>().MakeTile(x, y); } } }
public void rotate180() { string [,] tmp = null; tmp = flip(FLIP_HORIZONTAL); tmp = flip(FLIP_VERTICAL, tmp); currentLines = tmp; currentState = tileState.rot180; }
private void Select() { if (currState == tileState.randomizing) { if (globalLastTileSelected != null) { ResolveDeselect(); } } //this tile has already been selected else if (currState == tileState.selected) { print("already Selected: " + numInChain); if (nextSelected != null) { DeselectChainForwards(nextSelected); globalLastTileSelected = this; } } //no chain has begun else if (globalLastTileSelected == null) { currState = tileState.selected; render.color = selectedColor; numInChain = 1; //print("new global tile: " + numInChain); globalLastTileSelected = gameObject.GetComponent <BoardTile>(); AudioManager.instance.PlayPitch("Select", 1f); } //chain has begun and render matches else if (globalLastTileSelected.render.sprite == render.sprite) { currState = tileState.selected; render.color = selectedColor; //set this local tiles previous previousSelected = globalLastTileSelected; //increment numInChain numInChain = previousSelected.numInChain + 1; //set global last tile selected tot his globalLastTileSelected = gameObject.GetComponent <BoardTile>(); //set local previous's next to this previousSelected.nextSelected = globalLastTileSelected; AudioManager.instance.PlayPitch("Select", 0.8f + 0.2f * numInChain); //print("new tile to chain: " + numInChain); } //chain has begun but render does not match else { ResolveDeselect(); } //SFXManager.instance.PlaySFX(Clip.Select); }
private void SetRandomizing(float time) { //print("Set rerolling: " + numInChain + " timer:" + time); numInChain = 0; currState = tileState.randomizing; randomizingTimer = time; render.color = new Color(1f, 1f, 1f, 0f); if (explosion) { GameObject exploder = ((Transform)Instantiate(explosion, this.transform.position, this.transform.rotation)).gameObject; Destroy(exploder, 2.0f); } }
public void flipRot(int flipType, int rotateAmount) { string [,] tmp = null; tmp = rotate(rotateAmount); tmp = flip(flipType, tmp); currentLines = tmp; if (flipType == FLIP_HORIZONTAL) { if (rotateAmount == 90) currentState = tileState.flipHorRot90; if (rotateAmount == 270) currentState = tileState.flipHorRot270; } else { if (rotateAmount == 90) currentState = tileState.flipVerRot90; if (rotateAmount == 270) currentState = tileState.flipVerRot270; } }
/// <summary> /// Count how many pieces of the color are on the board /// </summary> /// <param name="tileColor">color of the pieces</param> /// <returns></returns> private int calculateScore(tileState tileColor) { int score = 0; for (int i = 0; i < BOARDSIZE; i++) { for (int j = 0; j < BOARDSIZE; j++) { if (board[i, j] == tileColor) { score++; } } } return(score); }
public void SetState(tileState state) { this.state = state; switch (this.state) { case tileState.empty: shape.FillColor = Color.Black; break; case tileState.flooded: shape.FillColor = Color.Red; break; case tileState.wall: shape.FillColor = Color.White; break; } }
//Move the tile on the grid based on its future coords from swiping, returns whether the tile moved public bool MoveTile() { state = tileState.idle;//Reset state to idle //Whether tile should move bool moving = (futureX != xPos || futureY != yPos); //If should move, set coords to new ones if (moving) { xPos = futureX; yPos = futureY; } //Set new desired location to animate to based on new coords desiredLocation = GetModifiedDesired(); return(moving);//True if tile moved, false if didn't, BM can use to determine if a move should be added to counter }
// Use this for initialization void Start() { state = tileState.idle;//Default state is idle //GameObject spriteObject = transform.Find("Sprite").gameObject;//Get child with sprite for resizing object to fit grid transform.position = GetModifiedDesired(); //Set position to appropriate area desiredLocation = transform.position; //Desired location is same as pos by default if (type != tileType.gray) { numberText = GetComponentInChildren <TextMesh>();//Get text component for number from child //Set up number text to display right number and scale correctly so it doesn't get stretched numberText.text = number.ToString(); numberText.gameObject.transform.localScale *= transform.Find("Sprite").localScale.x; } }
public void setTileState(tileState state) { switch (state) { case tileState.initial: reset(); break; case tileState.rot90: rotate90(); break; case tileState.rot180: rotate180(); break; case tileState.rot270: rotate270(); break; case tileState.fliphor: flipHor(); break; case tileState.flipver: flipVer(); break; } currentState = state; }
public void setTileState(int state) { switch (state) { case 0: reset(); break; case 1: rotate90(); break; case 2: rotate180(); break; case 3: rotate270(); break; case 4: flipHor(); break; case 5: flipVer(); break; case 6: case 9: flipRot(FLIP_HORIZONTAL, 90); break; case 7: case 8: flipRot(FLIP_VERTICAL, 90); break; } currentState = (tileState)state; }
void OnMouseOver() { // tile mouse hover effect GetComponent <Renderer>().material.SetFloat("_Metallic", 0.9f); // click on tile stuff if (Input.GetMouseButtonDown(0)) { if (this.type == tileType.UNEXPLORED) { GameObject board = GameObject.Find("Board"); if (this.state != tileState.EXPLORING && !board.GetComponent <BoardBehavior>().bExploring) { board.GetComponent <BoardBehavior>().bExploring = true; this.state = tileState.EXPLORING; } } } }
void Update() { mouseDown = Input.GetMouseButton(0); timeLeft = bmScript.timeRemaining; //if time is up and there are still some tiles highlighted, deselect them if (timeLeft == 0) { SetDeselected(); } if (currState == tileState.randomizing) { if (randomizingTimer < 1.1 && spawnEmitter && !emitterStarted) { GameObject emitter = ((Transform)Instantiate(spawnEmitter, this.transform.position, this.transform.rotation)).gameObject; Destroy(emitter, 2f); emitterStarted = true; } if (randomizingTimer > 0) { randomizingTimer -= Time.deltaTime; } else { //Debug.Log("Tile Timer finished"); SetDeselected(); randomizingTimer = 0.0f; // lock the timer so it doesn't turn negative currState = tileState.neutral; RandomizeSprite(); emitterStarted = false; } } if (!mouseDown && (globalLastTileSelected == this) && BoardManager.instance.IsActive) { ResolveDeselect(); } }
//Move the tile on the grid based on keyboard input, DELETE THIS EVENTUALLY public bool MoveTile(int xChange, int yChange) { futureX = xPos + xChange; futureY = yPos + yChange; tile otherTile; for (int i = 0; i < BM.Tiles.Count; i++) { otherTile = BM.Tiles[i].GetComponent <tile>(); if ((otherTile.futureX == futureX && otherTile.futureY == futureY) && otherTile.type != type) { futureX = xPos; futureY = yPos; return(false); } } state = tileState.idle; return(MoveTile()); }
public int getTileNeighbour(Vector tilePosition) { int neighbour = 0; int x = tilePosition.X; int y = tilePosition.Y; CompanyType com = getTile(tilePosition).Company; tileState state = getTile(tilePosition).State; if (state == tileState.UNSET) { return(-1); } Tile tile; if (x - 1 >= 0) { tile = tiles[x - 1, y]; state = tile.State; if (state != tileState.UNSET) { if (tile.Company == com) { neighbour |= 8; } } } if (x + 1 < 12) { tile = tiles[x + 1, y]; state = tile.State; if (state != tileState.UNSET) { if (tile.Company == com) { neighbour |= 2; } } } if (y - 1 >= 0) { tile = tiles[x, y - 1]; state = tile.State; if (state != tileState.UNSET) { if (tile.Company == com) { neighbour |= 1; } } } if (y + 1 < 9) { tile = tiles[x, y + 1]; state = tile.State; if (state != tileState.UNSET) { if (tile.Company == com) { neighbour |= 4; } } } return(neighbour); }
public void flipVer() { currentLines = flip(FLIP_VERTICAL); currentState = tileState.flipver; }
//Partially slide tile to indicate swipe direction public void PartialSlide(Vector2 swipeVector) { //If currently animating, ignore swipes until done if (state == tileState.animating || type == tileType.gray) { return; } state = tileState.swiping;//Set state to swiping //Reset future coords, modify them as needed futureX = xPos; futureY = yPos; //If swipe vector is longer horiz than vert and swipe wasn't being swiped vertically earlier if (BM.SwipeDir == SwipeDirection.horizontal) { //Determine if swipe is right or left if (swipeVector.x > 0) { futureX += 1; } else { futureX -= 1; } } //If swipe vector is vert and wasn't being swiped horiz earlier else if (BM.SwipeDir == SwipeDirection.vertical) { //Determine if swipe is up or down if (swipeVector.y > 0) { futureY += 1; } else { futureY -= 1; } } //Other tile to check against tile otherTile; //Check if pushing against a tile of a different type, don't move if so for (int i = 0; i < BM.Tiles.Count; i++) { otherTile = BM.Tiles[i].GetComponent <tile>();//Get other tile from list //If other tile is a different type and has same future coords that means we are pushing into it and shouldn't combine, return early and reset future coords if (otherTile.index != index && otherTile.type != type && otherTile.futureX == futureX && otherTile.futureY == futureY && otherTile.state == tileState.idle) { futureX = xPos; futureY = yPos; state = tileState.idle; return; } } swipeVector /= Screen.dpi; //Convert swipe vector from pixels to world units for position Vector3 newPos = GetModifiedDesired(); //Set new position to position of grid tile is currently at, then modify from there //If future x coords are different and are within bounds of grid, modify x pos based on swipe vector if (futureX != xPos && futureX >= 0 && futureX < BM.BoardWidth) { newPos.x += Mathf.Clamp(swipeVector.x, -(0.85f * BM.TileDist.x), (0.85f * BM.TileDist.x)); } //If y coords are different and within bounds, modify y pos else if (futureY != yPos && futureY >= 0 && futureY < BM.BoardHeight) { newPos.y += Mathf.Clamp(swipeVector.y, -(0.85f * BM.TileDist.y), (0.85f * BM.TileDist.y)); } //If neither, reset state and return else { futureX = xPos; futureY = yPos; state = tileState.idle; return; } transform.position = newPos;//Set position to newly calculated swipe position //If the swipe is less than 1/5 of distance to next, reset future coords so that on release tiles will slide back into place rather than moving if (Mathf.Abs(swipeVector.x) < BM.TileDist.x * 0.2f && Mathf.Abs(swipeVector.y) < BM.TileDist.y * 0.2f) { futureX = xPos; futureY = yPos; } }
public void rotate270() { currentLines = rotate(270); currentState = tileState.rot270; }
public void flipHor() { currentLines = flip(FLIP_HORIZONTAL); currentState = tileState.fliphor; }
public void rotate90() { currentLines = rotate(90); currentState = tileState.rot90; }
// Use this for initialization void Start() { currState = tileState.unpowered; }
public Tile(tileState tileState) { state = tileState; }
public void reset() { currentLines = originalLines; currentState = tileState.initial; }
private void SetDeselected() { numInChain = 0; currState = tileState.neutral; render.color = Color.white; }
/// <summary> /// Evaluation function /// based on https://kartikkukreja.wordpress.com/2013/03/30/heuristic-function-for-reversiothello/ /// The evaluation uses pieces differences, frontier pieces, position of the pieces, corner occupancy, corner closeness and mobility /// Pieces differences: /// based on our score and opponent score /// /// Frontier pieces: /// The more frontier pieces (pieces wich have an empty neighbor) we have, those pieces have more chances to get taken by the opponent /// Stability calculation is very heavy so this is a simple replacement to get a light approximation of stability /// /// Pieces position: /// Positions of the pieces on the board. (To avoid giving strategical positions to opponent and take them if given) /// /// Corner occupancy: /// Corners are very strong positions. So the score of the board takes in count who has corners. /// This could be put in the weight array but the corners scores would have to be way higher. /// /// Corner closeness: /// To avoid giving corners to opponent we check who has pieces in the direct neighborhood of corners. /// /// Mobility: /// Number of possible moves for us and the opponent so if we can make the opponent pass, the board have a better score /// /// </summary> /// <param name="whiteTurn">is white playing</param> /// <returns>double score of the board</returns> private double eval(bool whiteTurn) { int myTiles; int oppTiles; tileState myColor = whiteTurn ? tileState.WHITE : tileState.BLACK; tileState oppColor = !whiteTurn ? tileState.WHITE : tileState.BLACK; // ----------------------------------------------------- // Piece difference, frontier pieces and position values // ----------------------------------------------------- double coinParity = 0; double frontierDisk = 0; int positionScore = 0; int myFrontTiles = 0; int oppFrontTiles = 0; int x; int y; myTiles = 0; oppTiles = 0; for (int i = 0; i < BOARDSIZE; i++) { for (int j = 0; j < BOARDSIZE; j++) { // piece number and position value if (board[i, j] == myColor) { myTiles++; positionScore += weights[i, j]; } else if (board[i, j] == oppColor) { oppTiles++; positionScore -= weights[i, j]; } // frontier pieces if (board[i, j] != tileState.EMPTY) { for (int k = 0; k < 8; k++) { x = i + X1[k]; y = j + Y1[k]; if (x >= 0 && x < BOARDSIZE && y >= 0 && y < BOARDSIZE && board[x, y] == tileState.EMPTY) { if (board[i, j] == myColor) { myFrontTiles++; } else { oppFrontTiles++; } break; } } } } } // Final values for coinParity and frontierDisk if (myTiles > oppTiles) { coinParity = (100.0 * myTiles) / (myTiles + oppTiles); } else if (myTiles < oppTiles) { coinParity = -(100.0 * oppTiles) / (myTiles + oppTiles); } else { coinParity = 0; } if (myFrontTiles > oppFrontTiles) { frontierDisk = -(100.0 * myFrontTiles) / (myFrontTiles + oppFrontTiles); } else if (myFrontTiles < oppFrontTiles) { frontierDisk = (100.0 * oppFrontTiles) / (myFrontTiles + oppFrontTiles); } else { frontierDisk = 0; } // ---------------- // Corner occupancy // ---------------- double cornerOccupancy = 0; myTiles = 0; oppTiles = 0; // check each corners if (board[0, 0] == myColor) { myTiles++; } else if (board[0, 0] == oppColor) { oppTiles++; } if (board[0, 7] == myColor) { myTiles++; } else if (board[0, 7] == oppColor) { oppTiles++; } if (board[7, 0] == myColor) { myTiles++; } else if (board[7, 0] == oppColor) { oppTiles++; } if (board[7, 7] == myColor) { myTiles++; } else if (board[7, 7] == oppColor) { oppTiles++; } // final value for corner occupancy cornerOccupancy = 25 * (myTiles - oppTiles); // ---------------- // Corner closeness // ---------------- double cornerCloseness = 0; myTiles = 0; oppTiles = 0; // count the number of pieces close to each corner if corner is empty (to see if you give the opponent the corner) if (board[0, 0] == tileState.EMPTY) { if (board[0, 1] == myColor) { myTiles++; } else if (board[0, 1] == oppColor) { oppTiles++; } if (board[1, 1] == myColor) { myTiles++; } else if (board[1, 1] == oppColor) { oppTiles++; } if (board[1, 0] == myColor) { myTiles++; } else if (board[1, 0] == oppColor) { oppTiles++; } } if (board[0, 7] == tileState.EMPTY) { if (board[0, 6] == myColor) { myTiles++; } else if (board[0, 6] == oppColor) { oppTiles++; } if (board[1, 6] == myColor) { myTiles++; } else if (board[1, 6] == oppColor) { oppTiles++; } if (board[6, 0] == myColor) { myTiles++; } else if (board[6, 0] == oppColor) { oppTiles++; } } if (board[7, 0] == tileState.EMPTY) { if (board[7, 1] == myColor) { myTiles++; } else if (board[7, 1] == oppColor) { oppTiles++; } if (board[6, 1] == myColor) { myTiles++; } else if (board[6, 1] == oppColor) { oppTiles++; } if (board[6, 0] == myColor) { myTiles++; } else if (board[6, 0] == oppColor) { oppTiles++; } } if (board[7, 7] == tileState.EMPTY) { if (board[6, 7] == myColor) { myTiles++; } else if (board[6, 7] == oppColor) { oppTiles++; } if (board[6, 6] == myColor) { myTiles++; } else if (board[6, 6] == oppColor) { oppTiles++; } if (board[7, 6] == myColor) { myTiles++; } else if (board[7, 6] == oppColor) { oppTiles++; } } cornerCloseness = -12.5 * (myTiles - oppTiles); // -------- // Mobility // -------- double mobility = 0; possibleMoves(whiteTurn); myTiles = canMove.Count; possibleMoves(!whiteTurn); oppTiles = canMove.Count; if (myTiles > oppTiles) { mobility = (100.0 * myTiles) / (myTiles + oppTiles); } else if (myTiles < oppTiles) { mobility = -(100.0 * oppTiles) / (myTiles + oppTiles); } else { mobility = 0; } // ----------- // Final score // ----------- return((10 * coinParity) + (801.724 * cornerOccupancy) + (382.026 * cornerCloseness) + (78.922 * mobility) + (74.396 * frontierDisk) + (10 * positionScore)); }
private void Start() { game = FindObjectOfType <Game1>(); currentState = tileState.eIdle; isActive = false; }
public tile(int _x, int _y) { x = _x; y = _y; tileContents = tileState.empty; }
public void Harvest() { this.state = tileState.IDLE; this.ressourceProgress = 0.0f; this.ressourceSpawnTime = GetSpawnTime(); }