Expected Value Of a Random Grid That Contains Multipliers I am a software developer and recently came across this problem when working on a hobby project, and my knowledge of probability is too small to solve this.
I have a bag that contains 5 negative ones, 5 zeros, 10 ones, 5 twos, 5 threes. The tiles are set randomly on a 5 by 5 grid with 5 tiles left in the bag. The threes in the bag also multiply all 8 of the adjacent squares by 2 (A number is multiplied by $2^n$ adjacent 3's). What is the best way to calculate the expected value of the grid for any known bag that can contain a random amount of any numbers? Bonus points if it can handle any size (and rectangular shape) of grid.
Eg. Bag ( 2 1 3 3 3 ), Grid Value: 27
$$\begin{array}{c|c|c|c|c}
3&2&1&-1&1\\
\hline
1&1&0&0&-1\\
\hline 
1&0&3&2&2\\
\hline
-1&0&-1&2&1\\
\hline
1&-1&1&1&0
\end{array}$$
Without the multiplier, the solution is quite simple:

The number of values in the grid (25) × The sum of all of the numbers in the bag / the number of numbers in the bag. Or $(n * s) / a$

Since they do not interact, the fact they are in a grid does not even matter. For the same reason, it's not that useful for solving this problem, but I thought I would mention it as a start.
A kinda related question of mine
 A: Edit: this does NOT solve the problem stated. I implicitly assume that if a value is next to $n$ threes, it is multiplied by $n + 1$. However, OP clarified in the comments that the value is multiplied by $2^n$ if it is next to $n$ threes. I'm not sure how to fix this.
This is actually a rather simple problem (or rather, the complexity is deceptive). The problem boils down to calculating the expected value of the sum of elements adjacent to each three.
By linearity of expectation, it suffices to calculate the expected sum of elements adjacent to a given 3, then multiply by the number of 3s.
Now the expected sum of the neighbors of a given 3 is equal to the expected number of neighbors, times the expected value of each given neighbor. This is because no matter how many neighbors a 3 has, the expected value of a given neighbor is constant.
Let's take the case of an $m \times m$ grid with $n$ copies of 3 and a total number of bag elements $M \geq m \geq 2$. Then the expected value of a neighbor of 3 will be $\frac{S - 3}{M - 1}$, where $S$ is the sum of all elements in the bag.
Now for calculating the expected number of neighbors of a given 3. To do this, note that there is a $\frac{4}{M}$ chance of the 3 being in a corner, a $\frac{4(m - 2)}{M}$ chance of $m$ being on an edge, and a $\frac{(m - 2)^2}{M}$ chance of the 3 being in the middle. If the 3 is in a corner, it has only 3 neighbours. On an edge, the 3 will have 5 neighbours. There is also a chance the 3 won't make it onto the board of $\frac{M - m^2}{M}$, in which case the 3 will have zero neighbors. This gives us an expected value of $3 \frac{4}{M} + 5 \frac{4(m - 2)}{M} + 8 \frac{(m - 2)^2}{M}$.
So the expected sum of the neighbours of all threes will be $n \cdot \frac{S - 3}{M} \cdot (3 \frac{4}{M} + 5 \frac{4(m - 2)}{M} + 8 \frac{(m - 2)^2}{M})$.
To answer the original problem, we must add the expected sum of the (unadjusted by 3-doubling) grid back in, which is $\frac{S m^2}{M}$.
So the final answer is
$$
\frac{S m^2}{M} + n \cdot \frac{S - 3}{M} \cdot (3 \frac{4}{M} + 5 \frac{4(m - 2)}{M} + 8 \frac{(m - 2)^2}{M})
$$
