Skip to content

rrenno/coral-clownfish

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Programming competition 5/11/2018

Coral and clownfish

Coral and clownfish is a clone of a popular game called Tents and Trees (found on both the Apple app store, and Android play store)

Goal of game

The goal of Coral and Clownfish is to save the reef and determine where the clownfish should be placed.

Clownfish can be placed subject to some rules.

1) Each piece of coral needs at least one clownfish connected to it.

Do not leave a straggling coral behind

2) Each clownfish is connected to a coral either horizontally or vertically.

Fish can’t help coral diagonally

3) Clownfish need their space and should not be adjacent to each other.

Vertically, horizontally, or diagonally

4) Row/column constraints.

Each row and column has a specfic number of fish, defined by constraints.

All constraints must be satisfied to win.

5) All cells must be filled in.

Correct fish placement, but not all cells filled in.

Programming competition

The original game provides a button to provide a suggestion when stuck.

Write your own

The goal of this competition is to write a suggester to provide a suggestion for what cell to click next. I have written a basic framework to write a suggestion algorithm given a board state, and your goal will be to write a suggester to plug in.

Suggester engine

Task

Write a suggester that when plugged in can solve all the provided games. It doesn’t necessarily matter how many moves it requires, but it should be able to solve the game effectively unassisted but pressing “Make suggestion” N times (within reason)

Step 1 - Fork my github repo

https://github.com/ssirowy/coral-clownfish

Step 2 - Write a new suggester

At its heart, you are really going to implement one method.

/**
   Overridden method of base class. Will return a random cell to click.
   @method nextSuggestion
   @param {Game} Game object
   @return {Cell}
*/
nextSuggestion(game) {

    const size = game.board.length - 1;
    let row, column  = 0;

    // Pick a non coral cell
    do {
        row = this._getRandomInt(1, size);
        column = this._getRandomInt(1, size);
    } while (game.board[row][column].type == 'coral');

    return new CellSuggestion(row, column);
}

Step 3 - Demonstrate that it can solve all the defined games!

Board state

For a board for size N, The board is represented as an (N+1)*(N+1) 2D array where the row and column constraints are also represnted as cells.

Board state types

Constraint cells with be 0-indexed. Clickable board cells are effectively 1-indexed.

// Constraint cell
{
    type: 'constraint',
    value: 5,
}

// Actual board cell
{
    type: 'empty',  // might also take on 'clownfish', 'water', or 'coral'
}

Setup

This game is built using React and a couple of extra small libraries. The game also uses Redux to maintain state. You won’t really need to know how most of the app is working in order to write a suggester. You can just write basic Javascript to complete the competition part, but feel free to poke around the code and figure out what this game is doing. This is my first React app, so not everything may be up to code (pun intended), but I tried to employ the basic patterns as defined in the docs.

Prerequisites

  1. Git
  2. Node and NPM

Thats it!

Installation

  1. Clone this repository.
git clone git@github.com:ssirowy/coral-clownfish.git
  1. Download all dependencies.
cd coral-clownfish
npm install
  1. Run the game
npm start

About

Clone of Tents and Trees built in React

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 87.7%
  • CSS 8.3%
  • HTML 4.0%