Skip to content

Battleship Cog Causes IndexError #563

@HassanAbouelela

Description

@HassanAbouelela

Description

The battleship cog runs into an error when given lowercased input. An IndexError is caused when trying to get the matching letter from the list of letters. The bot quits the game with the error:

An error occurred. Game failed

Steps to Reproduce

  1. Start a game of battleship
  2. Send a DM containing any spot in lowercase on your turn (example: a1)
  3. The bot sends the failure message in the commands channel, the index error is raised to console

Expected Behaviour

The bot should be able to convert between upper and lower case.

Actual Behaviour

The bot errors out on lower case. Error:

File "./sir-lancebot/bot/exts/evergreen/battleship.py", line 146, in get_square
     return grid[number-1][index]  # -1 since lists are indexed from 0
IndexError: list index out of range

Possible Solutions

You could try converting from lower to uppercase.

Additionally, you can add a try/except around the input section, to report invalid input and stop the bot from failing the game.

Would you like to implement a fix?

Note: For high-priority or critical bugs, fixes may be implemented by staff.

  • I'd like to implement the bug fix
  • Anyone can implement the bug fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: backendRelated to internal functionality and utilitiesgood first issueGood for newcomersstatus: approvedThe issue has received a core developer's approvaltype: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions