A simulator for a 2-player game of Battleship
Python 3 (v3.8.8)
Execute the following command in the parent directory containing the repository
python -m battleship-sim.src.main
This runs the simulator with sample data provided in this file.
This should create a new text file in out/
directory, and it should contain the results of the simulation run.
This file should be identical to this file in its contents.
- Create a text file in
out/
directory in the following format -
<Board size M>
<No. of ships available to each player>
<Player 1 ship locations, separated by ',' and x-y coordinates separated by ':'>
<Player 2 ship locations, separated by ',' and x-y coordinates separated by ':'>
<No. of moves i.e. missiles available to each player>
<Player 1 move locations (in the given order), separated by ':' and x-y coordinates separated by ','>
<Player 2 move locations (in the given order), separated by ':' and x-y coordinates separated by ','>
Note: Each input has to be present in a single line, lines should not have empty lines in between them. Inputs spanning lines are not supported.
Please refer to this sample file for example of the input data.
- Execute the following command in the parent directory containing the repository
python -m battleship-sim.src.main --input=<name of the input file>
This runs the simulator with the data provided in the user-defined text file.
This should create a new text file of a corresponding name (user-defined name, but appended by Result__
and the system timestamp)
in out/
directory. This file should contain the results of the simulation run.
Execute the following command to run unit tests on the simulator.
python -m battleship-sim.tests.main
Expected output of running the unit tests -
..................
----------------------------------------------------------------------
Ran 18 tests in 0.004s
OK
This also creates a new result file in out/
directory as a part of one of the unit tests.