# Install Yarn
brew update
brew install yarn
# Clone the repo
git clone https://github.com/eakl/battleship
cd battleship
# Install dependencies
yarn
# Run tests
yarn test
# Start the server
yarn startOnce the server has started, you can use this simple API with cURL or Postman
To attack, just make a request to the attack endpoint with the query coord=X_Y. Where X and Y are your coordinates.
curl -X POST http://localhost:8080/attack?coord=X_YLet's say the generated battlefield looks like the following:
[0,0,0,0,0,0,1,1,0,1]
[0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,0,0,1,0]
[1,0,0,0,0,0,0,0,0,0]
[1,0,0,1,1,0,0,1,0,0]
[1,0,0,0,0,0,0,0,0,0]
[0,0,1,0,0,0,0,1,0,0]
[0,0,1,0,0,1,0,1,0,0]
[0,0,0,0,0,0,0,1,0,0]
[0,1,1,1,0,0,0,1,0,0]By making the following requests:
curl -X POST http://localhost:8080/attack?coord=3_7
# Hit
curl -X POST http://localhost:8080/attack?coord=3_8
# You just sank the destroyerYou'll sink the destroyer and the battlefield will look like this:
[0,0,0,0,0,0,1,1,0,1]
[0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,0,0,1,0]
[1,0,0,0,0,0,0,0,0,0]
[1,0,0,1,1,0,0,1,0,0]
[1,0,0,0,0,0,0,0,0,0]
[0,0,2,0,0,0,0,1,0,0]
[0,0,2,0,0,1,0,1,0,0]
[0,0,0,0,0,0,0,1,0,0]
[0,1,1,1,0,0,0,1,0,0]The coordinates you hit are replaces by the 2's
curl -X GET http://localhost:8080/restart