itblaked.battleships

Battleships

Overview

This Ansible role simulates the popular game 'Battleships'.

You can find it on Ansible Galaxy here.

In this game, players take turns shooting at ships located on a 10x10 grid.

Game Setup

  • Shots: These are the targeted points on the grid (e.g., a list of coordinates).
  • Ships: Each ship is represented by a list of details, including its name, health, and location.

Here’s what the grid looks like:

   A B C D E F G H I J
1  x x x x x x
2      x
3            s p p
4      x     s    x
5  b         s
6  b
7  b     x       x
8  b
9          x
10         x   d d d

Types of Ships

No Ship Type Size
1 Carrier 5
2 Battleship 4
3 Destroyer 3
4 Submarine 3
5 Patrol Boat 2

Installation

Each player should clone the role from this repository. It will be available on Ansible Galaxy in the future.

How to Play

Players launch the game using an Ansible Playbook. Each player sets up their ships in the role.

Players then take turns. The first player announces their targeted grid point.

The shots variable can be included in various ways—within the playbook or through the command line. This list should grow over the game.

If all grid points of a ship are shot, the ship sinks, and a 'spysub' feature activates.

Spysubs

Each player has two spysubs, spysub1 and spysub2, which provide bonuses if the player guesses the right access code.

  • spysub1: Gives 1 bonus shot on the next turn.
  • spysub2: Gives 2 bonus shots on the next turn.

The access codes are chosen randomly from 12, 8, 7, 14, 20. Players guess the codes through variables spysub1_accesscode and spysub2_accesscode.

Setting Up Ships

Players need to set their ships' locations in the defaults/main.yml file. Some key rules are:

  1. Ships cannot overlap on the grid.
  2. Ships should be placed in a straight line, either horizontally or vertically.
  3. Locations must be listed in YAML format.

Requirements

None

Role Variables

shots:
  - a1
  - c2
  - a8
  - e4
  - f8

spysub1_accesscode: 12
spysub2_accesscode: 20

ships:
  - name: carrier
    health: 5
    location:
      - a1
      - b1
      - c1
      - d1
      - e1
  - name: battleship
    health: 4
    location:  
      - d8
      - d7
      - d6
      - d5
  - name: destroyer
    health: 3
    location:
      - j10
      - h10
      - i10
  - name: submarine
    health: 3
    location:
      - f5
      - f4
      - f3
  - name: patrolboat
    health: 2
    location:
      - h3
      - i3

Dependencies

None.

Example Playbook

Here's how to use the role in a playbook:

- name: Play Battleships
  hosts: localhost
  connection: local
  vars:
    shots:
      - a1
      - b8
      - f3
    spysub1_accesscode: 12
    spysub2_accesscode: 20
    ships:
    - name: carrier
      health: 5
      location:
        - a1
        - b1
        - c1
        - d1
        - e1
    - name: battleship
      health: 4
      location:  
        - d8
        - d7
        - d6
        - d5
    - name: destroyer
      health: 3
      location:
        - j10
        - h10
        - i10
    - name: submarine
      health: 3
      location:
        - f5
        - f4
        - f3
    - name: patrolboat
      health: 2
      location:
        - h3
        - i3
  tasks:
    - name: Launch Battleships
      include_role:
        name: battleships

License

BSD

Author

Blake Douglas

Informazioni sul progetto

A classic game of Battleships, with Ansible.

Installa
ansible-galaxy install itblaked.battleships
Licenza
mit
Download
72
Proprietario
Geeking it up and loving it.