test-011-game.pinescript
Copy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos
//@version=4
study("test-011-game")
int msize = 8
var int[] A = array.new_int(size=msize, initial_value=0)
var int[] B = array.new_int(size=msize, initial_value=0)
var int[] C = array.new_int(size=msize, initial_value=0)
var int[] D = array.new_int(size=msize, initial_value=0)
var int[] E = array.new_int(size=msize, initial_value=0)
var int[] F = array.new_int(size=msize, initial_value=0)
var int[] G = array.new_int(size=msize, initial_value=0)
var int[] H = array.new_int(size=msize, initial_value=0)
f_xdim(_i)=>(_i==0?A:(_i==1?B:(_i==2?C:(_i==3?D:(_i==4?E:(_i==5?F:(_i==6?G:(_i==7?H:A))))))))
// populate:
pop_at_every = bar_index%21//input(3)
if barstate.islast
for _i=0 to msize-1
for _j=0 to msize-1
if (_i*_j)%pop_at_every
array.set(id=f_xdim(_i), index=_j, value=1)
//t = ''
for _i=0 to msize-1
//_ref_current_array = f_xdim(_i)
for _j=0 to msize-1
//t:= t + tostring((msize + _i - 1) % (msize)) + '\n'
int _north_cell = array.get(id=f_xdim((msize + _i - 1) % (msize)), index=_j)
int _south_cell = array.get(id=f_xdim((msize + _i + 1) % (msize)), index=_j)
int _west_cell = array.get(id=f_xdim(_i), index=(msize + _j - 1) % (msize))
int _east_cell = array.get(id=f_xdim(_i), index=(msize + _j + 1) % (msize))
//
int _sum_cells = _north_cell + _south_cell + _west_cell + _east_cell
int _current_cell = array.get(id=f_xdim(_i), index=_j)
// rules:
if _current_cell > 0
if _sum_cells > 1 and _sum_cells < 4
array.set(id=f_xdim(_i), index=_j, value=1)
else
array.set(id=f_xdim(_i), index=_j, value=0)
else
if _sum_cells == 3
array.set(id=f_xdim(_i), index=_j, value=1)
else
array.set(id=f_xdim(_i), index=_j, value=0)
// var label la = label.new(bar_index, 0.0, '')
// label.set_xy(la, bar_index, 0.0)
// label.set_text(la, t)
//
plot(series=array.get(id=A, index=0) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-7, show_last=1)
plot(series=array.get(id=A, index=1) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-6, show_last=1)
plot(series=array.get(id=A, index=2) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-5, show_last=1)
plot(series=array.get(id=A, index=3) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-4, show_last=1)
plot(series=array.get(id=A, index=4) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-3, show_last=1)
plot(series=array.get(id=A, index=5) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-2, show_last=1)
plot(series=array.get(id=A, index=6) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-1, show_last=1)
plot(series=array.get(id=A, index=7) > 0 ? 1.0 : 0.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=0.0, offset=-0, show_last=1)
plot(series=array.get(id=B, index=0) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-7, show_last=1)
plot(series=array.get(id=B, index=1) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-6, show_last=1)
plot(series=array.get(id=B, index=2) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-5, show_last=1)
plot(series=array.get(id=B, index=3) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-4, show_last=1)
plot(series=array.get(id=B, index=4) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-3, show_last=1)
plot(series=array.get(id=B, index=5) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-2, show_last=1)
plot(series=array.get(id=B, index=6) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-1, show_last=1)
plot(series=array.get(id=B, index=7) > 0 ? 2.0 : 1.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=1.0, offset=-0, show_last=1)
plot(series=array.get(id=C, index=0) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-7, show_last=1)
plot(series=array.get(id=C, index=1) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-6, show_last=1)
plot(series=array.get(id=C, index=2) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-5, show_last=1)
plot(series=array.get(id=C, index=3) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-4, show_last=1)
plot(series=array.get(id=C, index=4) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-3, show_last=1)
plot(series=array.get(id=C, index=5) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-2, show_last=1)
plot(series=array.get(id=C, index=6) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-1, show_last=1)
plot(series=array.get(id=C, index=7) > 0 ? 3.0 : 2.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=2.0, offset=-0, show_last=1)
plot(series=array.get(id=D, index=0) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-7, show_last=1)
plot(series=array.get(id=D, index=1) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-6, show_last=1)
plot(series=array.get(id=D, index=2) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-5, show_last=1)
plot(series=array.get(id=D, index=3) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-4, show_last=1)
plot(series=array.get(id=D, index=4) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-3, show_last=1)
plot(series=array.get(id=D, index=5) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-2, show_last=1)
plot(series=array.get(id=D, index=6) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-1, show_last=1)
plot(series=array.get(id=D, index=7) > 0 ? 4.0 : 3.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=3.0, offset=-0, show_last=1)
plot(series=array.get(id=E, index=0) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-7, show_last=1)
plot(series=array.get(id=E, index=1) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-6, show_last=1)
plot(series=array.get(id=E, index=2) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-5, show_last=1)
plot(series=array.get(id=E, index=3) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-4, show_last=1)
plot(series=array.get(id=E, index=4) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-3, show_last=1)
plot(series=array.get(id=E, index=5) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-2, show_last=1)
plot(series=array.get(id=E, index=6) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-1, show_last=1)
plot(series=array.get(id=E, index=7) > 0 ? 5.0 : 4.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=4.0, offset=-0, show_last=1)
plot(series=array.get(id=F, index=0) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-7, show_last=1)
plot(series=array.get(id=F, index=1) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-6, show_last=1)
plot(series=array.get(id=F, index=2) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-5, show_last=1)
plot(series=array.get(id=F, index=3) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-4, show_last=1)
plot(series=array.get(id=F, index=4) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-3, show_last=1)
plot(series=array.get(id=F, index=5) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-2, show_last=1)
plot(series=array.get(id=F, index=6) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-1, show_last=1)
plot(series=array.get(id=F, index=7) > 0 ? 6.0 : 5.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=5.0, offset=-0, show_last=1)
plot(series=array.get(id=G, index=0) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-7, show_last=1)
plot(series=array.get(id=G, index=1) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-6, show_last=1)
plot(series=array.get(id=G, index=2) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-5, show_last=1)
plot(series=array.get(id=G, index=3) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-4, show_last=1)
plot(series=array.get(id=G, index=4) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-3, show_last=1)
plot(series=array.get(id=G, index=5) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-2, show_last=1)
plot(series=array.get(id=G, index=6) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-1, show_last=1)
plot(series=array.get(id=G, index=7) > 0 ? 7.0 : 6.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=6.0, offset=-0, show_last=1)
plot(series=array.get(id=H, index=0) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-7, show_last=1)
plot(series=array.get(id=H, index=1) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-6, show_last=1)
plot(series=array.get(id=H, index=2) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-5, show_last=1)
plot(series=array.get(id=H, index=3) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-4, show_last=1)
plot(series=array.get(id=H, index=4) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-3, show_last=1)
plot(series=array.get(id=H, index=5) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-2, show_last=1)
plot(series=array.get(id=H, index=6) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-1, show_last=1)
plot(series=array.get(id=H, index=7) > 0 ? 8.0 : 7.0, title='', color=color.blue, style=plot.style_columns, transp=20, histbase=7.0, offset=-0, show_last=1)
Show all 122 lines