Permalink
Browse files

[fix] some updates in tictactopa

 * patching for nullary lambda
 * correcting a bug in ColSet.specialize
 * removing the warnings, add the flag warn-error root
 * completing documentation of funaction handler
  • Loading branch information...
1 parent 3a80167 commit 90a7efde77f269a91e9f05b5f78feba808c0925b Mathieu Barbin committed Jan 27, 2011
Showing with 49 additions and 31 deletions.
  1. +3 −3 multitub/multitub.opa
  2. +0 −1 src/client.opa
  3. +2 −9 src/colset.opa
  4. +18 −5 src/funaction.opa
  5. +9 −5 src/game.opa
  6. +14 −6 src/grid.opa
  7. +2 −2 src/ia.opa
  8. +1 −0 tictactopa.opack
View
@@ -1,5 +1,5 @@
/*
- * OPA design pattern collection. (c) MLstate - 2010
+ * OPA design pattern collection. (c) MLstate - 2011
*
* The Mutlitub pattern, for OPA-S3.
* @author Mathieu Barbin
@@ -130,7 +130,7 @@ type Multitub.C.interface('state) = {
* may be imperative, there are no reason to forbid it, e.g. wrt performances
* depending on the kind of the application.
**/
- init : void -> 'state
+ init : -> 'state
/**
* Handle messages received from the server, or from some funaction in the page.
@@ -184,7 +184,7 @@ type Multitub.S.interface('state) = {
* The initializer is not functionnal because the state of the server
* may be imperative.
**/
- init : void -> 'state
+ init : -> 'state
/**
* Some initialization may be necessary once the server knows the client.
View
@@ -238,7 +238,6 @@ clear() =
token = ClientToken.token(location)
do ClientToken.clear(token)
void
- columns = pred
do Loop.for2((0, GameParameters.dimensions.columns - 1), (0, GameParameters.dimensions.lines - 1), clear_token)
void
View
@@ -1,5 +1,5 @@
/*
- * Tictactopa. (c) MLstate - 2010
+ * Tictactopa. (c) MLstate - 2011
* @author Mathieu Barbin
**/
@@ -78,14 +78,7 @@ type ColSet.t = int
specialize(setA, setB) =
inter = inter(setA, setB)
- if is_empty(inter) then setA else setB
-
- priority_inter(list : list(ColSet.t), set : ColSet.t) =
- fold_inter(set, acc) = specialize(acc, set)
- match list with
- | { nil } -> empty
- | ~{ hd tl } ->
- List.fold(fold_inter, tl, hd)
+ if is_empty(inter) then setA else inter
/**
* Pick a random elt in the set.
View
@@ -9,17 +9,30 @@
@client @package Funaction = {{
-onclick_token(s_channel : Multitub.S.channel, c_channel : Multitub.C.channel, location : Grid.location, _) =
- i = location.column
- j = location.line
+/**
+ * The client has perform a click on the grid.
+ * In this case, we pass through the client tube, and send to it the [click] message
+ * No direct interaction with the server tube with this event.
+**/
+onclick_token(_ : Multitub.S.channel, c_channel : Multitub.C.channel, location : Grid.location, _) =
do Multitub.send_client(c_channel, {funaction = { click = location } })
void
-restart(s_channel : Multitub.S.channel, c_channel : Multitub.C.channel, _) =
+/**
+ * The client has perform a click on the "start a new game" button.
+ * In this case, we pass through the client tube, and send to it the [restart] message
+ * No direct interaction with the server tube with this event.
+**/
+restart(_ : Multitub.S.channel, c_channel : Multitub.C.channel, _) =
do Multitub.send_client(c_channel, {funaction = {restart}})
void
-level(s_channel : Multitub.S.channel, c_channel : Multitub.C.channel, dom_level : dom, _) =
+/**
+ * The client has perform a click on the level toggle button.
+ * In this case, we pass direclty through the server tube, and send to it the [ia_parameters] message
+ * No direct interaction with the client tube with this event.
+**/
+level(s_channel : Multitub.S.channel, _ : Multitub.C.channel, dom_level : dom, _) =
value = Dom.get_value(dom_level)
level = int_of_string_unsafe(value)
do Multitub.send_server(s_channel, {ia_parameters = { ~level }})
View
@@ -1,5 +1,5 @@
/*
- * Tictactopa. (c) MLstate - 2010
+ * Tictactopa. (c) MLstate - 2011
* @author Mathieu Barbin
**/
@@ -249,9 +249,9 @@ type Game.state = {
* Status detection:
* From a non {free} case, follow from a location in a given direction as long as
* the content does not change, or the value exceed goal. In this case, return the
- * corresponding player.
+ * corresponding player, else return [none]
**/
- follow(grid : Game.grid, i, j, direction : Grid.location) =
+ follow(grid : Game.grid, i, j, direction : Grid.location) : Game.winner =
goal = GameParameters.goal
columns = GameParameters.dimensions.columns
lines = GameParameters.dimensions.lines
@@ -280,7 +280,7 @@ type Game.state = {
* Follow in every direction (4), from every non-free location.
* Stops with the first success
**/
- status(grid : Game.grid) =
+ status(grid : Game.grid) : Game.winner =
h = { column = 1 ; line = 0 }
v = { column = 0 ; line = 1}
du = { column = 1 ; line = 1 }
@@ -368,9 +368,13 @@ type Game.state = {
GameUtils.count(grid, snd)
total = GameParameters.dimensions.columns * GameParameters.dimensions.lines
match GameUtils.status(grid) with
- | ({some=player}) as winner ->
+ | ({some=_}) as winner ->
{ winner = winner }
| _ ->
+ /*
+ In case [GameUtils.status = none], it could means that the game is over with exaeco,
+ or if the grid is not full, that the game is still in progress.
+ */
if total == n_fst + n_snd
then
{ winner = none }
View
@@ -1,5 +1,5 @@
/*
- * Tictactopa. (c) MLstate - 2010
+ * Tictactopa. (c) MLstate - 2011
* @author Mathieu Barbin
**/
@@ -128,15 +128,23 @@ type Grid.t('content) = {
dimensions(grid : Grid.t) = grid.dimensions
/**
+ * Get the content of a location in the content of a grid.
+ * Low level function, not exported.
+ * @errors(Unspecified in case of index out of bounds)
+ **/
+ @private getij_t(t : llarray(llarray('content)), column : Grid.column, line : Grid.line) =
+ t_line = LowLevelArray.get(t, column)
+ content = LowLevelArray.get(t_line, line)
+ content
+
+ /**
* Get the content of a location in a grid.
* Interface usefull for loops.
* @errors(Unspecified in case of index out of bounds)
**/
getij(grid : Grid.t, column : Grid.column, line : Grid.line) =
t = grid.t
- t_line = LowLevelArray.get(t, column)
- content = LowLevelArray.get(t_line, line)
- content
+ getij_t(t, column, line)
/**
* Get the content of a location in a grid.
@@ -193,7 +201,7 @@ type Grid.t('content) = {
dimensions = grid.dimensions
columns = dimensions.columns
lines = dimensions.lines
- t = grid.t
+ grid_t = grid.t
column = location.column
line = location.line
min_c = max(0, column - dist)
@@ -207,7 +215,7 @@ type Grid.t('content) = {
else
if ((i == column) && (j == line)) then aux(i, succ(j), acc)
else
- acc = fold(getij(grid, i, j), acc)
+ acc = fold(getij_t(grid_t, i, j), acc)
aux(i, succ(j), acc)
aux(min_c, min_l, acc)
View
@@ -1,5 +1,5 @@
/*
- * Tictactopa. (c) MLstate - 2010
+ * Tictactopa. (c) MLstate - 2011
* @author Mathieu Barbin
*/
@@ -79,7 +79,7 @@ IA_Winning = {{
p = ( p : Game.player ) <: Game.content
GameContent.equal(player, p)
| _ -> false
- grid = Grid.setij(grid, i, j, {free})
+ _grid = Grid.setij(grid, i, j, {free})
res
compute(grid : Game.grid, win : IA.winning_grid) : IA.winning_grid =
View
@@ -1,4 +1,5 @@
# sources for tictactopa
+--warn-error root
src/colset.opa
src/grid.opa
src/game.opa

0 comments on commit 90a7efd

Please sign in to comment.