[Question]
  [
## ...or Toroidal Moore Neighbourhoods
Given positive integers `h`, `w` and a non-negative integer `i`, return all of the indices surrounding `i`.
You are to assume a matrix consisting of `h` rows of `w` elements, numbered from lowest, in the top left-hand corner, to highest, in the bottom right-hand corner, and return, in any reasonable format, a list of the indices that would surround the index, `i`. This matrix is a torus (an infinite map that wraps around each edge).
For example, inputs `h=4` and `w=4`, would result in the matrix:
```
 0  1  2  3 
 4  5  6  7
 8  9 10 11
12 13 14 15
```
but more specifically:
```
**15 12 13 14 15 12**
 **3**  0  1  2  3  **0**
 **7**  4  5  6  7  **4**
**11**  8  9 10 11  **8**
**15** 12 13 14 15 **12**
 **3 0 1 2 3 0**
```
so that if `i` was `0`, you'd need to return `15, 12, 13, 3, 1, 7, 4, 5` (0-based).
## Examples
*0-based:*
```
h   w   i       Expected result
4   4   5       0, 1, 2, 4, 6, 8, 9, 10
4   4   0       15, 12, 13, 3, 1, 7, 4, 5
4   5   1       15, 16, 17, 0, 2, 5, 6, 7
1   3   2       1, 2, 0, 1, 0, 1, 2, 0
1   1   0       0, 0, 0, 0, 0, 0, 0, 0
```
*1-based:*
```
h   w   i       Expected result
4   4   6       1, 2, 3, 5, 7, 9, 10, 11
4   4   1       16, 13, 14, 4, 2, 8, 5, 6
4   5   2       16, 17, 18, 1, 3, 6, 7, 8
1   3   3       2, 3, 1, 2, 1, 2, 3, 1
1   1   1       1, 1, 1, 1, 1, 1, 1, 1
```
## Rules
* Your answer may be 0 or 1-indexed, your choice, please specify.
* You can assume that `i < h * w` (or `i <= h * w` for 1-indexed answers).
* You can assume that `i >= 0` (or `i > 0` for 1-indexed answers).
* The order of the returned values is not important as long as just the eight desired values are included.
* [Standard loopholes are forbidden](https://codegolf.meta.stackexchange.com/users/31957/conor-obrien).
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest answer, in each language, wins!
Thanks to [@Conor O'Brien](https://codegolf.meta.stackexchange.com/users/31957/conor-obrien) for the more technical sounding title and [@ngm](https://codegolf.meta.stackexchange.com/users/79980/ngm) for more test cases!
  
[Answer]
# JavaScript (ES6), 75 bytes
*Saved 2 bytes thanks to @KevinCruijssen*
Expects a 0-based index.
```
(h,w,i)=>[...'12221000'].map((k,j,a)=>(i+w+~-k)%w+~~(i/w+h+~-a[j+2&7])%h*w)
```
[Try it online!](https://tio.run/##bY7NbsJADITvPIUvwG4zbOxNltADvAjisOKnSfgJAtTcePWwWlqEmkqWLNvzeab23/66vlTn2@TUbLbdbt6pEi0qPV8sjTFjsdYKM49X5ujPSu1Rw4ejqpI2uU/2ehjaXVVpm5Rh9ss6saNipYflR6u7dXO6NoetOTRfaqdy5HBaU5oSgwRkQTloCpqBPsOGB32An4C4cA96yUBZhIsIux7iIG9IeC5BydHMRbPiDyLIYH@QKHuGe0Xknl5@UzH@q@4B "JavaScript (Node.js) ‚Äì Try It Online")
The surrounding indices are returned in the following order:
$$\begin{matrix}5&4&3\\6&\cdot&2\\7&0&1\end{matrix}$$
### How?
The indices \$I\_{dx,dy}\$ of each surrounding cell at \$(x+dx,y+dy)\$ are given by:
$$\begin{align}I\_{dx,dy}&=((x+dx) \bmod w)+w((y+dy) \bmod h)\\&=((N+dx) \bmod w)+w((\left\lfloor\frac{N}{w}\right\rfloor+dy) \bmod h)\end{align}$$
where \$N=wy+x\$ is the index of the target cell.
We walk through the list \$[1,2,2,2,1,0,0,0]\$ and subtract \$1\$ to get the value of \$dx\$, which gives:
$$[0,1,1,1,0,-1,-1,-1]$$
For the corresponding values of \$dy\$, we use the same list shifted by 2 positions, which gives:
$$[1,1,0,-1,-1,-1,0,1]$$
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 27 bytes
```
{(‚ç∫‚ä•‚ç∫|(‚ç∫‚ä§‚çµ)-‚ä¢)¬®1-1‚Üì4‚åΩ,‚ç≥3 3}
```
[Try it online!](https://tio.run/##bY/PSsNAEMbvfYq5JQsGd/OnUd8mpE1YTLJlNxfRXlQKpl0RxKMHq0LvUgTBSx9lXiTOpr0I3YVh2N8333ybzapgcpVVqgzyKjNG5j0@vkiFiyfeF1SvfbQ/2H1Svdm3H2i3LMBuzXYbEQhcPMe4@j1B@xVBNO97Q1Nol7j63m2wu4XjB@0rGKXbUU1y32D3zvDhzTVrdlydq3qWaWlUA7JslJZNCUpPpnrUupyUqqZh7bZ3d8UpZb3w1KWHy3uvyGTlufB2q@eDWTs17cj3Y4hZwlrgICCEGMZwBucg@AFxQiIBEYKgv5EmJU0ywISJAxyDSMkghITGU4ICIhY6SG/OeG/OByIGT/7//gE "APL (Dyalog Classic) ‚Äì Try It Online")
`{` `}` is a function with arguments `‚ç∫` (the dimensions `h w`) and `‚çµ` (the index `i`)
`‚ç≥3 3` is a matrix of all 2-digit ternary numbers: `0 0`, `0 1`, ..., `2 2`
`,` enlists the matrix as a vector
`1‚Üì4‚åΩ` removes the centre element `1 1` by rotating 4 to the left (`4‚åΩ`) and dropping one (`1‚Üì`)
`1-` subtracts from 1, giving all 8 neighbour offsets
`(` `)¬®` applies the function train in parentheses to each offset
`‚ç∫‚ä§‚çµ` is the base-`‚ç∫` encoding of `‚çµ` - the coordinates of `‚çµ` in the matrix
`(‚ç∫‚ä§‚çµ)-‚ä¢` subtracts the current offset, giving the coordinates of a neighbour
`‚ç∫|` is mod `a` to wrap around coordinates and stay within the matrix
`‚ç∫‚ä•` decodes from base `‚ç∫`
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 40 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous infix function. Takes `h` `w` as left argument and `i` as right argument.
```
{1‚Üì4‚åΩ,3 3‚Üë,‚ç®‚ç£2‚ç™‚ç®‚ç£2‚äÉ‚äñ‚àò‚çâ/(¬Ø1+‚ç∫‚ä§‚çµ),‚äÇ‚ç∫‚ç¥‚ç≥√ó/‚ç∫}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/6sNH7VNNnnUs1fHWMH4UdtEnUe9Kx71LjZ61LsKxupqftQ17VHHjEe9nfoah9Ybaj/q3fWoa8mj3q2aOo@6mkC83i2Pejcfnq4PZNf@TwMa/Ki3D2JHV/Oh9SBzgbzgIGcgGeLhGfzfRMFEIU3BlAtCGwBpUyBtyGWoYAykjYC0IUgcAA "APL (Dyalog Unicode) ‚Äì Try It Online") 
`{`‚Ä¶`}`‚ÄÉ"dfn"; `‚ç∫` is left argument (dimensions) and `‚çµ` is right argument (index).
‚ÄÉ`√ó/‚ç∫`‚ÄÉproduct (multiplication-reduction) of the dimensions
‚ÄÉ`‚ç≥`‚ÄÉthe first that many indices
‚ÄÉ`‚ç∫‚ç¥`‚ÄÉuse the dimensions to **r**eshape that
‚ÄÉ`‚äÇ`‚ÄÉenclose it (to treat it as a single element)
‚ÄÉ`(`‚Ä¶`),`‚ÄÉprepend the following:
‚ÄÉ‚ÄÉ`‚ç∫‚ä§‚çµ`‚ÄÉencode the index in mixed-radix `h` `w` (this gives us the coordinates of the index)
‚ÄÉ‚ÄÉ`¬Ø1+`‚ÄÉadd negative one to those coordinates
‚ÄÉ`‚äñ‚àò‚çâ/`‚ÄÉreduce by rotate-the-transpose  
‚ÄÉ‚ÄÉthis is equivalent to `y‚äñ‚çâx‚äñ‚çâ`‚Ä¶ which is equivalent to `y‚äñx‚åΩ`‚Ä¶ which rotates left as many steps as `i` is offset to the right (less one), and rotates up as many steps as `i` is offset down (less one), causing the the 3-by-3 matrix we seek to be in the top left corner
‚ÄÉ`‚äÉ`‚ÄÉdisclose (because the reduction reduced the vector to scalar by enclosing)
‚ÄÉ`‚ç™‚ç®‚ç£2`‚ÄÉstack on top of itself twice (we only really need thrice for single-row matrices)
‚ÄÉ`,‚ç®‚ç£2`‚ÄÉappend to itself twice (we only really need thrice for single-column matrices)
‚ÄÉ`3 3‚Üë`‚ÄÉtake the first three rows of the first three columns
The next two steps can be omitted if returning a 3-by-3 matrix is acceptable:
‚ÄÉ`,`‚ÄÉravel (flatten)
‚ÄÉ`4‚åΩ`‚ÄÉrotate four steps left (brings the centre element to the front)
‚ÄÉ`1‚Üì`‚ÄÉdrop the first element
[Answer]
# [Python 2](https://docs.python.org/2/), ~~79~~ ~~69~~ 66 bytes
```
lambda h,w,i:[(i+q%3-1)%w+(i/w+q/3-1)%h*w for q in range(9)if q-4]
```
[Try it online!](https://tio.run/##XZBLDsIwDETXcApvEAk1atIPBSS4SMiiCEIjQWkipIrTl9T9LJC88czzxHHz/VTvOunM6dI9y9f1VkKFLdqjYjZyq3Qr@aqNmI3byMXUVZsWzNuDA1uDL@vHnR24NeC2me56g1EAR98DiqkMIVSuEZRAkAgJCTuEPcIhKEJzhIkTPSfzIAdMpggpzRRjyET2wEyGKBkAQdE5RRcDKWk@IZLcYYN5DzFjcnxakPtfmuvjctF4W3@G@6DH9em8RjP@tvsB "Python 2 ‚Äì Try It Online")
3 bytes gifted by [Neil](https://codegolf.stackexchange.com/users/17602/neil) noting that `(x*w)%(h*w)==((x)%h)*w==(x)%h*w`.
0-indexed solution.
[Answer]
# [R](https://www.r-project.org/), ~~125 111~~ 108 bytes
```
function(x,i,m=array(1:prod(x),x),n=rbind(m,m,m),o=cbind(n,n,n),p=which(m==i,T)+x-1)o[p[1]+0:2,p[2]+0:2][-5]
```
[Try it online!](https://tio.run/##PcjNCsMgEATge58ix12yQjVJD6G@RW@SQ2qQePAHaal9emsilJnDN5OK6e6sK@bt9csGD5ksObmmtH6BzzGFDTJSrZfpaf0GjmqQgtTn9FSDFOVnt3oHJ6WlB/aZcQwqKr7011lQVOLEoti0FAMaRhqRbnj5mzdPh0XzUE8amvlhjuUH "R ‚Äì Try It Online")
14 and 8 bytes golfed by @JayCe and @Mark.
Input is `[w, h], i` because R populates arrays column first.
Makes the array and then "triples" it row- and column-wise. Then locate `i` in the original array and find it's neighborhood. Output without `i`.
[Answer]
# [PHP](http://www.php.net/), 165 bytes
This is "0-based". There must be a better solution in PHP, but this is a starting point!
```
<?list(,$h,$w,$i)=$argv;for($r=-2;$r++<1;)for($c=-2;$c++<1;)$r||$c?print(($k=(int)($i/$w)+$r)<0?$h-1:($k>=$h?0:$k))*$w+(($l=$i%$w+$c)<0?$w-1:($l>=$w?0:$l))%$w.' ':0;
```
To run it:
```
php -n <filename> <h> <w> <i>
```
Example:
```
php -n cell_neighbours.php 4 5 1
```
Or [Try it online!](https://tio.run/##JcpBDoIwFIThq7gYQ58FBaMboPYspom2sYGmELvh7D5r3U3@@YINzKP2bllFDVsj1XCkcI/P9/CYo0BUzXlAlHLsBirFlGL@BXHbYHSIblqFwEuJPEjAnZBIItLYatim6/N3U7C67fEiOiDJzL2C2@cJU1wqzmeXfs4T5fNY7aq@HZj5wlfuPnNY3Twt3Exf "PHP ‚Äì Try It Online")
[Answer]
# [K (ngn/k)](https://gitlab.com/n9n/k), ~~27~~ 24 bytes
```
{x/x!''(x\y)-1-3\(!9)^4}
```
[Try it online!](https://tio.run/##VcxBDoIwEIXhvad4JCa0C7RDKQhzDXaAwQ3GYDBhVULw6rUILszs5nv5@2i4D851xWzPNghDYetJRhTpWgS5vCaLK4v5WE3vsehwguX21bNou9vjyZYnHmWzHMpKJEjYSFYgxEiQ4oIcpJqfKclkQDFIQ/tR5kdmV8O0aQrKoHzA@ED2VYLm2Kt/ru2tr3aiNavwd437AA "K (ngn/k) ‚Äì Try It Online")
`{` `}` is a function with arguments `x` (the dimensions `h w`) and `y` (the index `i`)
`(!9)^4` is `0 1 2 3 4 5 6 7 8` without the `4`
`3\` encodes in ternary: `(0 0;0 1;0 2;1 0;1 2;2 0;2 1;2 2)`
`1-` subtracts from `1`, giving neighbour offsets: `(1 1;1 0;1 -1;0 1;0 -1;-1 1;-1 0;-1 -1)`
`x\y` is the base-`x` encoding of `y` - the coordinates of `y` in the matrix
`-` subtracts each offset, giving us 8 pairs of neighbour coordinates
`x!''` is mod `x` for each - wrap coordinates around to stay within the matrix
`x/` decodes from base `x` - turns pairs of coordinates into single integers
[Answer]
# [MATL](https://github.com/lmendo/MATL), 24 bytes
```
*:2Geti=&fh3Y6&fh2-+!Z{)
```
Inputs are `h`, `w`, `i`. The output is a row vector or column vector with the numbers.
Input `i` and output are 1-based.
[Try it online!](https://tio.run/##y00syfn/X8vKyD21JNNWLS3DONIMSBrpaitGVWv@/2/CZcJlBgA "MATL ‚Äì Try It Online") Or [verify all test cases](https://tio.run/##y00syfmf8F/LysA9tSTTVi0twzjSDEga6WorRlVr/lfX1VWPcAn5b8JlwmXGBSINgdiUywhIGwOhIQgCAA).
### Explanation
```
*     % Take two inputs implicitly. Multiply
      % STACK: 16
:     % Range
      % STACK: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
2G    % Push second input again
      % STACK: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16], 4
e     % Reshape with that number of rows, in column-major order
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16]
t     % Duplicate
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16],
      %        [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16]
i=    % Take third input and compare, element-wise
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16],
      %        [0 0 0 0; 0 1 0 0; 0 0 0 0; 0 0 0 0]
&f    % Row and column indices of nonzeros (1-based)
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16], 2, 2,
h     % Concatenate horizontally
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16], [2 2]
3Y6   % Push Moore mask
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16], [2 2],
      %        [1 1 1; 1 0 1; 1 1 1]
