6.5.0.3

8 — Selecting testable methods

Due Sunday, 7 March, midnight,
    late date for turning it in without penalty: Sunday 14 March, midnight

Your software architect has decided that it is time to finish up the feeding phase of an Evolution game. The key is a method that takes care of one step in the feeding phase; this method is repeated until the watering hole is out of food or none of the players wants more food.

The dealer starts the feeding process with the complete list of players. As long as the watering hole contains food tokens and a player may feed a species or take food for a fat tissue card, the dealer keeps transferring food from the watering hole to the player—either automatically or after asking the player for a decision.

To support all possible kinds of player strategies—not just the silly sample strategy from the previous two projects—he proposes to slightly re-interpret the results of a player query:
  • false, Note the difference to the official rules. meaning the player forgoes any additional chance to take food from the watering hole for a carnivore attack or a fat-tissue fill-up during this turn’s feeding cycle. Of course, if the player owns species that "scavenge", these species still receive food if a carnivore eats.

  • Natural is the index of a single species of the currently feeding player that is vegetarian and gets the next token of food;

  • [Natural, Nat+] combines an index to a given species and desired number of food tokens—meaning the indexed species of the currently feeding player comes with a fat-tissue trait and wishes to store the specified number of food tokens on that trait;

    Nat+ is a Nat greater than 0.

  • [Natural, Natural, Natural] is a triple of indexes: the first one pointing to a carnivore of the current player, the second one points to a player, and the third one into the species sequence of the designated player. The first species attacks the second species for one food token.

    A player index ranges between 0 and the length of the given player sequence (inclusive). The last one refers to the currently feeding player.

Task 1 Design a data representation for the dealer including the feed1 method that allows it to execute one step in the feeding cycle. The method
  • decides whether it can transfer a token of food (or several) from the watering hole to the current player automatically or whether it is necessary to query the next player;

  • transfers food, by interpreting the answer from a player if necessary;

  • remove the player from the sequence or rotate the sequence of players, as needed.

The dealer will call this method as long as there is food in the watering hole and species that may wish to take additional food.

Moved to FAQ on Evolution.

Delivery Create a sub-directory called dealer and place all necessary files/modules for the data representation and the necessary methods into this sub-directory.

Task 2 Develop a test harness for feed1. The harness accepts a single JSON array from STDIN and writes a single JSON array to STDOUT. Both arrays represent (dealer) configurations: the input represents the state of the dealer before feed1 is called, and the output represents the state after the call, with the player list in the exact same order as the given one.

A Configuration is [LOP+, Natural, LOC].

Constraints The list of players contains at least three and at most eight items. The player specifications may not contain extinct species. The list of cards in a configuration together with the cards in possession of the players must make up a subset of the complete set of Evolution cards.

Interpretation The list of players describes all players participating in this game. It also specifies the order in which they take turns feeding their species.

The natural number is the number of food tokens at the watering hole.

The list of cards is the remaining deck of cards; the cards are handed out in this order.

A LOP+ is [Player+, ..., Player+].

A Player+ is one of
A plain Player has no cards. None of a player’s species may have a population of 0. Every species has at most three traits.

A LOC is [SpeciesCard, ..., SpeciesCard].

A SpeciesCard is [FoodValue, Trait].

A FoodValue is a JSON number interpretable as an integer between -8 and 8 (inclusive).

The JSON array must match one of the game cards allowed according to the specifications of Evolution.

Rendering Your classes should render objects as follows:

question

     

answer

Why does the test harness demand that the result configuration must contain all the players in the same order while task 1 suggests a rotation?

     

As explained in class, there is no connection between the representation of tests for the harness and the internal data representation. In this case, you are getting a free hint concerning the representation of the dealer.

     

Where does the integration test supply the answer when the dealer has to ask the player what to feed next?

     

The test integrates the silly player strategy from 7 — Changing an API.

     

Which player is to be fed next in the given configuration?

     

The dealer will provide food to the species boards of the first player, if possible. This does not have any implications for the API specified in 7 — Changing an API.

     

Delivery Place an executable called xstep into your main folder. Make sure it can be run from the command line like this:

    ./xstep < some-json-input > some-json-output

The xstep executable must use the method from task 1. It may assume that all test inputs satisfy the JSON specification above.

Shell scripts A script must start with #!/bin/sh or #!/bin/bash or #!/usr/bin/python17.3 etc. Don’t assume we supply whatever it takes to get it started.

As for 7 — Changing an API, we will try to start xstep on one of our tests first. If it doesn’t run, we will reduce your base points to 75% of the total and you will get 24 hours to fix the problem. After that, your project is considered failed.

Task 3 Write up a wish list of methods to complete the player. A wish list entry consists of a method signature, a purpose statement, and a method header.

Delivery Create the document as a plain text file and name it rest.txt. Place it in this week’s folder.