Skip to main content

2023 ECM1400 Coursework - Battleships

Project description

ECM1400 Battleships

Introduction

A python application to simulate a Battleships game against an AI in both a command line interface and a Flask GUI.

Coursework Self assessment

All features required by specification are complete (including testing & logging)

Additional

Entry Screen

The user can select the game settings (size, difficulty) on an Entry page. Game screen has a return to menu button so games can be replayed

Storm Mode

When this is turned on The board will shift 1 space each turn in a predetermined direction

HTML Template Sunken ships

If a ship has been sunk, the main.py script sends a list of sunk positions for either the AI or Player to the HTML code, and it colours those tiles green

Other Frontend modifications

In the placement HTML file originally allowed users to place fewer than required number of ships. This was fixed.

Storm mode

To make it a more challenging if you select storm mode the player's board will shift one space each turn. Since the HTML grid isn't persistent this had to be coded in javascript

AI attacking

There are 5 AI difficulties code here 0. Pure Random Guessing

  1. Random but it won't guess same space twice
  2. Guessing a random position around unsunk hits
  3. Trying to guess in a line around unsunk hits
  4. Guesses in a line if there are unsunk hits, if none it calculates the probability of a ship being in any unguessed tile and guesses there

Wrote a script to test AI's against each other

drawing drawing

Prerequisites

  • Flask must be installed pip install Flask
  • numpy must be installed pip install numpy
  • For testing pytest must be installed pip install pytest
  • Pytest plugins must be installedpip install pytest-depends pip install pytest-cov
  • Python version must be ≥ 3.10 due to | symbol in typehinting

Version used in running = Python 3.11.4

Developer Documentation

All documentation for source code can be found here

In general

  • Components.py: Contains the basic functions for creating Battleships games
  • game_engine.py: Contains functions to run a single player game and to run a single player game
  • mp_game_engine.py: Contains functions needed for multiplayer games (against AI)
  • main.py: Contains the framework needed for a Flask GUI game
  • advanced_ai.py: Contains the functions needed for the extension 5 versions of AI
  • ai_comparison.py: Contains functions to compare different versions of AI difficulties

Testing

If 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 mock

  1. Use an IDE like PyCharm to run the tests manually
  2. Navigate to the tests folder in the project (from the root directory it would be cd tests then run pytest )

Details

License

MIT License: found here

Authors

  • Student 730003140

Source

Code hosted (may be public or private depending on time of reading) at https://github.com/edf1101/Battleships/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

battleships-edf1101-1.1.tar.gz (116.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page