Workshop › Battleship › Step 25 of 35
The computer stops guessing at random: it shoots the square with the highest heat.
```js
function computerShoots() {
const heat = heatMap()
let bestCell = null
for (let r = 0; r < N; r++) {
for (let c = 0; c < N; c++) {
if (!bestCell || heat[r][c] > heat[bestCell.r][bestCell.c]) bestCell = { r, c }
}
}
const result = fire(myFleet, theirShots, bestCell.r, bestCell.c)
```bestCell remembers the hottest square seen so far; it starts empty (null).In computerShoots, replace everything from let r to the fire(...) line with the new lines.
Skills: Loops
← A heat map Hunt around a hit →