6 — Incremental refinement, the second step
Due Sunday, 21 February, midnight Wednesday, 24 February, noon
Your software architect has determined that the dealer can perform some actions of the feeding step without input from the players. For example, if a player possesses a single hungry species and there is food available at the watering hole, the rules dictate that the player will feed this species. Similarly, if a player is in possession of a single hungry carnivore and only one other player has an attackable species, then the former will launch the attack on the latter. The dealer ought to ask the player, however, if it is willing to attack one its own species with such a single hungry carnivore. In other situations, the dealer must interact with the player and acquire the necessary information before it can take the next step in the feeding cycle.
Since this interaction is the most complex part of the player-dealer interaction, your architect asked for the attackable? method last week and now requests a method that implements a sample strategy for picking the next species to be fed.
Rule Change After some reflection, your software architect has also decided to disallow duplicate trait cards for a species.
Carnivores cannot attack themselves or, succinctly, carnivores are not cannibals.
If a species becomes extinct due to an attack, its food is lost to the player and the species board is immediately removed from the player’s possession. The player receives two cards at the end of the turn for this loss.
Task 1 Design a data representation for the players of the Evolution game.
Develop a function (method) that determines a player’s next species to be fed. Recall that this may be either a vegetarian or a carnivore. In the latter case, the response must not only specify which carnivore to feed but also which species it will attack and to which player this species belongs.
- Its type signature dictates that it consumes representations of the other players, in case one of the player’s carnivores must attack a species of some other player. The result type ought to describe the following possibilities:
one of its own species with the fat-tissue trait and the number of tokens it wishes to store
one of its own vegetarian species
one of its own carnivores plus a different player and one of this player’s species
an indication that it does not wish to feed any species anymore.
Its behavioral contract adds that the second and third kind of results must be "hungry" species and that in the third case, the first species can successfully attack the second one.
The sequencing constraints of the method implies that there is some food at the watering hole and that the player is in possession of at least two hungry species or of a carnivore that must decide which species to attack, if any.
If any species has a fat-tissue trait, the player will first request as much food as this trait allows. In case, more than one species has the fat-tissue trait, the player picks the one with the largest need for fat-tissue food. Finally, if two or more species have a largest need for fat-tissue food, the player goes by an order on species (specified below) and, secondary to that, uses the order of species boards.
If any of its vegetarians is still hungry, it feeds the largest one of those next. Ties are broken by the order of the species boards.
If there are no hungry vegetarians, the player use the largest carnivore that can attack some other species from the other players It attacks the largest species that can be attacked. A tie is broken with the order in which the players are given; the first player’s species in this ordering is picked; within the player, the strategy breaks ties via the ordering of the player’s species boards.
The player will not use one of its carnivores to attack any of its own species.
Ordering Species are ordered in a lexicographic manner, starting with the (plain) population attribute, followed by the food that the species has been fed so far, and finally the (plain) body size.
Delivery Create a sub-directory called feeding and place all necessary files/modules for the data representation and the method into this sub-directory.
Task 2 Develop a test harness for the method that accepts a single JSON expression from STDIN and writes its results to STDOUT after turning it into JSON.
false, meaning the only possibility is to have one of this player’s species attack some other species and the player chooses to forgo any attack now and for the rest of this turn;
Species+, meaning the species is vegetarian and gets the next token of food;
[Species+, Nat], meaning the species comes with a fat-tissue trait and wishes to store the specified number of food tokens;
[Species+, Player, Species+], meaning the first species attacks the second species, which belongs to the given player.
A Feeding is [Player, Natural+, LOP]. The natural number in the middle specifies how many tokens of food are left at the watering hole.
A LOP is [Player, ..., Player]; the list might be empty.
A LOS is [Species+, ..., Species+]; the list might be empty.
A Natural+ is a JSON number interpretable as a natural number larger than, or equal to, 1.
A Natural is a JSON number interpretable as a natural number.
a regular Species
a Species with a "fat-food" field:
[["food",Nat],
["body",Nat],
["population",Nat+],
["traits",LOT]
["fat-food" ,Nat]]
The additional field specifies how much food is stored on the species’s fat-tissue card. The specification is inconsistent if the traits list does not come with the trait "fat-tissue".
./xfeed < some-json-input > some-json-output |
./compile |
Implied by 4 —
Task 3 Study how a dealer (1) decides whether to call the above method for a player when it is the player’s turn to feed a species and (2) applies the results of the above method to the state of the game.
Delivery Write a one-page PDF memo and name it feed.pdf. There is no need for any header material other than a subject line and your names. Place the document into the folder for this project.
question
answer
What should xfeed produce if the JSON is well-formed but violates some other constraint(s)?
Your program should not return anything in this case.
The rest was moved to FAQ on Evolution.