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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (download) (annotate)
Sat Oct 4 23:33:09 1997 UTC (22 years, 10 months ago) by monnier
File size: 1314 byte(s)
Initial revision
(* explode.sml
 *
 * NOTE: there are two implementation strategies for this:
 *  (1) a centeralized implementation that seperates the game engine
 *      from the interface, and
 *  (2) a distributed implementation that more tightly couples the
 *      engines for the nodes with the widgets that represent them.
 *)

signature GAME_GRAPH =
  sig
    type node

    val neighbors : node -> node list
	(* returns the list of neighbors of this node *)
    val degree : node ->int
	(* returns the number of edges *)
    val state : node -> {player:int, npebbles} option
	(* returns the current state of the node, which can be
	 * empty (NONE), or have some number of pebbles belonging
	 * to some player.
	 *)
    val setState : (node * {player:int, npebbles} option) -> unit
  end

functor Explode (G : GAME_GRAPH) =
  struct

    fun placePebble (nd, player) = let
	  val n = (case (G.state nd)
		 of NONE => (
		      G.setState (nd, SOME{player=player, npebbles=1});
		      1)
		  | (SOME{player=p, npebbles}) =>
		      if (p <> player) then raise Illegal
		        else (
			  G.setState (nd,
			    SOME{player=p, npebbles=npebbles+1});
			  npebbles+1)
		(* end case *))
	  in
	    if (G.degree nd = n)
	      then (
		G.setState (nd, NONE);
		explode (player, G.neighbors nd))
	      else ()
	  end

  end;

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