-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.sml
51 lines (40 loc) · 1.42 KB
/
Game.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use "Table.sml";
structure Game =
struct
type suit = Card.suit
type card = Card.card
type player = Player.player
type table = Table.table
datatype action = Play (* attack or defend *)
| Stay (* refrain from attacking *)
| Giveup (* concede attack and pick up cards *)
datatype moveF = AttackF of int -> player -> card -> player -> table -> player * table
| DefendF of player -> card -> card -> table -> suit -> player * table
(* for capturing move *)
datatype move = Draw of Player.player * Card.card list
| Attack of Player.player * Player.player * Card.card
| Defend of Player.player * Card.card * Card.card
| Pickup of Player.player * Card.card list
| Skip of Player.player
| Clear of Card.card list
exception NoPlayers
exception InvalidMove
exception NotImplemented
val moveMap1 = [(#"1", AttackF Table.attackUntil),
(#"2", DefendF Table.defend)]
fun readKey moveMap =
case TextIO.input1 TextIO.stdIn of
NONE => readKey moveMap
| SOME c => (case List.find (fn (k,_) => k = c) moveMap of
SOME (k,m) => SOME m
| _ => raise InvalidMove)
(* fun game ps deck = *)
(* let fun loop (ps, deck, tbl, moves) = *)
(* case ps of *)
(* [] => raise NoPlayers *)
(* | p::[] => moves *)
(* | at::df::ps' => *)
(* in *)
(* loop (ps, deck, Table.Table [], []) *)
(* end *)
end