Package: battleships-game-pkg-oj263
Battleships GameIntroductionWelcome to the Battleships Game! This project is a Python-based implementation of the classic game Battleships, where players take turns to guess coordinates in order to sink the opponnets ships.
The game supports single-player and multiplayer against an AI opponent.
To meet the assessment criteria I have:Ensured fucntionality in single player, multiplayer and with the web interfaceTested my code using pytest and written aditional tests to cover all functions in components.py, game_engine.py and mp_game_engine.pyUsed docstrings, comments, type hinting and suitable identifier names to ensure my code is easy to understandUsed pylint to check the styling of the code
To meet the stretch goals I have:Added different options for placement algorithm in the place_battleships function. This includes a placement with random positions and orientations and a custom placement option that takes a json file as input.Added options for difficulty in the generate attack function. This includes easy, medium and hard modes.Easy: fires at a random locationMedium: If the last shot was a hit, it will attack a neighbour of the previous shotHard: looks through all previous shots that were a hit and checks if any of there neighbours have been hit, if they have then it works out the orientation and checks for valid neighbours of that orientationAdded a setup webpage to allow the user to select the difficulty and board size before being redirected to the placement page.I have generated a detailed index.html file with SphinxI have pushed to both GitHub and PyPI which can be seen below.PrerequisitesBefore you begin, ensure you have the following requirements:Python 3.11 or above. To install this, follow these steps:Go to this url: [https://www.python.org/downloads/windows/]Select downnload on the version of python you want to installRun the download installer.Flask 3.0. To install follow these steps:pip install Flaskpytest 7.4. To install follow these steps:pip install pytestpip install pytest-covpip install pytest-dependsInstallationTo install the Battleships Game, follow these steps:pip install battleships-game-pkg-oj263Or, if you have downloaded the source code:python setup.py installGetting StartedTo start playing the Battleships Game, run the following command within the battleships game directory:python game_engine.pyFor the version with an ai opponent, run this command:python mp_game_engine.pyFor the web based game with an ai opponent, run this command:python main.pythen go to this url:http://127.0.0.1:5000/setupEnter your difficulty and board size, then press submit and you will be redirected to the placement page.
Place your ships, then press send game and you will be directed to the main game page where you will play against the AI.
The first one to sink all the opponents ships is the winner.TestingTo run the tests for the Battleships Game, navigate to the project directory and run:pytestIf this command doesn't work. Try this:python -m pytestDeveloper DocumentationThe project package is seperated into four python modules:components.py - this contains all the necessary features to be used in creating and setting up the gamegame_engine.py - this contains the additional elements required to play a single player version of the gamemp_game_engine.py - this contains the additional elements required to play a multiplayer player version of the gamemain.py - this contains the the functions that handle requests to and from the server for the web interface version of the gameDetailsAuthors: N/ALicense: This project is licensed under the MIT License - see the LICENSE file for details.Acknowledgements: A special thanks to Matt Collison and all Teaching Assistants for their help.For more information and source code, please visithttps://github.com/ollyjohnson/battleships.