All expected features have been implemented: simple game, multiplayer game, flask game. All of which the user can win by guessing ships and the AI (where applicable) can win.
Defensive programming and try except statements are implemented throughout the project.
I have written some tests which can be found in tests/test_by_me.py
Logging is implemented throughout the project. See main.log for previous logs
The AI can't hit the same square twice in one game
The user cannot click the same square mutliple times
I have added another algorithm to the place_battleships function which places the ships in the most optimal locations. As referenced here Cite the most optimal placement puts ships adjacent to one another to confuse the user. This can be used in mp_game_engine.py by changing "custom" to "optimal" in the player board
There is a constant in main.py named HARD_MODE. When true once the AI hits a shit it will hit the ship until sunk in consecutive turns. This is implemented in the enhanced_ai module.
This is the battleships course work for ECM1400. Battleships can be played via the command line or a web interface. An AI has been made to play against the player in multiplayer mode and online mode. In simple game mode you play against a pre generated board.
Python packages required:
blinker==1.7.0
click==8.1.7
Flask==3.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
Werkzeug==3.0.1
pytest==7.4.3
pytest-cov==4.1.0
pytest-dependency==0.5.1
pytest-order==1.2.0
Python 3.10.12
Can be seen in requirements.txt
battleships.txt should store the ships on each line:
shipname:length
placement.json should store the ship placement on each line:
shipname:[x_coord, y_coord, orientation]
pip install -r requirements.txt
when in the root directory
OR
Indivually install each requirement
pip install Flask
...
- Install all required packages
- Run game_engine.py
- Use CLI to answer promts and play the game
- Game finishes once all ships are sunk
- Alter battleships.txt and placement.json if required
- battleships.txt states what ships and their length can be used
- placement.json states where your ships will be placed on the board
- Placement as follows: shipname:[x_coord, y_coord, orientation]
- Run mp_game_engine.py
- Use CLI to answer promts and play the game
- Game finishes once all ships are sunk
- run main.py
- Open a browser at 127.0.0.1:5000/placement
- Use the browser to place your ships and continue
- Use the grid to guess where the AI has placed their ships
- Game finishes once all ships are sunk
For hard mode change the HARD_MODE constant to True.
Tests can be seen in /tests. There are 4 testing files (test_by_me.py
, test_functionality.py
, test_helper_functions.py
test_students.py
) and 2 configuration files (battleships.txt
and placement.json
) followed by an __init__.py
. Tests have been provided by academics for this project, other than tests in test_by_me.py. These have been written by me to test additional funcitonality.
To run tests be in the root directory for the project in terminal and enter pytest
in CLI
A mixture of defensive programming and try except statments have been used in this project.
Full documentation can be seen throughout the code base in comments and docstrings. There are docstrings for each function and module.
For sphinx documentation open docs/_build_html/index.html
Note had issues generating the document so I moved things around in directories to get it to generate then it broke imports so I moved it all back later. Issue with the main module also
To view logs open main.log
. This stores any notable processes from the program.
Key game functions used in each version of the game
Single player game against the simple board placement. Can be run to play the simple version of the game
Multiplayer game against the AI. Your ships are placed using the placement.json and has additional functions to play against the AI
Development server to play against the AI. See intructions above. More function sot enable browser functionality.
Additional functionality to make the AI better - much much better!
Author: **********
License: MIT (License file)
Course work for ECM1400, Due 15/12/23
Github Handle: @Theocat321 | Github