Fun with 2 dimensional math + logic

woot

New Member
Reaction score
8
Ok so here goes..


I want to create some functions (logic) for creating units on a board

lets say i have a 12x12 board..

I want to be able to select a square on the board.. and from that square create a bunch of units around it in a particular pattern.. like a diamond.. or a square

but I may or may not want to create a unit in a square that already contains a unit.. and if there is a unit in that square it should count as a blocker.. so no more squares will be created between the origin and the end of square creation (the size of the diamond or square is dependent on an integer variable that determines its max radius)

how can I go about doing this?


(further example)

A diamond with a radius of 2 (empty squares are Os.. origin square is an M, units created are Xs):

0 0 0 0 X 0
0 0 0 X X X
0 0 X X M X
0 0 0 X X X
0 0 0 0 X 0

A square with a radius of 2:

0 0 0 0 0 0
0 0 X X X X
0 0 X X X X
0 0 X X M X
0 0 X X X X

A diamond (radius 2) with a blocker (blocker is U):

0 0 0 0 X 0
0 0 0 X X X
0 0 0 U M X
0 0 0 X X X
0 0 0 0 X 0

A square (radius 2) with a blocker:

0 0 0 0 0 0
0 0 X X X X
0 0 0 X X X
0 0 0 U M X
0 0 0 X X X


This might be a little oddly explained / hard to grasp.. but if anyone can think of what to do.. let me know.. i tried out a system of recursion to create the units but it doesn't quite work right..

essentially my faulty recursion system (for blockers) goes like this..

diamond:

for however large the radius is:
- create units up, down, left, and right of the origin square (units aren't created if there are blockers / other units)
- for each unit created, create units up down left and right of the created unit, remove 1 from the radius
- RECURSE the last step until the radius is 0

square: same as diamond but instead of making units up down left right you also include diagonals


this doesn't work though, it gives weird patterns at different radius sizes that aren't diamonds/squares

Thanks all.. let me know if you have any ideas :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top