Exemplo n.º 1
0
    Movement GetBlockingMovement()
    {
        int row = last_evaluation.row;
        int col = last_evaluation.col;

        EDirection direction_to_block = last_evaluation.DangerDirection();

        switch (direction_to_block)
        {
        case EDirection.Horizontal:
            // This needs to be extracted and deal with a more complex logic.
            // Its being repeated at make movement
            return(GetHorizontalMovement(col, row));

        case EDirection.Vertical:
            if (ValidIndex(row + 1) && playing_board.board[row + 1, col] == ESlotStatus.Empty)
            {
                return(new Movement(row + 1, col));
            }
            if (ValidIndex(row - 1) && playing_board.board[row - 1, col] == ESlotStatus.Empty)
            {
                return(new Movement(row - 1, col));
            }
            break;

        case EDirection.DiagonalNeg:
            if ((ValidIndex(row - 1) && ValidIndex(col - 1)) && playing_board.board[row - 1, col - 1] == ESlotStatus.Empty)
            {
                return(new Movement(row - 1, col - 1));
            }
            if ((ValidIndex(row + 1) && ValidIndex(col + 1)) && playing_board.board[row + 1, col + 1] == ESlotStatus.Empty)
            {
                return(new Movement(row + 1, col + 1));
            }
            break;

        case EDirection.DiagonalPos:
            if ((ValidIndex(row + 1) && ValidIndex(col - 1)) && playing_board.board[row + 1, col - 1] == ESlotStatus.Empty)
            {
                return(new Movement(row + 1, col - 1));
            }
            if ((ValidIndex(row - 1) && ValidIndex(col + 1)) && playing_board.board[row - 1, col + 1] == ESlotStatus.Empty)
            {
                return(new Movement(row - 1, col + 1));
            }
            break;

        case EDirection.ItsAllFine:
            break;

        default:
            break;
        }
        return(GetWinningMovement());
    }
Exemplo n.º 2
0
    Movement GetWinningMovement()
    {
        // What this should do:
        // Iterate over our movements, calculate the danger of the movement and
        // select the one that is going to give us the most for our buck!


        foreach (Movement current_movement in playing_board.ai_movements)
        {
            DangerEvaluation evaluation = EvaluateMovement(current_movement);
            if (last_self_evaluation.MaxRisk() < evaluation.MaxRisk())
            {
                last_self_evaluation = evaluation;
            }
        }

        EDirection direction_to_move = last_self_evaluation.DangerDirection();
        int        row      = playing_board.last_ai_movement.row;
        int        col      = playing_board.last_ai_movement.col;
        Movement   movement = new Movement(row, col);

        switch (direction_to_move)
        {
        case EDirection.Horizontal:
            // This needs to be extracted and deal with a more complex logic.
            // Its being repeated at make movement
            if (ValidIndex(col + 1) && playing_board.board[row, col + 1] == ESlotStatus.Empty)
            {
                return(new Movement(row, col + 1));
            }
            if (ValidIndex(col - 1) && playing_board.board[row, col - 1] == ESlotStatus.Empty)
            {
                return(new Movement(row, col - 1));
            }
            break;

        case EDirection.Vertical:
            if (ValidIndex(row + 1) && playing_board.board[row + 1, col] == ESlotStatus.Empty)
            {
                return(new Movement(row + 1, col));
            }
            if (ValidIndex(row - 1) && playing_board.board[row - 1, col] == ESlotStatus.Empty)
            {
                return(new Movement(row - 1, col));
            }
            break;

        case EDirection.DiagonalNeg:
            if ((ValidIndex(row - 1) && ValidIndex(col - 1)) && playing_board.board[row - 1, col - 1] == ESlotStatus.Empty)
            {
                return(new Movement(row - 1, col - 1));
            }
            if ((ValidIndex(row + 1) && ValidIndex(col + 1)) && playing_board.board[row + 1, col + 1] == ESlotStatus.Empty)
            {
                return(new Movement(row + 1, col + 1));
            }
            break;

        case EDirection.DiagonalPos:
            if ((ValidIndex(row + 1) && ValidIndex(col - 1)) && playing_board.board[row + 1, col - 1] == ESlotStatus.Empty)
            {
                return(new Movement(row + 1, col - 1));
            }
            if ((ValidIndex(row - 1) && ValidIndex(col + 1)) && playing_board.board[row - 1, col + 1] == ESlotStatus.Empty)
            {
                return(new Movement(row - 1, col + 1));
            }
            break;

        case EDirection.ItsAllFine:
            break;

        default:
            break;
        }

        return(GetRandomMovement());
    }