&f    % Row and column indices of nonzeros (1-based)
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16], [2 2],
      %        [1; 2; 3; 1; 3; 1; 2; 3], [1; 1; 1; 2; 2; 3; 3; 3] 
h     % Concatenate horizontally
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16], [2 2],
      %        [1 1; 2 1; 3 1; 1 2; 3 2; 1 3; 2 3; 3 3] 
2-    % Subtract 2, element-wise
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16], [2 2],
      %        [-1 -1; 0 -1; 1 -1; -1 0; -1 0; -1 1; 0 1; 1 1] 
+     % Add, element-wise with broadcast
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16],
      %        [1 1; 2 1; 3 1; 1 2; 3 2; 1 3; 2 3; 3 3]
!     % Transpose
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16],
      %        [1 2 3 1 3 1 2 3; 1 1 1 2 2 3 3 3]
Z{    % Convert into a cell array of rows
      % STACK: [1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16],
      %        {[1 2 3 1 3 1 2 3], [1 1 1 2 2 3 3 3]}
)     % Index. A cell array acts as an element-wise (linear-like) index
      % STACK: [1 2 3 5 7 9 10 11]
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 74 bytes
```
Mod[i=#;w=#2;Mod[i+#2,w]+i~Floor~w+w#&@@@{-1,0,1}~Tuples~2~Delete~5,1##2]&
```
[Try it online!](https://tio.run/##Rcq9CsIwGIXhPVcR@KAo/YpNNFOJZBA3wcGtdCia0kBrpEYyhObW4w8F4QzPgXdsXa/H1plrmzq5Sid7q42Eykvg1e/kwNE3uYnHwdop@txDppQKBcMS2Rwvr8egn5HHgx6001EgA@BNltYVOU/m7moo9p1S0GQbFQgJAunusxlJKP9kSMVCjnSLlC0B@5KQOb0B "Wolfram Language (Mathematica) ‚Äì Try It Online")
Takes input in reverse (`i, w, h`), 0-based.
### 3x3 matrix with the center cell in it, (60 bytes)
```
(Join@@(p=Partition)[Range[#2#]~p~#,a={1,1};3a,a,2a])[[#3]]&
```
Takes (`w, h, i`), 1-based.
[Try it online!](https://tio.run/##NcixCsMgFEDR3a8ICEHhhaK2XYLFuVPoKg6PkrQOMSG4ifl1GwOFOxzujPE7zhj9G8ukWWHPxQdj2KoH3KKPfgncvjB8Rksldfu6U0CdBIjcKwQEiY5bS5VzbeE9GTYfoqXdYzKGuvZiEiHpCs3RPcOfovJ2UlaqY0GjKsVJkQnJ5Qc "Wolfram Language (Mathematica) ‚Äì Try It Online")
[Answer]
## Batch, 105 bytes
```
@for /l %%c in (0,1,8)do @if %%c neq 4 cmd/cset/a(%3/%2+%1+%%c/3-1)%%%1*%2+(%3%%%2+%2+%%c%%3-1)%%%2&echo.
```
0-indexed. Saved 23 bytes by stealing @ChasBrown's modulo 3 trick.
[Answer]
# MATL, 24 bytes
```
X[h3Y6&fh2-+1GX\1Gw!Z}X]
```
[Try it on MATL Online](https://matl.io/?code=X%5Bh3Y6%26fh2-%2B1GX%5C1Gw%21Z%7DX%5D&inputs=%5B5+4%5D%0A2&version=20.9.1)
Takes inputs `[w h]` and `i`. 8 bytes of this was ~~shamelessly stolen from~~ inspired by Luis Mendos' answer, though the overall approach is different.
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), ~~85~~ 83 bytes
```
import StdEnv
r=(rem)
$h w i=tl[r(n+i/w)h*w+r(r(m+i)w)w\\n<-[0,1,h-1],m<-[0,1,w-1]]
```
[Try it online!](https://tio.run/##LcyxDsIgFEDRvV/B0AEEYps4ylYHE7eObQdCUUh41FD0xZ8XGcydznJNsDoW2NZXsAS0j8XDc0uZjHm9xHeTFE0WWNM6gsSrHKZEI/dHZO6APNFEgXuGDOc5nuXUiV442S8C/sCKpYxZ16UiLTnVuvI196Afe5HXWxk@UYM3@w8 "Clean ‚Äì Try It Online")
Treats `i` as a coordinate `(0 <= p < h, 0 <= q < w)`, and generates the values of the adjacent elements where the value is `p'w + q'`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 20 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
PRs¬©·π™{≈ìi+‚Ç¨√ò-≈ª¬§≈íp·∏ä≈ì·ªã¬Æ
```
A dyadic link accepting a list of the dimensions on the left, `[h,w]`, and the cell as an integer on the right, `i`, which yields a list of the neighbourhood.
Note: the order is different to that in the examples which is allowed in the OP
**[Try it online!](https://tio.run/##ATUAyv9qZWxsef//UFJzwqnhuap7xZNpK@KCrMOYLcW7wqTFknDhuIrFk@G7i8Ku////WzQsNV3/Mg "Jelly ‚Äì Try It Online")**
### How?
```
PRs¬©·π™{≈ìi+‚Ç¨√ò-≈ª¬§≈íp·∏ä≈ì·ªã¬Æ - Link: [h,w], i
P                    - product -> h*w
 R                   - range -> [1,2,3,...,h*w]
    ·π™{               - tail of left -> w
  s                  - split into chunks -> [[1,2,3,...w],[w+1,...,2*w],[(h-1)*w+1,...,h*w]]
   ¬©                 - ...and copy that result to the register
      ≈ìi             - multi-dimensional index of (i) in that list of lists, say [r,c]
             ¬§       - nilad followed by link(s) as a nilad:
          √ò-         -   literal list -> [-1,1]
            ≈ª        -   prepend a zero -> [0,-1,1]
        +‚Ç¨           - addition (vectorises) for ‚Ç¨ach -> [[r,r-1,r+1],[c,c-1,c+1]]
              ≈íp     - Cartesian product -> [[r,c],[r,c-1],[r,c+1],[r-1,c],[r-1,c-1],[r-1,c+1],[r+1,c],[r+1,c-1],[r+1,c+1]]
                ·∏ä    - dequeue -> [[r,c-1],[r,c+1],[r-1,c],[r-1,c-1],[r-1,c+1],[r+1,c],[r+1,c-1],[r+1,c+1]]
                   ¬Æ - recall (the table) from the register
                 ≈ì·ªã  - multi-dimensional index into (1-indexed & modular)
```
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 66 bytes
```
{a.=[]Moore[Integers@@__2,{Push[a,_]},cycle->1]Flat[a@_][0:3'5:8]}
```
[Try it online!](https://tio.run/##XcpNC4JAFIXhvb9iFlGbW/iREIIhBEGLwkW7y2UYpqsGouJMixB/@zQgQXR2z@FV1irdsKtElrtJ7XKka9@PjJfOcs2jKQopY5jKl2lQgaQZ9Fu3vD1GdG6VRVVIwjBLNml2oNndmB8GV8OgawrK8dnZOxt7UoYNrisQGAg/TEGIPYg9weLwz9Hi9OvY23/Jb@8dUUDkPg "Attache ‚Äì Try It Online")
I still need to implement `Moores` and `NMoore`, but I still have `Moore` which serves as an iteration function. Essentially, `Integers@@__2` creates an integer array of shape `__2` (the last two arguments) of the first `Prod[__2]` integers. This gives us the target array. Then, `Moore` iterates the function `{Push[a,_]}` over each Moore neighborhood of size `1` (implied argument), with the option to cycle each element (`cycle->1`). This adds each neighborhood to the array `a`. Then, `Flat[a@_]` flattens the `_`th member of `a`, that is, the Moore neighborhood centered around `_` (the first argument). `[0:3'5:8]` obtains all members except the center from this flattened array.
This solution, with an update to the language, would look something like this (49 bytes):
```
{Flat[NMoore[Integers@@__2,_,cycle->1]][0:3'5:8]}
```
[Answer]
# [Kotlin](https://kotlinlang.org), 88 bytes
Uses zero based indexes and outputs an 8 element list.
```
{h:Int,w:Int,i:Int->List(9){(w+i+it%3-1)%w+(h+i/w+it/3-1)%h*w}.filterIndexed{i,v->i!=4}}
```
[Try it online!](https://tio.run/##lVfbbtw2EH3XV4yNtNE6Wu3K9xi10SZoigJpAzR@6SNX4q7YSKRKUpENw9@eHl60q3Wdogkcm5KOzsyZGc5Qn5RthPyyOKK3mjPLK1orTbYWhkpVcdqoZk1lzZqGb/hVUlvbmavFwj1zj3JjWfmJ3wEhNzwvVbv4u@fGCiXNoji/vFxeJO@ErMDI6S1vmpeGfudiU69Ur02S5zms3SqtRMUa@k0pzXfPa6UqkyS/iM9cUqeMsFiRkBauaEN1RgMxcDOSSs4l37ApgERGmtteS4L3pNbeB/giSm7I9FqrHhdyQyJPkj9VTwzGrSJmTN9ysLbManGHOEgjIAlIkNSk1WDcaiDe8JZLazKSfbvi2kVPq5YaNSAGGYx5m1Z11PC1ndfO21JpyXXmLNUQOgWulLV4XeP2E7BbBzEezOQ9LplRkq0a7lIGX4GiBo4@lWprZmlQfVNtVY/P@R3ocrp16Y5qsWLwTfeGUiYBWgspLMfjLjJp1gETeDgra@LVhs8Qw3fIJb9jbddw52XXWyTp@tQ7P1yfZtEJzU3f2FFzMHuVJLQkKoiOiU4ooVOiM6JzoouELoleU7GkokiKYypOqDil4ixJVr2l1lWM6Xgp1qJEnu/BVJzRBId1AsopPS0TuqCJDayTAk93lrD@XzyJUSEsYk2CBmZomdG96l9WJDnqAVmORVicZaDA/5OM8FNkdJERgnJG6XK@YoZXiOHPIXyo@ngPcmoi1BqBPvz7@Q5y3U4NgUwS6HBanBj/b@nZjz37eUaXGb3GneUWt4y4r3qUjGzFFAmqAoClpz7z1BeJQyAQLh4B6Z8GD7Z@LD2smJheZs/9IHXfrvp8z/KJd@0iSs5czYzArZjzILk49WqPfYScnq3s4ykSXMWlV3ISNGeuNKLsk4g8HiN4nO0cKbayi52Pz/wkyR@9z7mDoBFp7BgzoIO17J5WHEHDxirmfr/yypeXRk9W2N0ZoVoQsbgF7vORg0ps3tjJQn3SD@hdR4hpCjZcXcfL9ZQ8Wjaz/yK6uYZLgeUGq/8iuMUOV7qCltiUwmYA7jNrMChcu5EKpG2ntGXSwhTaJ1ot/v7Vo5m5l9xAsFRxI/TuTdethSybvuJVMPYRBBXTFQhUV6smguDfSlQVl6NLwpt1I2zux5vfwghhDRfQjqME32h9f2sw23q2QbAHIc1BktyiN38ybm//@FZJyP/w8o0WGFJhdvLQlSwva@maEgzESWOFRbt2/fBHuWk9PEJhtkQewX60SJLFwtU7cE4uoolx6qxtOIYBhvR@o3doNPbRxmUMUJ6se4xNrTADTFr7GF7Rr9I6GZWt49rnza9ndB1KEHzhMAA7r8chFyyuRdP4ken79yBsPb7hZMfMTJxxlToSdE1vvL/xjfF@OtQCUd5wjAvwWz9HFXp7Axd0PvP497Cevp7RQ3DRE9yyT9zbVZiYQiLQcYZ5fdnW1p61gY8xcf6l94I34RBgX5odulRN38oQnFlG33sz25tO1g4bGpLjiOZdfq2y8AdvtTl97FdWs9LuXlEyVEGrqr5RLpoohTIGFole8X3np@5si0zy7Qkkj9DUK3/lca@E/e5kXsy@C/eexi0URBY2pRoiNypqkrJs9873E6CHPKd6B39O/r9V7/DPyZ@4FSXv8M9pD4qC@EUMhF34EIRHR5MY/Oac75r7J4ZW4YZ/e18Rq6r9InDwbfVsq39P0tfS5Okf84k773zd@6r3RgDGpWccXwpb49fYZh/i6c1DaH4THTq4ptNH3z9uXUupNA7E2rsSzvDukO77QsuETJnemCv6SWt2/8NHJFFubuIOA8F71q4qhgNdp91mUfIpDTnj1KFrePzlJaKHRvblob5ynWXwv4X7Pb@J2/chHV6JXWG@SpGixbBL09HwmO/pfBDZ5/mNOLg@fXz8EopX@6PvNuonuw8Cf/Z293qD9h28qoTpGuaz2mbjzo9XrhYnz5PJbjZOnoWpBx99JzQdd0zsLqE30LX35r2QPJ0dHORgEzaNKSM6pMNZ7o7OD8LmViEW6ezRP@0Qbpsepi9G2heR98WW@DC0Phf2NOQZe6973o9ZNBlpXwR8ZPA3G5nOYmo/YLDdlbxzn2kZKhpHTua/KqpphDBw18wdtcKO3o4oF5pHLC2adsrxQaGvMFSxh9y3yCxGbDR5@IZV4VsgQ1pc0iKrOYjOudg6cgPFbsZ8WKfxTzifnc2ybTj3HizRmPduFM9D3dl1Bw3nuON/I8NhbDmbBP0rKXdfLs7hUeu3JPMb0/mVhE5T6q4eY8NJ4hKVm/iF2@Zf/gE "Kotlin ‚Äì Try It Online")
[Answer]
# [Vyxal 3](https://github.com/Vyxal/Vyxal/tree/version-3), 11 bytes
```
Œ† Ä‚Å∞h·∫Ü√û»Æ1‚Åæ¬πi
```
[Try it Online!](https://vyxal.github.io/latest.html#WyIiLCIiLCLOoMqA4oGwaOG6hsOeyK4x4oG+wrlpIiwiUyIsIls0LDRdXG42IiwiMy40LjEiXQ==)
Output is sorted in footer but is not necessary to the program bytecount
input is of the form `[w,h], n`
```
Œ† Ä‚Å∞h·∫Ü√û»Æ1‚Åæ¬πi¬≠‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å™‚Äè‚Å†‚Å™‚Å™‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
Œ† Ä           # ‚Äé‚Å°range [0, w*h)
  ‚Å∞h·∫Ü        # ‚Äé‚Å¢split into chunks of given width
     √û»Æ1‚Åæ    # ‚Äé‚Å£grid neighbors with wraparound flattened by one
         ¬πi  # ‚Äé‚Å§at given index
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
]