Package: battleships-edf1101
ECM1400 BattleshipsIntroductionA python package (availible on PyPi) to simulate a Battleships game against an AI in both a command line interface and a Flask GUI.Coursework Self assessmentAll features required by specification are complete (including testing & logging). Note: main.py uses classes to avoid global
variables.ExtensionsEntry ScreenUsers can select game settings (size, difficulty, storm mode) on an Entry page.
main.html now has a menu button so games can be replayed.HTML Template Sunken shipsSunken ship positions for either the AI or Player to the HTML code, and it colours those tiles green.Storm modeWhen activated, the player's board shifts one space each turn (as suggested by specification). Since the main.html's grid
isn't persistent this had to be in javascriptPackagingPackaged with PyPiDetailed documentation from sphinxAI attackingThere are 5 difficultiescode here0. Pure Random GuessingRandom but it won't guess same space twiceGuessing a random position around hits where the ship is still unsunk. If no unsunk hits it guesses randomlyGuesses in a line following unsunk hits (more accurate method)Guesses in a line if there are unsunk hits, if not it calculates all possible ship placements in the board
given what's already guessed. Then chooses the tile that has the highest probability of a shipWrotea scriptto score AIs against themselves.PrerequisitesFlask must be installedpip install Flasknumpy must be installedpip install numpyFor testing pytest must be installedpip install pytestPytest plugins must be installedpip install pytest-dependspip install pytest-covPython version must be ≥ 3.10 (pip package requires ≥ 3.11) due to|symbol in typehintingVersion used in running = Python 3.11.4Installation and Getting StartedThere are 3 modes to run the game:Run thegame_engine fileas a module for a CLI game against yourselfRun themp_game_engine filefor a CLI game against an AIRun themain filefor a full GUI game. Once you have run this program navigate tohttp://127.0.0.1:5000on a
browser of choice.If you are using the Flask (main.py) application then on my version you do not need to enter via /placement. The script
will automatically render the correct webpage and handle logic (entry, placement or main) depending on your game status.There are two ways to install the package:pip (recommended)In a new venv or for the whole computer runpip install battleships-edf1101This will automatically install Flask and numpyYou can then runpython -m battleships.mainorpython -m battleships.game_engineorpython -m battleships.mp_game_engineto run each modeManuallyGet this repository's folder (clone from github, or download otherwise)Open it either either with a virtual environment (useful if using PyCharm) and install Flask and numpy manually as
shown in prerequisitesOr you can install Flask and numpy for the whole PCTo open files you can cd to the battleships directory (the source code folder not the project root) and runpython -m main(note if you are running it from within the source code directory you don't need to have battleships. prefix)Alternatively you could open them manually in a file browser and run themDeveloper DocumentationAll documentation for source codecan be found hereIn generalComponents.py: Contains the basic functions for creating Battleships gamesgame_engine.py: Contains functions to run a single player game and to run a single player gamemp_game_engine.py: Contains functions needed for multiplayer games (against AI)main.py: Contains the framework needed for a Flask GUI gameadvanced_ai.py: Contains the functions needed for the extension 5 versions of AIai_comparison.py: Contains functions to compare different versions of AI difficultiesTestingIf pytest & plugins are installed then you can test in 2 ways.Note scripts like game_engine.py, mp_game_engine and main.py don't have full coverage as some functions require input statements which
my unittests were not intended to mockUse an IDE like PyCharm to run the tests manuallyNavigate to the tests folder in the project (from the root directory it would becd teststhen runpytest)pylintpylint can be run by going to either the root of the project or the source code folder in the terminal then runningpylint battleshipsLoggingLogs are taken for error events and for general game actions.Logs can be found at the working directory for python, this will be different depending on how you installed the package.DetailsLicenseMIT License:found hereAuthorsStudent 730003140AcknowledgmentsThis coursework is for the University of Exeter.Thank you to the Computer Science department.SourceCode hosted (may be public or private depending on time of reading) onGitHubPackaged at :PyPi