cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Translate the entire conversation x

Mathcad Community Challenge November 2025 - You Sank My Battleship!

DaveMartin
16-Pearl

Mathcad Community Challenge November 2025 - You Sank My Battleship!

Recently, I was in the position of trying to explain to a 6- and 8- year old how to play the board game Battleship. (Kids from my generation had commercials that seemed to explain the basics of the game fairly well.) While trying to explain the concept of the grid to them and search algorithms, I couldn’t help but wonder, “How could this be done in Mathcad Prime?”

 

BB61_USS_Iowa_BB61_broadside_USN.jpg

 

This month’s challenge, should you choose to accept it, is fairly open-ended: simulate various aspects of the Battleship game in Mathcad. Here are some suggestions:

 

  • Write a program that will place the ships on the ocean grid. The ships must be placed horizontally or vertically; no diagonals. Ships can’t overlap one another. Do you place the ships randomly or according to some kind of optimized algorithm?

  • Alternatively, can you use Advanced Input Controls to allow the user to place the ships on the ocean grid?

  • Display the placement of the ships using the plotting capability.

  • Write an algorithm for hunting the ships. Do you use something like a random walk? A standard grid search? Your own preferred algorithm from when you were a kid?
  • Alternatively, use Advanced Input Controls to let the user enter their own coordinates. Use these same controls to provide feedback to the user on hit or miss. (Note: David Newman and I discussed whether you could use Advanced Input Controls for the user to enter guesses and have Mathcad keep track of previous shots. David said that it doesn't work like that. I thought you could append new guesses to an existing matrix; if that doesn't work, I think the brain power we have in the community can figure out a way. That have surprised me before.)
  • Display the hits and misses on a plot or chart.

  • Can you program Mathcad Prime to run through a number of iterations of placing and hunting ships, and then evaluate statistics on number of shots needed to sink the fleet?

Again, these are just suggestions. Feel free to create a worksheet that tackles any aspects of the classic board game. Do as little or as much as you like. Also, your worksheet should stand on its own; a stranger should be able to open it and understand what it’s for.

For the sake of this challenge, we will use the following ships:

  • Aircraft carrier 5
  • Battleship 4
  • Cruiser 3
  • Submarine 3
  • Destroyer 2

It’s a kids game, so have fun with this!

 

Find the Mathcad Community Challenge Guidelines here!

 

 

Dave Martin - dmartin@creowindchill.com - https://www.mcaeconsulting.com
71 REPLIES 71
StuartBruff
23-Emerald IV
(To:DJNewman)


@DJNewman wrote:

Full confession: I recalculated until I got 100, just for the screenshot.


I hope you wrote a Mathcad program to do the recalculations ...

Nope, manually, but I got it within 5 refreshes.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Werner_E
25-Diamond I
(To:DaveMartin)

In the version of the game I posted a few days ago was an error in the function which places a ship in the game board which prevented ships from using part of the upper half of the board and the rightmost column.

Since I am therefore forced to provide an error-corrected version, I took the opportunity to implement an additional “verbose” mode.
When this is activated, the program also provides information about which ship was hit when a hit occurs.

Werner_E_0-1762498046289.png

Furthermore if a ship is sunk the appropriate info is also displayed and additionally the ship is framed with an orange border.

Werner_E_1-1762498189496.png

The cheat mode also shows borders around the ship if verbose mode is on:

Werner_E_2-1762498364566.png

 

I wished I would have planned the verbose mode right from the start as I sure would have written the sheet in a different way and probably would have turned more calculations into functions. But, alas, that's just how things are...

 

EDIT: I made a minor change and therefore replaced the file. In verbose mode, the ship overview now also shows how many parts of a ship have already been hit. However, the display is not an indicator of which parts have been hit.

Werner_E_2-1762541372629.png

 

Prime 11 file attached

EDIT (20251111): Just noticed that in the attached file the playing field was slightly compressed vertically and did not match the vertical slider. So a new file was attached (no other changes made).

 

mathcad-community-challenge-november-2025-werner-43-shots.png

yay

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Werner_E
25-Diamond I
(To:DJNewman)

I guess that 43 shots with verbose (and of course cheat) set to off is pretty good!

However, I don't have any comparative values of my own. I have to admit that I found using two sliders and an additional button too cumbersome to play through the game completely.

I wanna make a video showing off the different modes but I gotta also get used to the control scheme so it's not too labourious to get through and I can present it as at least... somewhat smooth.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Werner_E
25-Diamond I
(To:DJNewman)

Just downloaded the file I had attached and noticed that the board was compressed vertically. That's not seen in the screenshot you showed so I guess you fixed it.

Have attached a corrected file in my post above.

For a video I guess its more to see if verbose mode is on. And its a bit easier for a human player, too, which may means fewer shots and so also a less boring video.

Of course you could use the cheat mode before starting the video so you have full control over the number of shots needed 😉


@DaveMartin wrote:

For the sake of this challenge, we will use the following ships:

  • Aircraft carrier 5
  • Battleship 4
  • Cruiser 3
  • Submarine 3
  • Cruiser 2

Dave, can I just confirm - is that list of ships definitive, ie one and only one of each 'ship'?  Or would it be fair to say, 

 

6b64f77f964a559512daaf65b4340e28

 

Edited to add:

 

It's just that I was thinking of adding a little historicity to the proceedings.

 

2025 11 07 B.png

 

Clearly not totally accurate.  For example, Campbeltown took the St Nazaire docks up with her during Operation Chariot, and I don't think Yamato is due for her afterlife upgrade for another 174 years. 

 

Stuart

I think of the challenges more like Dr. Peter Venkman in Ghostbusters: it's more of a guideline than a rule.

 

They are more like loose parameters. As we have seen many times before, people explore tangents that they find interesting. And I think that's great. It's not about coming up with a specific answer; it's more in the way that people use the tools in Mathcad Prime to approach different problems.

 

Dave Martin - dmartin@creowindchill.com - https://www.mcaeconsulting.com

Realising that you called the two-piece a "Cruiser" and not "Destroyer" in the opening post; edited that to fix it. That's probably why I couldn't remember the names of the pieces while I was recording me playing these. 😞

 

Also yeah let's extend the submissions to December 13 as a birthday gift to me. 🙂

 

(There won't be a December 2025 Mathcad Minute anyway, our target for the write-up being published is late December [hardly likely] or early January 2026)

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
StuartBruff
23-Emerald IV
(To:DJNewman)

Happy Birthday in advance, and here's a little birthday present  ...

 

2025 11 13 A.png.

 

Although I'm not sure it's a very good birthday present, installing your namesake ship as something that somebody will be hoping to pound into scrap.  Still, you're in good company.

 

Stuart

 

(Hopefully, that will give me time to complete my game proposal - it seems as if I'm enjoying a recurrence of long-term, intermittent dreaded lurgi, which is slowing things down a bit)

 

https://en.wikipedia.org/wiki/USS_Newman

...oh yeah, I guess this ends this week. December 13 seemed so far away...

 

Anyway, it'd be awesome to see last-minute entries / revisions / discussion.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Announcements

Top Tags