// ПОСЛЕДНЯЯ РЕАЛИЗАЦИЯ ИНТЕРФЕЙСА ОТ МИХАИЛА public CellCoordinates NextMove(CellState.cellState[,] currentState, byte qtyCellsForWin, bool isHuman, TimeSpan remainingTimeForGame, int remainingQtyMovesForGame) { CellCoordinates nextMove = new CellCoordinates(); Cell aiMove; // move in Team4 naming // Check empty field -> AIPlayer makes 1st move if (IsBoardEmpty(currentState)) { // TODO: ПЕРВЫЕ ХОДЯТ ВСЕГДА КРЕСТИКИ SetAIPlayerParameters(1, qtyCellsForWin, currentState.GetLength(0)); aiMove = TakeCenter(MainBoard); } else //not 1st move in game! { if (MainBoard == null) // if AIPlayer has not made a turn yet (second turn in game) - AI plays 'O'. { SetAIPlayerParameters(2, qtyCellsForWin, currentState.GetLength(0)); } // Update MainBoard lastMove - not 1st or 2nd move in game MainBoard.UpdateBoard(DefineLastMove(currentState)); aiMove = MakeMove(MainBoard); } nextMove.X = (byte)aiMove.row; // Y - это значение столбца, а X - строки. nextMove.Y = (byte)aiMove.col; return(nextMove); }
public void PlacePawn(CellController cellToPlaceOn) { transform.position = cellToPlaceOn.transform.position; PawnCoordinates = cellToPlaceOn.cellCoordinate; PawnManager.Instance.FillOrganizedArray(this); PawnManager.Instance.VictoryCheck(0, 1, 2, 3, true); PawnManager.Instance.VictoryCheck(0, 1, 2, 3, false); PawnManager.Instance.VictoryCheck(0, 4, 8, 12, true); PawnManager.Instance.VictoryCheck(0, 4, 8, 12, false); PawnManager.Instance.VictoryCheck(0, 5, 10, 15, true); PawnManager.Instance.VictoryCheck(0, 5, 10, 15, false); PawnManager.Instance.VictoryCheck(1, 5, 9, 13, true); PawnManager.Instance.VictoryCheck(1, 5, 9, 13, false); PawnManager.Instance.VictoryCheck(2, 6, 10, 14, true); PawnManager.Instance.VictoryCheck(2, 6, 10, 14, false); PawnManager.Instance.VictoryCheck(3, 6, 9, 12, true); PawnManager.Instance.VictoryCheck(3, 6, 9, 12, false); PawnManager.Instance.VictoryCheck(3, 7, 11, 15, true); PawnManager.Instance.VictoryCheck(3, 7, 11, 15, false); PawnManager.Instance.VictoryCheck(4, 5, 6, 7, true); PawnManager.Instance.VictoryCheck(4, 5, 6, 7, false); PawnManager.Instance.VictoryCheck(8, 9, 10, 11, true); PawnManager.Instance.VictoryCheck(8, 9, 10, 11, false); PawnManager.Instance.VictoryCheck(12, 13, 14, 15, true); PawnManager.Instance.VictoryCheck(12, 13, 14, 15, false); }
public InputCell(CellCoordinates _coordinates, ObjectOrientation _orientation, int _value) : base(GridObjectType.Input, FindFootprint(_coordinates, _orientation)) { CurrentValues = new int[1]; InputValue = _value; Exit = GridObjectOrientationHelper.Find1x1OffsetRight(_coordinates, _orientation); }
public OutputCell(CellCoordinates _coordinates, ObjectOrientation _orientation, int _target) : base(GridObjectType.Output, FindFootprint(_coordinates, _orientation)) { CurrentValues = new int[1]; OutputTarget = _target; Entry = GridObjectOrientationHelper.Find1x1OffsetLeft(_coordinates, _orientation); }
private static CellCoordinates[] FindOutputs(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates output1 = GridObjectOrientationHelper.Find1x1OffsetRight(_coordinates, _orientation); CellCoordinates output2 = GridObjectOrientationHelper.Find1x1OffsetDown(_coordinates, _orientation); return(new CellCoordinates[] { output1, output2 }); }
private bool IsAdjacentTo(CellCoordinates _cell, CellCoordinates _other) { int xDif = Mathf.Abs((int)_cell.X - (int)_other.X); int yDif = Mathf.Abs((int)_cell.Y - (int)_other.Y); return(xDif + yDif <= 1); }
public Vector2 GetScreenFromGrid(CellCoordinates _coordinates) { Vector2 gridSize = new Vector2(endPos.x - startPos.x, endPos.y - startPos.y); Vector2 squareSize = new Vector2(gridSize.x / gridWidth, gridSize.y / gridHeight); return(startPos + (new Vector2((int)_coordinates.X - 1, (int)_coordinates.Y - 1) * squareSize) + (squareSize * 0.5f)); }
public void TestValidFieldToText() { var position = new CellCoordinates(4, 2); string received = BoardCoordinatesConverter.CoordinatesToCellName(position); Assert.AreEqual("C5", received); }
public void ClearWire(CellCoordinates _cellCoordinates) { foreach (VisualWire visualWire in completedWires.ToArray()) { if (visualWire.cellCoordinates == _cellCoordinates) { foreach (GameObject gameObjectToKill in visualWire.wireObjects) { Destroy(gameObjectToKill); } completedWires.Remove(visualWire); } } GridObject gridPoint = gridManager.GetCell(_cellCoordinates); if (gridPoint != null) { foreach (CellCoordinates connection in gridPoint.Coordinates) { foreach (VisualWire visualWire in completedWires.ToArray()) { if (visualWire.cellCoordinates == connection) { foreach (GameObject gameObjectToKill in visualWire.wireObjects) { Destroy(gameObjectToKill); } completedWires.Remove(visualWire); } } } } }
private static CellCoordinates[] FindInputs(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates input1 = GridObjectOrientationHelper.Find1x1OffsetLeft(_coordinates, _orientation); CellCoordinates input2 = GridObjectOrientationHelper.Find1x1OffsetUp(_coordinates, _orientation); return(new CellCoordinates[] { input1, input2 }); }
private void CreateExplosions(CellCoordinates cell) { Match[cell] = new Explosion(Match, Explosion.Type.CENTER, new Vector(), Match.GetScreenCoordinates(cell), Match.CellSize); var direction = new CellCoordinates(-1, 0); for (int i = 0; i < 4; i++) { direction = direction.RotatedRight; for (int r = 1; r <= Constants.Bomb.REACH; r++) { var explosionCell = cell + direction * r; var cellContent = Match[explosionCell]; if (cellContent == null) { Match[explosionCell] = new Explosion(Match, getExplosionType(r), new Vector(direction.Column, direction.Row), Match.GetScreenCoordinates(explosionCell), Match.CellSize); } else { if (cellContent.Destroyable) { cellContent.Destroy(); Match[explosionCell] = new Explosion(Match, Explosion.Type.END, new Vector(direction.Column, direction.Row), Match.GetScreenCoordinates(explosionCell), Match.CellSize); } break; } } } }
public Cell(int id, CellCoordinates coordinates, Vector2 worldPosition, int[] adjacentCellsIds) { Id = id; Coordinates = coordinates; WorldPosition = worldPosition; _adjacentCellsIds = adjacentCellsIds; }
private static IList <int> FindOpenerMoves(Board board) { var dimensions = board.Dimensions; // The middle of a board is of highest priority. // account for a multi cell middle, e.g. width = 4, height = 3 => middle is at (1,1) and (2,1) var middleSpan = new CellSpan(1 - dimensions.Width % 2, 1 - dimensions.Height % 2); var step = new CellSpan(1, 1); for ( CellCoordinates topLeft = new CellCoordinates(dimensions.Width / 2, dimensions.Height / 2), bottomRight = topLeft + middleSpan; CellCoordinates.IsInside(topLeft, dimensions) && CellCoordinates.IsInside(bottomRight, dimensions); topLeft -= step, bottomRight += step) { var cells = Cells.TakeAnyFreeCellInRect( board, CellCoordinates.ToCellAt(topLeft, dimensions), CellCoordinates.ToCellAt(bottomRight, dimensions)); // If cells are already occupied, take a cell from the rectangle around the current one, if (cells.Length > 0) { return(cells); } // repeat until a free cell is found. } return(Array.Empty <int>()); }
private void TryCommit() { CellCoordinates _end = m_passedThrough.Peek(); GridObject end = m_gridManager.GetCell(_end); if (end == null) { Log("WireManager: Commit attempted on an empty cell " + _end.ToString() + ", ending mode."); ResetMode(); return; } if (m_passedThrough.Count < 3) { Log("WireManager: Commit attempted with too few cells passed through."); ResetMode(); return; } // Generate wire objects List <CellCoordinates> coordinates = new List <CellCoordinates>(m_passedThrough); coordinates.Reverse(); // Probably? Wire toCreate = new Wire(coordinates.GetRange(1, coordinates.Count - 2).ToArray(), coordinates[0], coordinates[coordinates.Count - 1]); // Insert wire into grid m_gridManager.InsertObject(toCreate); m_gameplayManager.UpdateGiblets(toCreate.Entry); m_gameplayManager.UpdateGiblets(toCreate.Exit); Log("WireManager: Successfully committed at " + _end.ToString()); ResetMode(); }
public static CellCoordinates Find1x1OffsetRight(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates coords = _coordinates; switch (_orientation) { case ObjectOrientation.Or0: { coords.X += 1; break; } case ObjectOrientation.Or90: { coords.Y -= 1; break; } case ObjectOrientation.Or180: { coords.X -= 1; break; } case ObjectOrientation.Or270: { coords.Y += 1; break; } } return(coords); }
private bool checkResult(CellState.cellState id, CellCoordinates move) { if (checkBackwardDiagonal(id, new byte[] { move.X, move.Y }) || checkForwardDiagonal(id, new byte[] { move.X, move.Y }) || checkHorizntal(id, move.X) || checkVertical(id, move.Y)) { return(true); } return(false); }
private Cell GetNewCell(int rows, int columns, int id, int x, int y) { var coordinates = new CellCoordinates(x, y); var worldPosition = new Vector2(x * _cellOffset, y * _cellOffset); var adjacentCells = GetAdjacentCellsToCell(rows, columns, id, x, y); return(new Cell(id, coordinates, worldPosition, adjacentCells)); }
public static CellCoordinates Find1x1OffsetUp(CellCoordinates _coordinates, ObjectOrientation _orientation) { int orientation = (int)_orientation; orientation += 3; orientation = orientation % (int)ObjectOrientation.SIZE; return(Find1x1OffsetRight(_coordinates, (ObjectOrientation)orientation)); }
public static Cell GetMockCell(int cellId, CellCoordinates coordinates, int[] adjacentCells) { return(new Cell( cellId, coordinates, new UnityEngine.Vector2(coordinates.X, coordinates.Y), adjacentCells )); }
public int GetDistanceToCoordinates(CellCoordinates target) { var vectorDistance = new Vector2Int( Mathf.Abs(target.X - X), Mathf.Abs(target.Y - Y) ); return(vectorDistance.x + vectorDistance.y); }
public void CreateWireAndLink(CellCoordinates _currentStart, CellCoordinates _currentEnd) { Vector2Int direction = new Vector2Int((int)_currentEnd.X - (int)_currentStart.X, (int)_currentEnd.Y - (int)_currentStart.Y); GameObject wire = CreateWire(_currentStart, _currentEnd, direction); completedWires.Add(new VisualWire(_currentEnd, new List <GameObject>() { wire })); }
public void TestLargeColumnCausesException() { var position = new CellCoordinates(0, 9); TestDelegate failure = delegate() { BoardCoordinatesConverter.CoordinatesToCellName(position); }; Assert.Catch(failure, "invalid row name"); }
public void ClearCell(CellCoordinates _coordinates) { // Removes all references to the GridObject at _coordinates from the grid GridObject o = m_grid[_coordinates.X, _coordinates.Y]; if (o != null) { // Delete wires (if any) if (o.ObjectType == GridObjectType.Gate) { Gate gate = (Gate)o; foreach (CellCoordinates inputCoords in gate.Inputs) { GridObject input = GetCell(inputCoords); if (input != null && input.ObjectType == GridObjectType.Wire) { Wire wire = (Wire)input; for (uint i = 0; i < o.Coordinates.Length; ++i) { if (o.Coordinates[i] == wire.Exit) { // This wire actually connects to us, destroy it ClearCell(input.Coordinates[0]); break; } } } } foreach (CellCoordinates outputCoords in gate.Outputs) { GridObject output = GetCell(outputCoords); if (output != null && output.ObjectType == GridObjectType.Wire) { Wire wire = (Wire)output; for (uint i = 0; i < o.Coordinates.Length; ++i) { if (o.Coordinates[i] == wire.Entry) { // This wire actually connects to us, destroy it ClearCell(output.Coordinates[0]); break; } } } } } // Delete self for (uint i = 0; i < o.Coordinates.Length; ++i) { Debug.Log("GridManager: Clearing a GridObject from (" + o.Coordinates[i].X.ToString() + "," + o.Coordinates[i].Y.ToString() + ")"); m_grid[o.Coordinates[i].X, o.Coordinates[i].Y] = null; } } }
protected override void OnDestroy(CellCoordinates cell) { timer.Stop(); timer.Dispose(); Match.Output.Audio.Play(Sounds.Explosion); CreateExplosions(cell); Match.CheckAllDeaths(); }
public void TestNegativeColumnIndexCausesException() { var position = new CellCoordinates(3, -1); TestDelegate failure = delegate() { BoardCoordinatesConverter.CoordinatesToCellName(position); }; Assert.Catch(failure, "invalid column name"); }
///////////////////////// Helpers ///////////////////////// private void StartDragging(CellCoordinates _start) { GridObject gridObject = m_gridManager.GetCell(_start); if (gridObject != null && (gridObject.ObjectType == GridObjectType.Gate || gridObject.ObjectType == GridObjectType.Input)) { Log("WireManager: Starting drag from " + _start.ToString()); m_passedThrough.Push(_start); m_isDragging = true; } }
private static CellCoordinates[] FindInputs(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates[] footprint = GridObjectOrientationHelper.Find2x1Footprint(_coordinates, _orientation); CellCoordinates[] inputs = new CellCoordinates[footprint.Length]; for (uint i = 0; i < footprint.Length; ++i) { inputs[i] = GridObjectOrientationHelper.Find1x1OffsetLeft(footprint[i], _orientation); } return(inputs); }
public override int GetValueForCoordinate(CellCoordinates _coordinates) { for (int i = 0; i < Outputs.Length; ++i) { if (Outputs[i].X == _coordinates.X && Outputs[i].Y == _coordinates.Y) { return(CurrentValues[i]); } } Debug.LogError("Gate: GetValueForCoordinate passed coordinate (" + _coordinates.X + "," + _coordinates.Y + ") which maps to no outputs for this gate."); return(CurrentValues[0]); }
public override void OnGUI( Rect position, SerializedProperty property, GUIContent label ) { CellCoordinates coordinates = new CellCoordinates( property.FindPropertyRelative("x").intValue, property.FindPropertyRelative("z").intValue ); position = EditorGUI.PrefixLabel(position, label); GUI.Label(position, coordinates.ToString()); }
GameObject CreateWire(CellCoordinates _currentStart, CellCoordinates _currentEnd, Vector2Int _direction) { GameObject currentWire = Instantiate(wirePrefab, gridParent.transform); Log("Visual Wire Manager:Creating Wire at Start point:" + _currentStart + " & End point:" + _currentEnd); currentWire.transform.SetAsFirstSibling(); currentWire.GetComponent <RectTransform>().anchoredPosition = visualGridManager.GetScreenFromGrid(_currentStart) + new Vector2(-5, 0); currentWire.GetComponent <RectTransform>().rotation = Quaternion.Euler(0, 0, 90) * Quaternion.LookRotation(Vector3.forward, new Vector3(_direction.x, _direction.y, 0.0f)); currentWire.GetComponent <RectTransform>().sizeDelta = new Vector2((visualGridManager.GetScreenFromGrid(_currentStart) - visualGridManager.GetScreenFromGrid(_currentEnd)).magnitude + 5, 10.0f); currentWire.transform.SetParent(wireParent.transform); return(currentWire); }