So in this video, 4 purple hats drone place block representing a bit string eg. '110011" and 1 reader drone read it and print it out
red indicate 1 while green indicate 0
the bottom most column represent area reserve for flag
these are the flag
green -> not written yet -> reader can skip reading the bits
blue -> writting -> reader can skip reading the bits
red -> written -> reader has to read
Here is the code
def topos(x,y):
`cy = get_pos_y()`
`cx = get_pos_x()`
`while(cx != x):`
`if(cx > x):`
`move(West)`
`else:`
`move(East)`
`cx = get_pos_x()`
`while(cy != y):`
`if(cy > y):`
`move(South)`
`else:`
`move(North)`
`cy = get_pos_y()`
def writer_job(args):
`change_hat(Hats.Purple_Hat)`
`col = args[0]`
`nflip = args[1]`
`bit = args[2]`
`for i in range(0,nflip):`
`do_a_flip()`
`topos(col,0)`
`place(Grounds.Block_Blue) # this tell reader that , the drone is writting`
`for j in range(0,len(bit)):`
`topos(col,2 + j) # writting field start at j = 2`
`if(bit[j] == '1'):`
`place(Grounds.Block_Red)`
`topos(col,0)`
`dig()`
`place(Grounds.Block_Red)`
`return`
def reader_job(args):
`change_hat(Hats.Green_Hat)`
`print("Hello, i am a reader drone")`
`num_writer_drone = args[0]`
`ex,ey = args[1]`
`bit_string_length = args[2]`
`bits = []`
`num_has_not_read = num_writer_drone`
`# bit prefill with 0`
`for d in range(num_writer_drone):`
`tmp = []`
`for b in range(bit_string_length):`
`tmp.append(0)`
`bits.append(tmp)`
`while(num_has_not_read != 0):`
`for i in range(0,num_writer_drone):`
`topos(i,0)`
`if(get_ground_type() == Grounds.Block_Green): # drone i is not writting yet`
continue
`if(get_ground_type() == Grounds.Block_Blue): # Writting but not finished`
continue
`if(get_ground_type() == Grounds.Block_Red): # finished writting -> read`
for j in range(0,bit_string_length):
topos(i,2 + j) # writting field start at j = 2
if(get_ground_type() == Grounds.Block_Red):
# read as 1
bits[i][j] = 1
#else 0 but we dont have to assign that cuz we prefil with 0 before hand
num_has_not_read = num_has_not_read - 1
topos(i,0)
dig()
`topos(ex,ey)`
`for d in range(num_writer_drone):`
`bit_str = ''`
`for b in range(bit_string_length):`
`bit_str = bit_str + str(bits[d][b])`
`message = "Drone " + str(d) + " wrote " + bit_str`
`move(South)`
`print(message)`
ws = 10
bit_string_length = 6
num_writer_drone = 4
set_world_size(10)
for i in range(0,num_writer_drone):
`topos(i,0)# reserve for flag`
`dig() # you need dlc for this`
`place(Grounds.Block_Green)`
`for j in range(2,2 + bit_string_length):`
`topos(i,j)# reserve for bit information`
`dig() # you need dlc for this`
`place(Grounds.Block_Green)`
bits = ["110011","101010","100010","001100"] # message for each writer drone to write
writer_drones = []
num_flips = [1,6,2,8]
topos(8,0)
reader_args = []
reader_args.append(num_writer_drone)
ex,ey = 6,6
reader_args.append((ex,ey)) # position where to print result
reader_args.append(bit_string_length)
reader_drone = spawn_drone(reader_job,reader_args)
topos(0,0)
do_a_flip()
do_a_flip()
for i in range(0,num_writer_drone):
`topos(i,0)`
`writer_args = []`
`writer_args.append(i) # assigning columns`
`writer_args.append(num_flips[i])`
`writer_args.append(bits[i])`
`writer_drones.append(spawn_drone(writer_job,writer_args))`
for w_drone in writer_drones:
`wait_for(w_drone)`