Git Product home page Git Product logo

battleship-kata-scala's Introduction

Continuous Integration

Battleship Game

Battleship CodeKata ๐Ÿšข๐Ÿ’ฅ

Welcome! Your assignment is to create a simple program that emulates the classic game Battleship.

Just in case you've never played this game before (shame on you!) let's go through the rules quickly.

Rules of the Game ๐Ÿ“œ

  • Two players play the game, each taking turns
  • Players have five ships:
    • an Aircraft Carrier
    • a Battleship
    • a Submarine
    • a Cruiser
    • a Destroyer
  • Players have a grid or "ocean" where they arrange their ships
    • The grid is 10 x 10
    • The X-axis runs from A to J
    • The Y-axis goes from 1 to 10
    • Any square in the grid can be identified by combining these, for example B-3 is the square second from the left and third from the top
  • After arranging the ships, they cannot be moved
  • Ships occupy space on the grid, specific to the type of ship:
    • the Aircraft Carrier takes 5 squares
    • the Battleship takes 4 squares
    • the Submarine takes 3 squares
    • the Cruiser takes 3 squares
    • the Destroyer takes 2 squares
  • A ship can only be positioned vertically or horizontally on the grid
  • A ship cannot overlap other ships, or be placed outside of the grid
  • Each round, each player takes a shot, announcing which square on the opponent's grid got hit
  • The opposing player announces whether the shot hit or missed any of his ships
  • When all squares of a ship are hit, the player announces it was sunk, including which ship it was
  • The first player to sink all of his opponent's ships wins
  • If both players eliminate all the opponent's ships in the same round, the game ends in a draw

Battleship Game Board

Still want more info on the game? Check out this step-by-step guide.

Hints ๐Ÿ’ก

  • How will you model the Grid? Does it need to be multidimensional?
  • Can you make the language enforce correct (programmatic) inputs into the core domain?
  • In what way can you leverage datastructures to your advantage?

Bonus Challenges ๐Ÿฅต

  • Implement the entire core domain immutably
  • Also tell the players which squares they already hit on the opponent's grid
  • Allow players to automatically place their ships randomly on their grid
  • Implement a bot to allow single-player mode
    • Start off simple, let the bot shoot random squares
    • Let the bot only shoot squares he has not hit yet
    • ...
  • Implement spectator mode where two bots duke it out

Additional Notes ๐Ÿ“

You can implement the game as simple, or hard as you want to! From running the game with a test suite to text-based to a graphical interface. Go nuts!

Focus on learning, not on the results. Above all: have fun!

Contribute ๐Ÿ™‹

Have ideas to make this Kata better? Maybe you found a typo, or grammar issue? Or how about a new idea that can make the Kata more interesting? Let me know!

battleship-kata-scala's People

Contributors

rstraub avatar

Watchers

 avatar  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.