# How to make arrays of array?

**URL:** <https://discourse.julialang.org/t/how-to-make-arrays-of-array/27863>\
**Category:** General Usage\
**Created:** [August 22, 2019, 8:03pm UTC](https://discourse.julialang.org/t/how-to-make-arrays-of-array/27863 "2019-08-22T20:03:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxiumburn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxiumburn/32/10673_2.png) [@maxiumburn](https://discourse.julialang.org/u/maxiumburn)\
**Post date:** [August 22, 2019, 8:03pm UTC](https://discourse.julialang.org/t/how-to-make-arrays-of-array/27863/1 "2019-08-22T20:03:08Z")

</div>

I would like to store an Array (Tic Tac Toe Game (initialized) position 3 X 3 array of string(A = fill(“”,3,3)) in a list array. The game A gets filled with moves of X and O, so my list of game positions would have a list [A1… first board position,moves filling X and O, A2 second move (this would have all the previous moves and then A3 etc.] [[“X” “” “” ; “” “” “”; “” “” “O”], ["X “X” “”; “” “” “O”; “” “O” “O”]] …]  
How would I fill an list or array with the A1,A2 ,A3,…game positions? My code updates the previous positions which is not what I want. I tried to paste the screen snippet for the output. but I do not see it.

```julia
type or paste code 
C = []
A = fill("",3,3)

for i in 1:2

    
listgamestate = [] 
    
listpossmove= [1,2,3,4,5,6,7,8,9]

selectedmove = rand(listpossmove)
    println("selected move",selectedmove)

A[selectedmove] = "X"
#println(A)
            push!(C, A)
    println(C)

println()
    
    listpossmove = filter(x ->x!= selectedmove, listpossmove)
    
    
    
      selectedmove = rand(listpossmove)
        #println("selected move",selectedmove)
        
        A[selectedmove] = "O"
        #println("O selected",A)
        
        C = push!(C,A)
            println(C)
    listpossmove = filter(x ->x!= selectedmove, listpossmove)
end

```

 ![TiC%20tac](https://global.discourse-cdn.com/julialang/original/3X/5/c/5cd55b765a76a510e8a676cebd9ed09f41c4eaf5.png)

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [August 22, 2019, 8:16pm UTC](https://discourse.julialang.org/t/how-to-make-arrays-of-array/27863/2 "2019-08-22T20:16:39Z")

</div>

I’m not sure I follow. But, you may want something like `push!(C, copy(A))`

Also. In Julia arrays of element type `Any` are not called lists. Might cause confusion.

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [August 22, 2019, 8:43pm UTC](https://discourse.julialang.org/t/how-to-make-arrays-of-array/27863/3 "2019-08-22T20:43:25Z")

</div>

Hello and welcome!

The thing is, arrays are what is called “reference types”. That means, an array variable in fact holds only the location of the data in memory.  
So, when you say `B=A` and change _an element of_ `A`, `B` changes as well. To make a new array that holds the same elements as `A`, you must use `B = copy(A)`, as the previous commenter suggests.

Another advice is to use a `Set` datatype to store moves. Then, you can use

```julia
# the following function removes a random element from a set and returns its value
poprandom!(x::Set) = pop!(x, rand(x))

possiblemoves = Set([1:9...])

selectedmove = poprandom!(possiblemoves)
# etc...

```
