• Stars
    star
    1
  • Language
    Scala
  • Created over 3 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mars Rover Case Study

Solve the problem below as a group using TDD.

The problem is taken from codingdojo.org.

Problem Specification

ACME Space Team Ltd are planning a privately funded mission to Mars. Build a simulation to help them design their first rover controller!

The project will evolve in phases as Mission Command unveils new requirements. Try not to look ahead to the next phase until you've finished with the current one.

Use TDD throughout:

  • Change roles after each TDD cycle.

  • No "red phases" while refactoring. The code should always compile, and tests should always be green!

  • Be careful about edge cases and exceptions.

Phase 1 - Brave New World

Initial scans of Mars have revealed the nature of the terrain there. Let's start by modelling the terrain and the location of the rover:

  • Contrary to popular belief, the Martian surface is actually a grid of squares.

  • Most of the terrain is sandy; about 10% is made up of rocks.

  • The rover occupies exactly one square of terrain. It is always faces in one of the four cardinal directions: North, South, East, or West.

  • We should have a way of visualising the simulation. Let's print it to the console! Use '.' for sand, 'O' for a rock, and one of '^>V<' for the rover.

Phase 2 - First Steps

The boffins in Engineering have come up with a remote telemetry system. We'll send the rover individual commands, each time waiting for a response.

A command is a single character:

  • F to move forward;
  • B to move backward;
  • L to turn left;
  • R to turn right.

Implement a method to simulate sending the command (by typing it on the console) and receiving a response (by printing it out). Note that some commands can fail:

  • L and R always succeed;
  • F and B will fail if the rover tries to move into a square containing a rock;
  • F and B will fail if the rover tries to move off the edge of the world (which we know is flat).

The rover should respond with Ok if a command was successful, or Fail and an error message if it failed for any reason.

Phase 3 - Rolling Out

Apparently it takes an average of 12.5 minutes for a command to reach Mars. This is clearly too slow for our rover pilots (who are notorious adrenaline junkies). To speed things up, we'll batch commands into short programs and send them in one go.

A program is a string made up of FBLR commands.

We'll send a whole program in one go. The rover should respond by telling us whether the program was successful. If the program failed, the rover should tell us which command failed and why.

Phase 4 - Samples Rock!

Rocks are really interesting. We must take samples... and by taking samples we mean smashing them to bits!

Implement a new command, S, to take a sample:

  • the command succeeds if there is a rock in the square in front of the rover;

  • the rover destroys the rock in the process;

  • we should record the number of successful samples we've taken.

Phase 5 - Look Before You Leap

It turns out that bashing into rocks is expensive. Sampling thin air is also not ideal. Let's add a camera to the rover so we can see what we're doing.

Implement a command P to take a picture. The command should respond with the terrain in the square immediately in front of the rover.

Phase 6 - SLAM!

Our rover pilots are demanding a pay rise so we're going to have to make them redundant.

Let's implement a new "high level command system" to replace our current programming system.

The new system should have a single "move" command, that instructs the rover to move to an (x, y) location. The rover should turn and move as necessary. If it enounters any rocks, sample those suckers!

Implement the command in terms of the existing FBLRS commands:

  • if the rover isn't facing in the irght direction turn towards the goal;

  • if the rover is facing in the right direction, take a picture and either move or sample as appropriate;

  • the command should keep going until the rover reaches its destination.

More Repositories

1

bridges

Generate bindings for Scala types in other programming languages.
Scala
56
star
2

checklist

Validation library for Scala.
Scala
47
star
3

unindent

Indent-adjusted multiline string literals for Scala.
Shell
47
star
4

bulletin

Automatically perform shallow merges on case classes. Treat your data with the latest updates!
Scala
42
star
5

meowsynth

The mighty meowing synthesizer!
Scala
30
star
6

validation

Scala data validation library
Scala
29
star
7

typelevel-todomvc

Scala
25
star
8

atlas

A tiny embedded scripting language implemented in Scala.
Scala
24
star
9

shapeless-guide

