Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSCI212 Interacting Systems Assignment 3 TASK The game Sea Battleship is a guessing game usually played by 2 people. The game is played on four

CSCI212 Interacting Systems Assignment 3 TASK The game Sea Battleship is a guessing game usually played by 2 people. The game is played on four grids, two for each player. The grids are typically square can be 8 8 and the individual squares in the grid are identified by letter and number. On one grid the player arranges ships and records the shots by the opponent. On the other grid the player records his own shots. In this assignment, you are tasked to develop an interactive network game programs using C/C++ where a human player (client) will play against the computer (server). You are required to use socket (TCP) programming to implement the messaging between the client and server machines. For a start, you will just the implement the human player bombing the computers warships. Each ship occupies a number of consecutive squares on the grid, arranged either horizontally or vertically. The number of squares for each ship is determined by the type of the ship. The ships cannot overlap (i.e., at most one ship can occupy any given square in the grid). The types and numbers of ships allowed are the same for each player. These may vary depending on the rules. There are two typical complements of ships, as given in the rules below: Type of warship Symbol Code Length aircraft carrier A 5 battleship B 4 destroyer D 3 submarine S 3 patrol boat P 2 Before play begins, the computer (server) randomly arranges a number of ships secretly on the grid (see below diagram as example) and save this grid information in a flat file at its server end. The flat file could be stored in the following format or any other format you define: Example: Flat file format Battle Grid View A4;A5;A6=S B3;C3;D3;E3;F3=A D7;E7=P F5;F6;F7;F8=B H3;H4;H5=D => After the ships have been positioned, the game proceeds in a series of rounds. In each round, the client player (Human) can enter a target square (eg: A3) in the server's grid which is to be shot at. If a ship occupies the square, then it takes a hit. The server opponent will reply whether or not the shot hit one of its ships and type of warship will be revealed using the symbol code as given above. When all of the squares of a ship have been hit, the ship is sunk (as shown below in RED letter the corresponding direct hit of the type of ship). The X can depict as miss hits. This data grid view can be displayed at the client side. After all of server computers ships have been sunk, the game ends and the game timing can end. The medal tally can then keep scores of who are the fastest winners to beat the server computer. The server program developed must be able to handle multiple queries and hence be able to search through its data file for a correct response. The server program should also allow continuous enquires until the customer enters quit. The communication between the client and server machine can be any bidirectional interactive protocol. An example is to use socket programming where network endpoints (IP address and port number) are represented as sockets. When creating the server application, you must follow these steps: Create a new socket by typing: socket(). Bind an address (IP address and port number) to the socket by typing: bind. This step identifies the server so that the client knows where to go. Listen for new connection requests on the socket by typing: listen(). Accept new connections by typing: accept(). Often, the servicing of a request on behalf of a client may take a considerable length of time. It would be more efficient in such a case to accept and deal with new connections while a request is being processed. The most common way of doing this is for the server to fork a new copy of it after accepting the new connection. The responsing Server listens on a port and waits for clients request. Based on the Clients questions, the Server will response appropriately by looking up a data file stored at the servers end. Example of Battle Ship game interactions on the Clients and Servers console: Clients Console Servers Console Enter a square on the battle grid to bomb : A3 > < Client bombed on square - A3 A Miss! ---> A Miss! Pls entered another square to bomb or press V to view your battle grid: H3 > < Client bombed on square H3 Destroyer got a HIT!! Destroyer got a HIT!! Pls entered another square to bomb or press V to view your battle grid: F6 > Client bombed on square F6 Battle Ship got a HIT!! Battle Ship got a HIT!! Pls entered another square to bomb or press V to view your battle grid: V > < Returning Battle grid so far for Player 1 A B C D E F G H 1 2 X X 3 X D 4 5 X 6 B 7 8 Pls entered another square to bomb or press Q to Quit the game. Q > Player 1 ended the game. Other enhanced features : ? Multihreaded server: - to handle multiple game socket connections where the system allow more than one players playing with the server. ? Time keeping for every games played by the respective players. ? The server can capture the medal tally to display the top 10 players. ? High concurrency, Critical regions have small granularity by the following techniques: - Use read write lock whenever applicable. - Use thread local copy whenever applicable before locking and merging. Grading: Your submission will be graded according to the following criteria: - Program design - Correctness / completeness of the C/C++ program - Programming clarity (Comment lines to be provided) - Readme file containing instructions on how to compile and run your program properly. - Zipped up all your files and named it with your FULL student name with NO space. Eg: JasonFongYongSeng.zip Please scan your zip file to ensure there are no virus in it. For submission, pls drop your zip file into moodle website.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

Students also viewed these Databases questions

Question

2. Why has the conflict escalated?

Answered: 1 week ago