public void CastRay() { if (PositionPiece.isMoving) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity, LayerMask.GetMask("Stuff")); if (hit.collider != null) { if (selected) { selected.graphics[0].color = Color.white; } selected = hit.collider.GetComponent <PositionPiece>(); hit.collider.GetComponent <PositionPiece>().graphics[0].color = Color.blue; } else { if (selected) { selected.graphics[0].color = Color.white; } selected = null; } }
public string GetBoardState(PositionPiece color) { char[] boardState = new char[19 * 19]; char available = '0'; char unavailable = '1'; char black = '2'; char white = '3'; GoPosition[] adjacentPositions = new GoPosition[4]; foreach (var position in positions) { char state = available; if (position.piece == PositionPiece.Empty) { state = unavailable; if (lastLiberties.ContainsKey(position)) { GetAdjacentPositions(position, adjacentPositions); foreach (var adjacent in adjacentPositions) { if ( adjacent.piece == PositionPiece.Empty || (adjacent.piece == color && !adjacent.group.hasManyLiberties) || (adjacent.piece != color && adjacent.group.hasManyLiberties)) { state = available; break; } } } else if (falseEyes.Contains(position)) { GetAdjacentPositions(position, adjacentPositions); if (adjacentPositions[0].piece != color) { state = available; } } else { state = available; } } else { state = position.piece == PositionPiece.Black ? black : white; } SetCharValue(state, position.rowIndex, position.colIndex, boardState); } return new String(boardState); }
public void SnapPieceToGrid(GridCell cell, PositionPiece piece) { List <(int, int)> positionsToOccupy = new List <(int, int)>(); (int, int)positions = (cell.line, cell.column); for (int i = 0; i < piece.matrix.Count; i++) { positions.Item1 = i + cell.line; for (int j = 0; j < piece.matrix[i].column.Count; j++) { if (piece.matrix[i].column[j] == 0) { continue; } positions.Item2 = j + cell.column; if (positions.Item1 >= 5 || positions.Item2 >= 5 || grid_matrix[positions.Item1, positions.Item2] == 1) { Debug.Log(grid_matrix[positions.Item1, positions.Item2]); Debug.Log("Cell is nope " + positions.Item1 + " " + positions.Item2); FindObjectOfType <ShakeCamHandler>().Shake(); piece.isSnapped = false; piece.transform.position = FindNewPosition(); return; } positionsToOccupy.Add((positions.Item1, positions.Item2)); } positions.Item2 = cell.column; } piece.isSnapped = false; piece.select.position = new Vector3(cell.transform.position.x, cell.transform.position.y, piece.select.transform.position.z); piece.snappedTo = cell; SetPositionsToGrid(positionsToOccupy, 1); piece.positions = positionsToOccupy; }
public GoPosition(int rowIndex, int colIndex, PositionPiece piece) { this.rowIndex = rowIndex; this.colIndex = colIndex; this.piece = piece; }
public GoBoardGroup(PositionPiece color) { this.groupColor = color; this.piecesInGroup = new List<GoPosition>(); firstLiberty = null; hasManyLiberties = false; }
private bool KillDeadGroups(PositionPiece color) { bool hasKilledSomething = false; bool hasWrongColorDeadGroup = false; foreach (var group in deadGroups) { if (group.groupColor != color) { foreach (var piece in group.piecesInGroup) { piece.piece = PositionPiece.Empty; } hasKilledSomething = true; } else { hasWrongColorDeadGroup = true; } } if (hasKilledSomething) { ResetGroups(); } return hasKilledSomething || !hasWrongColorDeadGroup; }
public bool Play(PositionPiece position, int rowIndex, int colIndex) { rowIndex = rowIndex % 18; colIndex = colIndex % 18; if (positions[rowIndex, colIndex].piece != PositionPiece.Empty) { return false; } positions[rowIndex, colIndex].piece = position; PrepareBoardInfo(); return KillDeadGroups(position); }
public GoGame MakePlay(string initialState, bool blackPlaysNext, bool isNullGame, PositionPiece color, int row, int col, bool isValidPlay, string newState, out bool result) { GoGame game = null; if (!isNullGame) { game = new GoGame(); game.BlackPlaysNext = blackPlaysNext; game.GameOver = false; game.GameState = initialState; } var activeGame = new Mock<IActiveGoGame>(); activeGame.Setup(x => x.Game).Returns(game); activeGame.Setup(x => x.PlayerColor).Returns(color); var boardService = new Mock<IGoBoardData>(); boardService.Setup(x => x.Play(color, row, col)).Returns(isValidPlay); boardService.Setup(x => x.GetBoardState(color)).Returns(newState); var goService = new GoService(activeGame.Object, null, boardService.Object, null); result = goService.Play(row, col); return game; }
public void unSnapToGrid(PositionPiece piece, List <(int, int)> positions)