Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Programming assignments for MSU CSCI 366

License

NotificationsYou must be signed in to change notification settings

msu-netlab/CSCI_366_Programming_Assignments

 
 

Repository files navigation

Instructions

Complete the following assignment individually.Submit your work on D2L into the "Programming Assignment 1" folder.

For a deeper discussion of the assignment and the code, please check out thisYouTube video.

Learning Objectives

In this programming assignment you will:

  • clone and commit toGitHub repositories
  • Learn how to build a C++ project usingCMake
  • Learn how to test your code usinggoogletest

Overview

Your objective is to implement a basic version of theBattleshipgame.You will use the standard10x10 variation of the game.Here is an example ofonline implementationof the game.Note that the ships in that implementation have slightly different names.

Your implementation will be a client server architecture.This repository provides you with the header files for the client (player) and server implementations (src/Client.hppandsrc/Server.hpp), client and server run times (src/client_main.cpp andsrc/server_main.cpp), and a suite oftests (test/tests.cpp).Your job is to finish the implementation ofClient.cpp andServer.cpp to pass all the tests intests.cpp.

Board Setup

The first step before the game begins is to create asetup board for each player, according to therules of the game.You will represent the board with a character array, where_ represents water and Carrier, Battleship, cRuiser,Submarine, and Destroyer fields are represented byC,B,R,S,D respectively.For example, your board might be set up as follows:

CCCCC_____BBBB______RRR_______SSS_______D_________D_________________________________________________

Save these boards for both players asplayer_1.setup_board.txt andplayer_2.setup_board .txt.

Messages

To play the game, your implementation needs to exchange two types of messages -shot andresult.Theshot message needs to communicate the grid location of salvo.Theresult message needs to communicate whether the salvo was a hit, a miss, or if the shot was out of bounds.

You will represent both of these messages as JSON files that the client and server exchange via local disk storage.Assume that the x and y board coordinates are zero indexed at the top-left corner of the board and increase as you goright and down.

Program Operation

The following figure illustrates the operation of the program.(I kept the image from the lecture for continuity.)

system architecture

The player fires ashot by writing coordinates to aplayer_#.shot.json file.The server reads the shot file, determines the result of the shot, and writes it intoplayer_#.result.json.The player reads the result file and updates the result on its action boardplayer_#.action_board.json.

Program Invocation

To play Battleship you should first start the server by running therun-server executable.Then start the player clients by running two instances of therun-client executable.Unfortunately, the client and server executables will not do anything interesting until you implementClient.cppandServer.cpp.As you progress in these implementations, your code will pass more and more tests intests.cpp.When your code passes all the tests, you will be able to run the client and server executables to play the game.

Bonus

I will awardone bonus point for each of the following:

  • Server throws an error if both players start with the same player number. (implementations and tests)

  • Server sends a different result when a ship is sunk. The client implementation notifies the player when they sink aship (implementation and tests)

  • Server detects when a game ends and returns the winner to both players. Player clients display the winner.(implementation and tests)

What to Submit

Submit your work on D2L into the "Programming Assignment 1" folder.

  • A text file containing a link to a GitHub repository with your solution

  • A text file alerting the TA if you implemented any of the bonus features, and if so, which ones

Grading

We will grade your submissions based on how many test cases intests.cpp your solution passes.Note that for grading we will use out owntests.cpp and full size setup board files.

About

Programming assignments for MSU CSCI 366

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp