Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    public void HandlePlayerClick(int x, int y)
    {
        if (!ReversiRules.CanPutCell(_currentBordData, x, y, _firstPlayer))
        {
            return;
        }

        OnDoTurn?.Invoke(x, y);
        PlayerInput.OnTouchBoard -= HandlePlayerClick;
    }