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
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?”
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.
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:
It’s a kids game, so have fun with this!
Find the Mathcad Community Challenge Guidelines here!
@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.
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.
Furthermore if a ship is sunk the appropriate info is also displayed and additionally the ship is framed with an orange border.
The cheat mode also shows borders around the ship if verbose mode is on:
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.
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).
yay
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.
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,
Edited to add:
It's just that I was thinking of adding a little historicity to the proceedings.
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.
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)
Happy Birthday in advance, and here's a little birthday present ...
.
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)
...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.
