public void StartTurn(Cell[,] currentBordData) { var possibleCells = ReversiRules.GetPossibleTurns(currentBordData, _firstPlayer); var cellValue = new Dictionary <Cell, int>(); foreach (var cell in possibleCells) { var value = 0; var rivalLines = ReversiRules.GetRivalLinesAroundCell(currentBordData, cell.x, cell.y, _firstPlayer); foreach (var rivalLine in rivalLines) { value += rivalLine.Count; } cellValue[cell] = value; } var optimalTurn = possibleCells.First(); foreach (var cell in cellValue.Keys) { if (cellValue[cell] > cellValue[optimalTurn]) { optimalTurn = cell; } } OnDoTurn?.Invoke(optimalTurn.x, optimalTurn.y); }
public void HandlePlayerClick(int x, int y) { if (!ReversiRules.CanPutCell(_currentBordData, x, y, _firstPlayer)) { return; } OnDoTurn?.Invoke(x, y); PlayerInput.OnTouchBoard -= HandlePlayerClick; }