games · MIT License
Overview
A one-player Battleship game on a 5 by 5 grid: find three hidden ships by row and column before you run out of 10 misses.
- Owner-tested on a TI calculator
- Version 1.0.0
- 1898 bytes
- Uses random
Tried it? Did this program work on your calculator?
Before you run it
- TI-84 Plus CE Python · No calculator OS or Python App version has been verified.
- TI Connect CE .py transfer to the Python App; the owner's transfer details were not recorded
- Three ships, 3, 2, and 2 squares long, are hidden at random on a 5 by 5 grid for every game, across or down.
- Ships never overlap but may touch each other.
- A shot is typed as row,col with whole numbers from 1 to 5, such as 2,3.
Play it here first
Play a full round right here before you download. The screen below runs the same steps as the calculator game: type your answer in the box under it and press Enter, just as you would on the calculator. Each round picks a new secret, and nothing you type is saved.
TI-84 Plus CE Python · screen preview
How to play
How to play Battleship
About the game
The calculator hides three ships on a 5 by 5 grid: one 3 squares long and two 2 squares long. Each ship lies in a straight line, across or down. Fire at squares by row and column to find all 7 ship squares.
You can miss 10 times. Sink every ship before the tenth miss to win; run out of misses and the game is over. Ships never overlap, but they can touch each other.
Controls
row,col- fire at a square: the row number, a comma, then the column number, such as 2,3
Q- quit the game
enter- fire, or move on from a result screen
Y- play another game; any other answer ends the program
How to play
- Press enter at the opening screen. The grid shows rows 1 to 5 down the side and columns 1 to 5 across the top.
- Type a row and column, such as 2,3, and press enter.
- The calculator says HIT! or MISS! and how many misses you have left. Press enter to see the grid again: X marks a hit and o a miss.
- Keep firing until all 7 ship squares are hit (ALL SHIPS SUNK!) or you reach your tenth miss (OUT OF MISSES!).
- After each game the grid and your wins and losses are shown. Type Y to play again.
Tips
- After a hit, fire at the squares directly above, below, left, and right of it. Ships are straight, so a second hit tells you which way the ship runs.
- The game never says when a single ship sinks. Keep count: the ships cover 3 + 2 + 2 = 7 squares.
- Because ships can touch, a line of hits longer than 3 means two ships are side by side.
- Firing at a square you already tried, or outside the grid, does not cost a miss. The calculator just tells you and lets you fire again.
Good to know
- The win and loss totals start over each time you run the program.
- Typing Q ends the program straight away, without counting the game.
- To stop the game at any time, press the [on] key. The Python App returns to the shell.
Exact reviewed bytes
Source code
# DuckieDai(TM) Battleship# TI-84 Plus CE Pythonfrom random import randintdef clear():print('\n'*8)def intro():print('DUCKIEDAI(TM)')print('BATTLESHIP')print(' __')print(' ___(o )> quack!')print(' \\ <_. )')print(" `---'")print('by DuckieDai')print('hiddenwordscanner.com')input('Press Enter ')clear()def ships():used=[]for size in (3,2,2):while 1:d=randint(0,1)r=randint(0,4-(size-1)*(1-d))c=randint(0,4-(size-1)*d)cells=[]for i in range(size):cells.append((r+i*(1-d),c+i*d))if all(p not in used for p in cells):used+=cellsbreakreturn useddef board(fired):print(' 1 2 3 4 5')for r in range(5):s=str(r+1)+' 'for c in range(5):s+=fired.get((r,c),'.')+' 'print(s)def play():wins=0losses=0limit=10while 1:target=ships()fired={}hits=0misses=0quitgame=Falsewhile hits<7 and misses<limit:clear()print('HITS',hits,'/7 MISS',misses,'/10')board(fired)print('X=hit o=miss')s=input('Row,col? (q=quit) ')if s.lower()=='q':quitgame=Truebreaktry:a,b=s.split(',')r=int(a)-1c=int(b)-1if r<0 or r>4 or c<0 or c>4:msg='Use 1 to 5'elif (r,c) in fired:msg='Already fired!'elif (r,c) in target:fired[(r,c)]='X'hits+=1msg='HIT!'else:fired[(r,c)]='o'misses+=1msg='MISS!'except:msg='Enter row,col'clear()print(msg)print('Misses left:',limit-misses)input('Press Enter ')if quitgame:breakclear()if hits==7:print('ALL SHIPS SUNK!')print('QUACK QUACK!')wins+=1else:print('OUT OF MISSES!')losses+=1print('Wins:',wins,'Losses:',losses)board(fired)input('Press Enter ')clear()if input('Again? Y/N ').upper()!='Y':breakclear()print('DuckieDai(TM)')print('hiddenwordscanner.com')intro()play()
- Filename
BATTLE.py- Size
- 1898 bytes
- SHA-256
c917be46318cdd68df1803e9fe2d7f99c15f3ceee07b97b0986b7f2b03eae8d5
Usage
Inputs
- A shot as row,col, such as 2,3
- Q to quit the game
- Y to play again, anything else to stop
Outputs
- The grid with X for hits and o for misses, with hits out of 7 and misses out of 10
- HIT or MISS after each shot, with the misses left
- ALL SHIPS SUNK or OUT OF MISSES, then the win and loss totals
Units: Grid squares; no units.
Assumptions and limitations
Assumptions
- Three ships, 3, 2, and 2 squares long, are hidden at random on a 5 by 5 grid for every game, across or down.
- Ships never overlap but may touch each other.
Constraints
- A shot is typed as row,col with whole numbers from 1 to 5, such as 2,3.
- A shot outside the grid, at a square already fired on, or typed another way does not count as a miss.
Known failures
- The game does not say when a single ship has sunk; it counts hits up to 7.
- The win and loss totals reset when the program is started again.
Compatibility and review
- Review status
- Owner-tested on a TI calculator
- Tested on
- Owner reports personally playing this game on a TI-84 Plus CE Python calculator; the test date, OS version, and Python App version were not recorded
- What happened
- Owner reported pass on the calculator. The file is published exactly as provided; this exact file has not yet been rerun on a calculator.
- Dependencies
- random
- Suggested calculator name
BATTLE— you can give it another valid, unique name when you transfer it- Desktop test cases
- Not available for this interactive-only source
This exact source auto-launches an interactive calculator session, so compatibility evidence comes from the recorded physical-device review rather than an importable desktop fixture.
Transfer and launch
Download the .py file, send it to your calculator with TI Connect CE as BATTLE or another name, then open the Python App and start a game. Press [on] to stop at any time. This release has no verified calculator OS or Python App version; treat transfer and execution as unverified until independently tested.
Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.
Version history
- 1.0.0 — current version, published . Download this reviewed version
Related learning
Enjoying a DuckieDai game? Every game and program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.
Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.
Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.