Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/eXene/examples/explode/explode.sml
ViewVC logotype

Annotation of /sml/trunk/src/eXene/examples/explode/explode.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : monnier 2 (* explode.sml
2 :     *
3 :     * NOTE: there are two implementation strategies for this:
4 :     * (1) a centeralized implementation that seperates the game engine
5 :     * from the interface, and
6 :     * (2) a distributed implementation that more tightly couples the
7 :     * engines for the nodes with the widgets that represent them.
8 :     *)
9 :    
10 :     signature GAME_GRAPH =
11 :     sig
12 :     type node
13 :    
14 :     val neighbors : node -> node list
15 :     (* returns the list of neighbors of this node *)
16 :     val degree : node ->int
17 :     (* returns the number of edges *)
18 :     val state : node -> {player:int, npebbles} option
19 :     (* returns the current state of the node, which can be
20 :     * empty (NONE), or have some number of pebbles belonging
21 :     * to some player.
22 :     *)
23 :     val setState : (node * {player:int, npebbles} option) -> unit
24 :     end
25 :    
26 :     functor Explode (G : GAME_GRAPH) =
27 :     struct
28 :    
29 :     fun placePebble (nd, player) = let
30 :     val n = (case (G.state nd)
31 :     of NONE => (
32 :     G.setState (nd, SOME{player=player, npebbles=1});
33 :     1)
34 :     | (SOME{player=p, npebbles}) =>
35 :     if (p <> player) then raise Illegal
36 :     else (
37 :     G.setState (nd,
38 :     SOME{player=p, npebbles=npebbles+1});
39 :     npebbles+1)
40 :     (* end case *))
41 :     in
42 :     if (G.degree nd = n)
43 :     then (
44 :     G.setState (nd, NONE);
45 :     explode (player, G.neighbors nd))
46 :     else ()
47 :     end
48 :    
49 :     end;

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0