xvi
Getting the State of a Row in the Ocean .................................................................................. 232
How the Code Works: Lines 40 to 62 ...................................................................................... 233
Creating a New Game Board ................................................................................................... 233
Creating the Random Treasure Chests ..................................................................................... 235
Determining if a Move is Valid ............................................................................................... 235
How the Code Works: Lines 64 to 91 ...................................................................................... 236
Placing a Move on the Board ............................................................................................... 236
An Algorithm for Finding the Closest Treasure Chest ............................................................ 237
The remove() List Method .................................................................................................. 240
How the Code Works: Lines 94 to 162 .................................................................................... 241
Getting the Player's Move ........................................................................................................ 241
Asking the Player to Play Again .............................................................................................. 243
Printing the Game Instructions for the Player .......................................................................... 243
How the Code Works: Lines 165 to 217 .................................................................................. 245
The Start of the Game .......................................................................................................... 245
Displaying the Game Status for the Player .......................................................................... 245
Getting the Player's Move .................................................................................................... 246
Finding a Sunken Treasure Chest ........................................................................................ 247
Checking if the Player has Won ........................................................................................... 247
Checking if the Player has Lost ........................................................................................... 248
Asking the Player to Play Again, and the sys.exit() Function.............................................. 249
Summary: Review of our Sonar Game .................................................................................... 249
Caesar Cipher ............................................................................................................................... 250
About Cryptography ................................................................................................................ 250
The Caesar Cipher .................................................................................................................... 251
ASCII, and Using Numbers for Letters ................................................................................... 253
The chr() and ord() Functions .......................................................................................... 254
Sample Run of Caesar Cipher .................................................................................................. 255
Caesar Cipher's Source Code ................................................................................................... 256