You should turnin a mlstone.sml ML source code file that is
executable from the command-line using sml mlstone.sml
.
It should have your name in an ML comment at the top.
Use ML to implement the following program. Write a header comment for each function, and internal comments as needed. Basic points for correctness. Extra points for clarity and brevity. You should write helper functions as needed for your solution. If you find a built-in function or external source that does part or all of the solution for you, feel free to use it. For external sources, be sure to cite what you incorporated and where it came from.
For this assignment you are to write a "MLStone" game in ML.
MLStone is a ultra-simplified cheesy interactive card game for two players: in this case, a human called "Player" versus a computer called "AI".
( cost, spellp, name, attack, health )with semantics as follows. All numbers are integers.
Field | Meaning as Minion | Meaning as Spell, if different |
---|---|---|
cost | energy needed to play the card | |
spellp | false for minions | true for spell cards |
name | String name of the card. While it is pure decoration, it allows decks of cards to have a fun theme. | |
attack | damage the minion can do each turn | damage the spell does (once) |
health | cumulative damage to kill the minion | the spell heals this much health |
Symbol | Meaning |
---|---|
Health | Player's health. Integer, starts at 30. <=0 means enemy wins |
AIHealth | Computer player's health. Integer, starts at 30. <=0 means player wins |
Energy | Energy available for play. Integer >= 0. Set from the game turn number at the start of each player's turn, and expended by playing cards. |
Hand | List of lists. Each element sublist represents a card that may be played. |
AIHand | List of lists. Each element sublist represents a card that may be played. |
Minions | List of lists. Each element sublist represents a creature that is available to help the player. Format of elements is identical to the card format described above, except that the first two elements (energy and spellp) are omitted. |
Monsters | List of lists. Each element sublist represents a creature that is available to help the computer player. Format of elements is identical to the card format described above, except that the first two elements (energy and spellp) are omitted. |
use
function
from a file named "game.sml", formatted as legal ML code
assignments to these symbols. Example:
val Health=30; val AIHealth=30; val Hand=[ (1, false, "C slug", 0, 1), (1, false, "int", 1, 1), (1, true, "++", 0, 1), (1, true, "^=", 4, 0), (2, false, "for (;;)", 2, 2), (3, false, "switch", 3, 3), (4, false, "array a[100]", 4, 4), (4, true, "Bus Error Fireball", 6, 0) ]; val AIHand=[ (1, true, "Atom", 0, 1), (1, true, "Car", 1, 0), (1, true, "Cdr", 2, 0), (1, false, "Parenthesis", 1, 1), (2, false, "Cons Cell", 2, 1), (2, false, "defun", 3, 2), (3, true, "Mapcar", 4, 0), (4, false, "ML Monster", 2, 6) ];The Minions and Monsters lists always start empty, but of course a saved game might add assignments of those variables to the file. Similarly the energy available is derived from the current turn number, which starts at 1, but a Saved Game would add an assignment to Energy to indicate the turn number.
set turn to 1 repeat forever set player energy to equal turn number print game state while player is not finished do ; PLAYER TURN (read-eval-print loop) read player command evaluate player command if Player is dead, print message and exit if AI is dead, print message and exit print game state set AI energy to equal turn number while AI is not finished to ; AI TURN select AI command evaluate AI command if Player is dead, print message and exit if AI is dead, print message and exit print game state increment turn
read-line
and then parse, or
prompt them for each piece of the command separately in order
to avoid having to parse their replies into multiple variables.
You are allowed to use assignments to store the input into variables,
either setq or let, or by passing their input as parameters into
other functions.