Permalink
Browse files

[bug fix] avoiding the good old 'incoherent state' error

well the patch is mostly from mathieu, of course
  • Loading branch information...
1 parent 2be6ac9 commit 5336097a43b460df270a1013118dbac4a1021ab7 Valentin Gatien-Baron committed Jun 9, 2011
Showing with 35 additions and 14 deletions.
  1. +7 −0 src/client.opa
  2. +15 −7 src/client_implementation.opa
  3. +1 −1 src/funaction.opa
  4. +8 −3 src/ia.opa
  5. +1 −1 src/messages.opa
  6. +3 −2 src/server_implementation.opa
View
@@ -342,6 +342,13 @@ xhtml(s_channel : Multitub.S.channel, c_channel : Multitub.C.channel) =
set_status(status : string) =
do Dom.transform([ #{status_id} <- status ])
void
+
+ /**
+ * Set the ia level on the input (at initialization)
+ **/
+ set_level(level : IA.level) =
+ do Dom.set_value(#{level_id}, string_of_int(level))
+ void
}}
/**
@@ -34,6 +34,11 @@ type C.implementation.state = {
**/
client_num : int
server_num : int
+
+ /**
+ * A flag indicating if the game is over
+ **/
+ game_over : bool
}
/**
@@ -77,7 +82,8 @@ type C.implementation.state = {
server_num = 0
date = 0
player = {Y}
- state = ~{ client_num server_num date player }
+ game_over = false
+ state = ~{ client_num server_num date player game_over }
state : C.implementation.state
/**
@@ -91,28 +97,30 @@ type C.implementation.state = {
do ClientLayout.jlog(message)
{unchanged}
- | { who_you_are = player ; ~date } ->
+ | { who_you_are = player ; ~level ; ~date } ->
+ do ClientLayout.set_level(level)
do ClientLayout.set_player(player)
do ClientGrid.clear()
client_num = 0
server_num = 0
date = date ? state.date
- state = ~{ state with client_num server_num player date }
+ game_over = false
+ state = ~{ state with client_num server_num player date game_over }
do ClientUtils.status(state)
{set = state}
| { ~winner } ->
match winner with
| {none} ->
- do ClientLayout.set_status("EXAECO !")
- {unchanged}
+ do ClientLayout.set_status("EXAEQUO !")
+ { set = { state with game_over=true} }
| { some = player } ->
do if GameContent.equal_player(player, state.player)
then
ClientLayout.set_status("YOU WIN :)")
else
ClientLayout.set_status("YOU LOOSE :(")
- {unchanged}
+ { set = { state with game_over=true} }
end
| ~{ player location date } ->
state =
@@ -132,7 +140,7 @@ type C.implementation.state = {
| { ~funaction } ->
match funaction with
| { click = location } ->
- if not(ClientUtils.my_turn(state))
+ if not(ClientUtils.my_turn(state)) || state.game_over
then {unchanged}
else
date = state.date
View
@@ -34,7 +34,7 @@ restart(_ : Multitub.S.channel, c_channel : Multitub.C.channel, _) =
**/
level(s_channel : Multitub.S.channel, _ : Multitub.C.channel, dom_level : dom, _) =
value = Dom.get_value(dom_level)
- level = int_of_string_unsafe(value)
+ level = int_of_string_unsafe(value) : IA.level
do Multitub.send_server(s_channel, {ia_parameters = { ~level }})
void
View
@@ -15,9 +15,14 @@ import tictactopa.{colset,grid}
**/
/**
+ * The type representing the level of the IA
+**/
+type IA.level = int
+
+/**
* Supported level of the IA.
**/
-type IA.parameters = {level : int}
+type IA.parameters = {level : IA.level}
/**
* We use a 2 dimension Grid for seing if a location make a player win.
@@ -153,9 +158,9 @@ IA_Winning = {{
Parameters = {{
- max_level = 4
+ max_level = 4 : IA.level
- default = { level = 0 } : IA.parameters
+ default = { level = max_level } : IA.parameters
/**
* Return a level in the bounds of the ia.
View
@@ -110,7 +110,7 @@ type Multitub.C.message =
* If the server should start, the date is not given, so that every action
* sent to the server before it has had the time to play would be ignored.
**/
- / { who_you_are : Game.player ; date : option(Multitub.message.date) }
+ / { who_you_are : Game.player ; level : IA.level ; date : option(Multitub.message.date) }
/**
* The server wants to notify the client that the game is over.
@@ -70,9 +70,10 @@ type S.implementation.state = {
server_starts =
GameContent.equal_player(server_player, GameParameters.first_player)
game = Game.reset(state.game)
+ level = state.game.ia.level
if server_starts
then (
- do Multitub.send_client(c_channel, { who_you_are = client_player ; date = none })
+ do Multitub.send_client(c_channel, { who_you_are = client_player ; ~level ; date = none })
action = IA.compute(game)
match GameUtils.free_line(game.grid, action) with
| {none} -> @fail("IA returns an illicit action")
@@ -85,7 +86,7 @@ type S.implementation.state = {
)
else (
date = generate_date()
- do Multitub.send_client(c_channel, { who_you_are = client_player ; date = some(date) })
+ do Multitub.send_client(c_channel, { who_you_are = client_player ; ~level ; date = some(date) })
{ state with ~date ; ~game ; player = server_player }
)

0 comments on commit 5336097

Please sign in to comment.