Printing Guess in the Incorrect Spot (re-opened)


#1

I still think that there's a discrepancy between the computer's and a player's interpretation of the game.

I've completed the Battleship lesson and codecademy gave me the ok to move on to the next section, but I noticed that the 'X' being printed on the board in the console window was reflective of how a computer would interpret a person's guess, and not reflective of how a person would interpret their guess.

In other words:
If a player were to enter in the guess: row 1, col 1
The computer would place an 'X' in it's row 1, col 1
The player would see an 'X' in row 2, col 2

In order to fix this problem, I think that this code:

for turn in range(4):
    guess_row = int(raw_input("Guess Row:"))
    guess_col = int(raw_input("Guess Col:"))

should be changed to subtract 1 from the player's input. This would allow the player and the computer to be talking about the same position, even though their numbering systems are not the same.

for turn in range(4):
    guess_row = int(raw_input("Guess Row:"))-1
    guess_col = int(raw_input("Guess Col:"))-1

I've found that both answers pass through codecademy (but this might just be because I entered the former code and gained clearance, before I went back and tested the latter). But I think that the former is a more correct version of the game?

https://www.codecademy.com/courses/python-beginner-en-4XuFm/2/4?curriculum_id=4f89dab3d788890003000096


#2

For this exercise the author chose to maintain normal zero-indexing. We are the only user, and since it is our code, we know what inputs are allowed. The range is set to 5 (0..4). Don't be distracted by what human's would expect. You are the user.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.