vendredi 5 novembre 2021

PHP - interactive grid movement trough cells

I am trying to make a plan from which I will code desired output in PHP.

I have a grid with like "grid": {"length": 5, "breadth": 5} with x and y coordinates with set of operations:

  • L - turn left 90 degrees

  • R - turn right 90 degrees

  • F - move forward 1 square

As a person moves through the grid, if they happen to move through a cell which is marked, every subsequent cell they enter will end up being marked.

  • X - marked cells

  • 0 - unmarked cells

Marked cells on the start would be:

[{"x": 1, "y": 1}, {"x": 2, "y": 3}]

and initial position of the two persons start is:

{"initialPosition": "1 0 N", "movement:" "FFRFFRF"},

{"initialPosition": "1 3 S", "movement": "LFFLFRFRFF"}

Expected output would be:

OOOXX

OOXXX

OXXXX

OXOXO

OOOOO

This is my mock up: IMAGE

Also, maybe suggestion what is the best approach to accomplish this in PHP while using OOP concepts, abstractions, design patterns etc..

This is not basic coding so I would appreciate some help.

Aucun commentaire:

Enregistrer un commentaire