...

/

Battle of the Robots

Battle of the Robots

Let's take a look at what we have learned so far by making a simple game.

Problem statement

Let’s build a simple game together, to sum up, all information that we have gathered from the previous chapters. We’ll have 20 robots and two teams, with 10 robots in each team. Each team will be represented by its array, with a size of 10. Each element, or cell, of the array may have only one of these two values:

  1. 0 when the robot is destroyed.
  2. 1 when the robot is still alive.

Define two arrays. 1 in the example below indicates that we defined an array with robots who are still alive

arr1 = Array.new(10, 1)
arr2 = Array.new(10, 1)

Each team will attack one after the other. But what does it mean “to attack” in this case? If 1 in the array represents a robot that is alive, and 0 signifies a dead robot, then “to attack” means to "change the value for a certain cell in the array from 1 to 0.” But which cell are we going to attack? We have ...