The Type Astronaut's Guide to Shapeless
19
star
10

functional-data-validation

Slides and code samples for a talk on thinking functionally (and validating web forms).
Scala
18
star
11

99-ways-to-di

Slides from my lightning talk on Dependency Injection at Scala Central #5.
14
star
12

css-selector

Lift-style CSS selector transforms based on Scalate's Scuery
Scala
10
star
13

tipi

Tiny templating language written in Scala.
Scala
10
star
14

macros-vs-shapeless

Slides and code samples on meta-programming techniques in Scala.
Scala
10
star
15

spandoc

Write Pandoc filters in Scala.
Scala
7
star
16

scalalol-2011-talk

Slides and code samples for talk at Scala Lift-Off London 2011.
Scala
6
star
17

scala-opengl

Simple OpenGL examples using Scala, LWJGL, and sbt-lwjgl
Scala
6
star
18

shapeless-guide-slides

Slides for my Scala World 2016 workshop on shapeless.
6
star
19

smartypants

Simple smart constructor generation for Scala.
Scala
4
star
20

scalax2gether-2017

Workshop and hack proposals for the Scala Exchange Hack Day (ScalaX2gether 2017)
4
star
21

shapeless-sandbox

Scala
3
star
22

scalax-2014

Slides and code samples for my Scala Exchange 2014 talk on Functional Data Validation.
3
star
23

typelevel-philly-2016

3
star
24

sbt-less

Superseded by sbt-less in https://github.com/untyped/sbt-plugins.
Scala
3
star
25

akka-streams-case-study

Scala
2
star
26

poker-case-study

Poker hand comparison in Scala. A fairly advanced "Essential Scala" case study.
Scala
2
star
27

interpreter-case-study

Scala case study about building an interpreter and a simple DSL.
Scala
2
star
28

cats-error-case-study

Scala
2
star
29

bus-driver-case-study

Gossiping Bus Drivers Kata
Scala
2
star
30

concurrency-case-study

Scala
2
star
31

scala-rpg-test

A sandbox project for playing with Scala and the graphics from Browserquest.
Scala
2
star
32

versionit

Grab your Git commit hash as a Scala String.
Scala
2
star
33

advanced-scala-scalax15

Code written at Advanced Scala at Scala Exchange 2015
Scala
1
star
34

spectaskular-iphone

iPhone todo list app
Objective-C
1
star
35

brighton-java-sample-app

Scala talk for Brighton Java
CSS
1
star
36

session-cell

Cookie-based in-memory session storage for the Racket HTTP Server.
Scheme
1
star
37

kitties-case-study

Meow!
Scala
1
star
38

gilded-rose-case-study

Code refactoring kata
Scala
1
star
39

conway-case-study

Scala
1
star
40

asyncjs-creative-fp

Creative Functional Programming talk for AsyncJS.
1
star
41

parallel-case-study

Scala
1
star
42

bank-ocr-case-study

Scala
1
star
43

play-json-case-study

Scala
1
star
44

calc-case-study

Scala
1
star
45

bowling-case-study

Scala
1
star
46

paths-case-study

Essential Scala case study: selecting paths from a route finder service
Scala
1
star
47

typeclub

Scala
1
star
48

tagless-case-study

Scala
1
star
49

doodlejs

Javascript port of Doodle
JavaScript
1
star
50

composejs

Javascript port of Compose (https://github.com/underscoreio/compose).
JavaScript
1
star
51

fpinscala

My attempts at the exercises in Functional Programming in Scala.
Scala
1
star
52

shapeless-guide-code

The Type Astronaut's Guide to Shapeless (Example Code)
1
star
53

scaladays-berlin-2016

1
star
54

property-based-testing-workshop

Scala
1
star
55

advanced-scala-exercises

Scala
1
star
56

advanced-scala

The old source code repository for Scala with Cats
1
star
57

cats-effect-sandbox

An empty SBT project with dependencies on Cats and Cats Effect.
Scala
1
star
58

away-with-the-types

Scala
1
star