Skip to content

Commit

Permalink
Change names
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Jan 17, 2024
1 parent 00bfddb commit 07dc496
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions exercises/practice/robot-simulator/.meta/example.gd
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
var _position: Vector2i
var _direction: String
var current_position: Vector2i
var current_direction: String
var allowed_directions = ['north', 'east', 'south', 'west']

func _init(position: Vector2i = Vector2i(0, 0), direction: String = 'north'):
_position = position
_direction = direction
current_position = position
current_direction = direction


func move(instructions: String):
for instruction in instructions:
match [instruction, _direction]:
match [instruction, current_direction]:
['L', _]:
var index = allowed_directions.find(_dir) - 1
_direction = allowed_directions[index]
var index = allowed_directions.find(current_direction) - 1
current_direction = allowed_directions[index]
['R', _]:
var index = allowed_directions.find(_dir)
var index = allowed_directions.find(current_direction)
index = (index + 1) % 4
_direction = allowed_directions[index]
current_direction = allowed_directions[index]
['A', 'north']:
_position += Vector2i(0, 1)
current_position += Vector2i(0, 1)
['A', 'south']:
_position += Vector2i(0, -1)
current_position += Vector2i(0, -1)
['A', 'east']:
_position += Vector2i(1, 0)
current_position += Vector2i(1, 0)
['A', 'west']:
_position += Vector2i(-1, 0)
current_position += Vector2i(-1, 0)

0 comments on commit 07dc496

Please sign in to comment.