python assignment 35

In this programming assignment you will:

  • Write a client-server application
  • Communicate using HTTP
  • Design a messaging standard


Overview

In this lab you will write a distributed implementation of the Battleship game. We will use the standard 10×10 variation of the game. Here is an online implementation of the Battleship game. Note that the ships in that implementation have slightly different names.

Our implementation will be based on a symmetric client server architecture, where each player has both a server and a client. The server keeps an internal state of the game and issues replies to the other player’s client.


Board Setup

The first step before the game begins is the setup of the board, according to the rules of the game. We will represent the board with a character array, where _ represents water and Carrier, Battleship, cRuiser, Submarine, and Destroyer fields are represented by C, B, R, S, D respectively. For example, your board might be set up as follows:

CCCCC______x000D_
BBBB_______x000D_
RRR________x000D_
SSS________x000D_
D__________x000D_
D__________x000D_
___________x000D_
___________x000D_
___________x000D_
___________x000D_

You will save your board as own_board.txt.


Messages

To play the game, your implementation needs to exchange two types of messages – fire and result. The fire message needs to communicate the grid location of salvo. The result message needs to communicate whether the salvo was a hit, a sink, or a miss.

The fire message will be represented as an HTTP POST. The content of the fire message will include the targeted coordinates as a URL formatted string for Web forms, for example 5 and 7, as: x=5&y=7. Assume that coordinates are 0-indexed. So, assuming that your opponent’s server runs at 111.222.333.444:5555, the fire message is a POST request sent to http://111.222.333.444:5555?x=5&y=7.

The result message will be formatted as an HTTP response. For a correctly formatted fire request your reply will be an HTTP OK message with hit= followed by 1 (hit), or 0 (miss). If the hit results in a sink, then the response will also include sink= followed by a letter code (C, B, R, S, D) of the sunk ship. An example of such a reply is hit=1&sink=D.

If the fire message includes coordinates that are out of bounds, the response will be HTTP Not Found. If the fire message includes coordinates that have been already fired opon, the response will be HTTP Gone. Finally, if the fire message is not formatted correctly, the response will be HTTP Bad Request. For your reference here’s a link to the different HTTP response status codes.


Program Invocation

Your server process should accept a port parameter, on which a client can connect, and the file containing the setup of your board, eg.

python server.py 5000 own_board.txt.

Your client process should accept the IP address, the port of the server process, and the X and Y coordinates onto which to fire, eg.

python client.py 128.111.52.245 5000 5 7.

The client will be invoked multiple times during the game.

Internal State Representation

Following each fire message the server should update the state of the player’s own_board.txt (whether a player’s ship has been hit and where). Following each result message the client should update the record of the player’s shots onto the opponent’s board, represented internally as opponent_board.txt. A player should be able able to visually inspect their own board and their record of opponent’s board on http://localhost:5000/own_board.html and http://localhost:5000/opponent_board.html respectively. It is up to you how you visually represent the state of each board.

Please:

Take a video less than 5 min to show that how the game work and how the code work.

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.