Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Cyber Battle Game
Game elements
Main Game Loop
Robot moves
Final game

Instruction

Great! We have all the helper functions we need to create the actual function for moving a robot forward.

Exercise

Create a function named move_forward(board, robot). The function should move the robot by 1 field in the direction it is facing – unless the new field is occupied by the other robot or the new field is outside the game board.

  1. Check where the robot is now.
  2. Calculate the robot's new position after moving forward.
  3. If the new position is within the board and the new position is empty (not occupied by the other robot), update the board: the new position should now be occupied by the robot, and the old position should become empty ('-').

Stuck? Here's a hint!

Use all the helper functions we've created. To insert an empty field into the board, use the following code:

board[current_row][current_column] = '-'