public override void SetBoard(GridBasedBoard boardToSet) { for (int y = 0; y < board.GetLength(0); y++) { for (int x = 0; x < board.GetLength(1); x++) { if (boardToSet.GetCell(x, y) == 1) { //Show the counter object at this position and have it use the player one material board[y, x].SetActive(true); board[y, x].GetComponent <Renderer>().material = PlayerOneMat; } else if (boardToSet.GetCell(x, y) == 2) { //Show the counter object at this position and have it use the player two material board[y, x].SetActive(true); board[y, x].GetComponent <Renderer>().material = PlayerTwoMat; } else { //Hide the counter object at this position board[y, x].SetActive(false); } } } }
/// <summary> /// Hashes a <see cref="Board"/> object to a unique position in world space /// </summary> /// <param name="board">The board to hash</param> /// <returns>A <see cref="Vector3"/>, unique to the board state of hte board being hashed </returns> public Vector3 BoardToPosition(Board board) { GridBasedBoard gridBoard = (GridBasedBoard)board; Vector3 finalPos = Vector3.zero; if (spherePositions == null) { spherePositions = new Vector3[gridBoard.Width * gridBoard.Height]; #region Fibbonacci Sphere algorithm for (int i = 0; i < spherePositions.Length; i++) { int samples = spherePositions.Length; float offset = 2f / samples; float increment = Mathf.PI * (3 - Mathf.Sqrt(5)); float y = ((i * offset) - 1) + (offset / 2); float r = Mathf.Sqrt(1 - Mathf.Pow(y, 2)); float phi = ((i + 1) % samples) * increment; float x = Mathf.Cos(phi) * r; float z = Mathf.Sin(phi) * r; spherePositions[i] = new Vector3(x, y, z); } #endregion } for (int y = 0; y < gridBoard.Height; y++) { for (int x = 0; x < gridBoard.Width; x++) { finalPos += spherePositions[(x * gridBoard.Height) + y].normalized * gridBoard.GetCell(x, y); } } return(finalPos * NODE_SPACING); }
/// <summary> /// Sets the pieces of this board model to represent the given board state /// </summary> /// <param name="boardToSet">The board state to represent</param> public abstract void SetBoard(GridBasedBoard boardToSet);