Code Monkey home page Code Monkey logo

battleship-board's Introduction

battleship-board

This was developed as a solution to a technical assignment I was tasked with completing.

Background

The classic game of 'Battleship' has the following rules:

  • There are two opposing players.
  • Each player has a 10x10 board.
  • During the setup phase, each player places some number ( >= 1) of battleships on their board.
    • A battleship is represented as a 1-by-n or n-by-1 sequence of grid squares.
    • A battleship must be placed such that it fits entirely on the board.
    • A battleship cannot overlap with another battleship on the same board.
  • After setup, both players alternate taking turns to choose a single coordinate on the opponent's board to "attack".
    • If the opponent contains a battleship at that coordinate, that part of the battleship is "damaged".
    • If all squares occupied by a battleship have been damaged, it is "sunk".
    • The attacker receives information about whether their attack was "hit" or "miss".
  • Players continue to take turns until a player wins by sinking all of the opponent's battleships.

Task

We are not required to implement the full game, only a state tracker for each player.
In particular, we must implement the following functionality:

  • Create a board.
  • Add a battleship to the board.
  • Take an 'attack' at a given position, and report back whether the attack resulted in a hit or a miss.
  • Return whether the player has lost the game yet (i.e. all battleships have been sunk).

Layout

This repo contains a Visual Studio 2017 solution with two projects:

  • battleship-board: Contains all functionality. Built as a library; No executable is produced.
  • battleship-board-tests: Contains unit tests to validate the functionality implemented in battleship-board.

Run

Open the solution file at battleship-board\battleship-board.sln and use Visual Studio's inbuilt test runner to execute all tests (From the menu bar: Test > Run > All Tests).

battleship-board's People

Contributors

adamkinnell avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.