# Presenting: Salvo!

**URL:** <https://forum.makecode.com/t/presenting-salvo/199>\
**Category:** Arcade\
**Tags:** featured-game, game\
**Created:** [May 24, 2019, 5:10am UTC](https://forum.makecode.com/t/presenting-salvo/199 "2019-05-24T05:10:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [May 24, 2019, 5:10am UTC](https://forum.makecode.com/t/presenting-salvo/199/1 "2019-05-24T05:10:53Z")

</div>

This week, I offer to you: Salvo! This probably will be my last game for a while. I do need to start writing the course. 😃 Mad props to one of my best friends, Solar, for drawing some amazing ships for me. Have fun!

> **[salvo](https://robo-technical-group.github.io/salvo/)**
>
> Salvo for MakeCode Arcade

Play-through video:

[http://somup.com/cqhufNnEiW](http://somup.com/cqhufNnEiW)

Use the following URL to import the code into MakeCode Arcade: [https://github.com/robo-technical-group/salvo](https://github.com/robo-technical-group/salvo)

Multiplayer is local; JACDAC is not currently supported. ~~Hardware _hates_ this game right now. I’ll open a separate thread on that.~~ It works on hardware, now, too! (URL has been updated with version 2.1.)

More info on the to-do list in a later comment.

## Rules

If you are familiar with Milton Bradley’s Battleship, then Salvo! will be familiar to you. Players first place their fleet on their own boards. Then, in each round, players select locations on opponents’ boards to send torpedoes.

In each round, a player can fire as many torpedoes as there are ships in the fleet. Each player starts with seven ships, so players start with seven torpedoes per round.

When a player’s torpedo hits an opponent’s ship, the hit is registered with _all_ players. Similarly, when a ship is sunk, _all_ players will know about it.

The game ends when one player has eliminated all others, or when no players have ships remaining. (Yes, a draw _is_ possible.)

Players should keep their fleet locations secret. Shot selection also should be done in secret, although players can form alliances if they wish. Thus, when there are multiple human players, each player should be permitted privacy when operating the game.

## Fleet Configuration

### Standard Salvo Fleet

| Quantity | Ship | Size |
| --- | --- | --- |
| 1 | Aircraft Carrier | 5 |
| 1 | Battleship | 4 |
| 1 | Cruiser | 3 |
| 2 | Destroyer | 2 |
| 2 | Submarine | 1 |

## TODO

- [] Improve the AI (refer to function `takeAiTurn`).
- [] Allow for randomized turn order each round (refer to function `setTurnOrder`).
- [] Allow player to select fleet type used in the game.
  - [] Add an option screen.
  - [] Modify global variable `fleetStyle`.

- [] Add JACDAC support.
- [] Allow players to choose a randomized fleet placement (difficult).
- [X] Add legend to shot selection screen. (Done - version 1.0.)
- [X] Give option to show player boards at the end of the game. (Done - version 1.0.)

## For compatibility with MakeCode Arcade home page

> **[salvo](https://arcade.makecode.com/09229-95407-17958-51273)**
>
> Originally a pencil-and-paper game, Salvo! is the precursor to Milton Bradley’s Battleship. In this version for MakeCode Arcade, up to four players can participate, with any combination of human and computer players.

* * *

I’ll edit this post as updates occur.

[See all of my MakeCode Arcade games and extensions here!](https://sites.google.com/site/akulcsarsite/makecode/makecode-arcade)

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [May 24, 2019, 6:50am UTC](https://forum.makecode.com/t/presenting-salvo/199/2 "2019-05-24T06:50:16Z")

</div>

So, I’m thinking that advanced students can take this game and make improvements, using the to-do list for inspiration.

The AI is intentionally dumb in this game. It just fires random shots. Modify the `takeAiTurn` function found in `main.ts` to make the AI more intelligent. Some ideas are provided in comments in that function.

A really easy one is to modify the turn order each round. Simply modify the `setTurnOrder` function in `main.ts` to do so. You could rotate turn order, randomize the turn order each round, set the turn order based on the number of ships remaining, or anything else that your heart desires. 🙂 Turn order doesn’t carry that much importance with the current gameplay - although you could alter the gameplay a bit to make the turn order more significant.

With the current structure for a round, players launch their torpedoes simultaneously at the end of the round, and then the results are presented on the summary screen. A challenging alteration to the gameplay would be to assess the shots at the end of each player’s turn, registering hits to everyone at that time, which would make turn order more significant (since a hit scored by the first player would be known by the second player to take a turn in that round).

Another alteration is to allow the players to select the fleet type used in the game. Add a new screen to the `OptionScreenCollection` object, and then save the setting to the `fleetStyle` variable (both found in `main.ts`). This requires students to read and then use an API - a skill that we all use every day. Two alternate fleet styles are already built into `custom.ts`: “classic” and “modern,” which use fleet configurations from the Battleship board game.

JACDAC and randomized fleet placement are pretty difficult. Actually, the implementation of randomized fleet placement would be rather straightforward; the AI already uses randomized placement. Incorporating it into the current UI, though, would be a bit more challenging, since all six buttons are already used when placing the fleet. Maybe use @jwunderl’s excellent button combination extension? Or add a prompt ahead of time? Up to you. 🙂

Just some ideas. Feel free to take this game and run with it. Most importantly, have fun! Happy Friday and, for those of us in the U.S., have a great Memorial Weekend!

---

<div class="post-metadata">

**Author:** ![frank\_schmidt](https://avatars.discourse-cdn.com/v4/letter/f/7993a0/32.png) [@frank\_schmidt](https://forum.makecode.com/u/frank_schmidt)\
**Post date:** [May 24, 2019, 1:23pm UTC](https://forum.makecode.com/t/presenting-salvo/199/3 "2019-05-24T13:23:17Z")

</div>

This gives us a tremendous amount to work with, Alex ! I do not have any students at present working at this level of computing knowledge but to just be able to show what they could learn .

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [May 25, 2019, 11:38pm UTC](https://forum.makecode.com/t/presenting-salvo/199/4 "2019-05-25T23:38:08Z")

</div>

We have this working on hardware, now, too! Game URL updated above. ~~Before downloading to your hardware, be sure to set the `HARDWARE` flag to `true` in `main.ts` (line 52).~~ As of version 1.4, this is no longer necessary, as the flag is now set automatically.

Many thanks to Joey (@jwunderl) for the assistance! (For version 1.4, thanks, too, to @mmoskal!)

---

<div class="post-metadata">

**Author:** ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)\
**Post date:** [August 23, 2019, 8:36pm UTC](https://forum.makecode.com/t/presenting-salvo/199/5 "2019-08-23T20:36:04Z")

</div>

@AlexK could you update salvo and rename the “settings” variable to something else? It seems that it is clashing with a new package for storing data on the device.

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [August 24, 2019, 2:37am UTC](https://forum.makecode.com/t/presenting-salvo/199/6 "2019-08-24T02:37:26Z")

</div>

Yup! Already did that for Lemonade Stand; forgot about that for Salvo. I’ll upload a new version of both games this weekend that is compatible with beta.

Thanks for the heads-up!

---

<div class="post-metadata">

**Author:** ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)\
**Post date:** [September 9, 2019, 5:52pm UTC](https://forum.makecode.com/t/presenting-salvo/199/7 "2019-09-09T17:52:35Z")

</div>

@AlexK we are ready to upgrade the beta. Is your upgrade ready?

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [September 9, 2019, 8:23pm UTC](https://forum.makecode.com/t/presenting-salvo/199/8 "2019-09-09T20:23:36Z")

</div>

Yup! URL updated.

Thanks for updating the settings to allow me to edit. 🙂
