{"id":16234263,"url":"https://github.com/parmsang/battleshipsweb-2","last_synced_at":"2025-07-21T15:11:27.142Z","repository":{"id":36054502,"uuid":"40352786","full_name":"parmsang/BattleshipsWeb-2","owner":"parmsang","description":null,"archived":false,"fork":false,"pushed_at":"2015-08-07T19:18:46.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T05:14:58.990Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parmsang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-07T09:33:05.000Z","updated_at":"2023-03-09T03:45:52.000Z","dependencies_parsed_at":"2022-09-04T17:23:08.241Z","dependency_job_id":null,"html_url":"https://github.com/parmsang/BattleshipsWeb-2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parmsang%2FBattleshipsWeb-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parmsang%2FBattleshipsWeb-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parmsang%2FBattleshipsWeb-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parmsang%2FBattleshipsWeb-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parmsang","download_url":"https://codeload.github.com/parmsang/BattleshipsWeb-2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801170,"owners_count":20998331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T13:15:31.701Z","updated_at":"2025-04-08T07:56:00.531Z","avatar_url":"https://github.com/parmsang.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Referenced from [Makers Academy Battleships](https://github.com/makersacademy/course/blob/master/battle_ships/battle_ships.md) (private repo).\n\nBattleships (or Battleship) is a game where each player has a board upon which they can place a number of ships. The boards are 10x10 two dimensional grid.\n\n\u003cimg src=\"battleships.jpg\" width=\"500px\" height=\"500px\"\u003e\n\nAfter each player has placed their ships on their own board they take turns to shoot on the opponents board. In each round, each player takes a turn to announce a target square in the opponent's grid which is to be shot at. The opponent announces whether or not the square is occupied by a ship, and if it is a _hit_ they mark this on their own primary grid. The attacking player notes the hit or miss on their own _tracking_ grid, in order to build up a picture of the opponent's fleet.\n\nWhen all of one player's ships have been sunk the game finishes and the player who has ships remaining is the winner.\n\nThe code is intended to demonstrate a range of techniques:\n\n* Dependency inversion (e.g. `Game` with `Player` and `Board` ) over tighter dependencies (e.g. `Board` and `Cell`)\n* TDD and BDD\n* Factory methods (e.g. `Ship.submarine`)\n* Refactoring to create service objects (e.g. `CoordinateHandler`)\n* Implementing `Enumerable` (`CoordinateHandler`)\n* Emergent design.  No part of the code architecture was decided on up front.  All classes and refactoring emerged as a consequence of further tests being addded.\n\nThe game is fully playable in `irb`:\n```\n$ gem install battleships\n$ irb\n\u003e require 'battleships'\n```\nNow create a new game using `Game`, `Player` and `Board` classes:\n```\n\u003e game = Game.new Player, Board\n```\nEach player can place ships on their own board:\n```\n\u003e game.player_1.place_ship Ship.battleship, :B4, :vertically\n\n\u003e game.player_2.place_ship Ship.cruiser, :G6\n```\nPlayers can shoot at each other's boards:\n```\n\u003e game.player_1.shoot :C2\n =\u003e :miss\n\u003e game.player_2.shoot :B4\n =\u003e :hit\n```\nPlayers can view their own boards:\n```\n\u003e puts game.own_board_view game.player_1\n   ABCDEFGHIJ\n  ------------\n 1|          |1\n 2|          |2\n 3|          |3\n 4| *        |4\n 5| B        |5\n 6| B        |6\n 7| B        |7\n 8|          |8\n 9|          |9\n10|          |10\n  ------------\n   ABCDEFGHIJ\n   \n\u003e puts game.own_board_view game.player_2\n   ABCDEFGHIJ\n  ------------\n 1|          |1\n 2|  -       |2\n 3|          |3\n 4|          |4\n 5|          |5\n 6|      CCC |6\n 7|          |7\n 8|          |8\n 9|          |9\n10|          |10\n  ------------\n   ABCDEFGHIJ\n```\nAnd their opponent's boards:\n```\n\u003e puts game.opponent_board_view game.player_1\n   ABCDEFGHIJ\n  ------------\n 1|          |1\n 2|  -       |2\n 3|          |3\n 4|          |4\n 5|          |5\n 6|          |6\n 7|          |7\n 8|          |8\n 9|          |9\n10|          |10\n  ------------\n   ABCDEFGHIJ\n\n\u003e puts game.opponent_board_view game.player_2\n   ABCDEFGHIJ\n  ------------\n 1|          |1\n 2|          |2\n 3|          |3\n 4| *        |4\n 5|          |5\n 6|          |6\n 7|          |7\n 8|          |8\n 9|          |9\n10|          |10\n  ------------\n   ABCDEFGHIJ\n```\nPlayers can sink their opponent's ships:\n```\ngame.player_2.shoot :B5\n =\u003e :hit\ngame.player_2.shoot :B6\n =\u003e :hit\ngame.player_2.shoot :B7\n =\u003e :sunk\n```\nAnd the game can be tested for a winner:\n```\n\u003e game.has_winner?\n =\u003e true\n\u003e game.player_1.winner?\n =\u003e false\n\u003e game.player_2.winner?\n =\u003e true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparmsang%2Fbattleshipsweb-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparmsang%2Fbattleshipsweb-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparmsang%2Fbattleshipsweb-2/lists"}