Skip to content

Commit f4eb9c1

Browse files
committed
Handling undo dialog.
1 parent f4148fd commit f4eb9c1

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

bot/bot.rml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ let process main text mask position reset =
2828
emit reset pos_init;
2929
pause
3030
| Intent_undo ->
31-
print_endline "Undo not implemented"; (* XXX TODO XXX *)
31+
let n = run Dialog.get_undo conf text position in
32+
print_endline ("Undo("^(string_of_int n)^") not implemented"); (* XXX TODO XXX *)
3233
pause
3334
| Intent_resign ->
3435
print_endline "Resign not implemented"; (* XXX TODO XXX *)

bot/config_bot.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ let wcs_workspace_piece_id = ref None
2828
let set_wcs_workspace_piece_id s =
2929
wcs_workspace_piece_id := Some s
3030

31+
let wcs_workspace_undo_id = ref None
32+
let set_wcs_workspace_undo_id s =
33+
wcs_workspace_undo_id := Some s
34+
3135
let options =
3236
[ ("-wcs-user", Arg.String set_wcs_user,
3337
"username Set the Watson Conversation Service user name");
@@ -43,6 +47,8 @@ let options =
4347
"workspace Set the Watson Conversation Service workspace id for intent dispatch questions");
4448
("-wcs-workspace-piece", Arg.String set_wcs_workspace_piece_id,
4549
"workspace Set the Watson Conversation Service workspace id for piece questions");
50+
("-wcs-workspace-undo", Arg.String set_wcs_workspace_undo_id,
51+
"workspace Set the Watson Conversation Service workspace id for undo questions");
4652
]
4753

4854
(* Must be called after Arg.parse. *)
@@ -52,20 +58,23 @@ let get () =
5258
!wcs_workspace_castling_id,
5359
!wcs_workspace_turn_id,
5460
!wcs_workspace_intent_dispatch_id,
61+
!wcs_workspace_undo_id,
5562
!wcs_workspace_piece_id) with
5663
| Some wcs_user, Some wcs_password,
5764
Some wcs_workspace_square_id,
5865
Some wcs_workspace_castling_id,
5966
Some wcs_workspace_turn_id,
6067
Some wcs_workspace_intent_dispatch_id,
68+
Some wcs_workspace_undo_id,
6169
Some wcs_workspace_piece_id ->
6270
{ wcs_user = wcs_user;
6371
wcs_password = wcs_password;
6472
wcs_workspace_square_id = wcs_workspace_square_id;
6573
wcs_workspace_castling_id = wcs_workspace_castling_id;
6674
wcs_workspace_turn_id = wcs_workspace_turn_id;
6775
wcs_workspace_intent_dispatch_id = wcs_workspace_intent_dispatch_id;
68-
wcs_workspace_piece_id = wcs_workspace_piece_id; }
76+
wcs_workspace_piece_id = wcs_workspace_piece_id;
77+
wcs_workspace_undo_id = wcs_workspace_undo_id; }
6978
| _ ->
7079
Arg.usage options "Need all workspace identifiers.";
7180
exit 1

bot/context_types.atd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ type context = {
55
?color : string option;
66
?dispatch : string option;
77
?filled : string option;
8+
?undo_half_moves <json name="undo-half-moves"> : int option;
89
} <ocaml field_prefix="ctx_">

bot/dialog.rml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ let process get_intent wcs_config text : intent_dispatch process =
147147
run get_value wcs_config wcs_config.wcs_workspace_intent_dispatch_id text
148148
ctx txt turn_of_resp
149149

150+
let process get_undo wcs_config text position : int process =
151+
let ctx =
152+
let total_moves =
153+
begin match (last ?position) with
154+
| Some (_, p) -> p.number
155+
| None -> max_int
156+
end
157+
in
158+
json_of_string
159+
("{ \"totalmoves\": "^(string_of_int total_moves)^" }")
160+
in
161+
let undo_half_moves_of_resp resp =
162+
begin match context_of_json resp.rsp_context with
163+
| Some { ctx_undo_half_moves = Some n } -> Some n
164+
| _ -> None
165+
end
166+
in
167+
run get_value wcs_config wcs_config.wcs_workspace_undo_id text
168+
ctx "" undo_half_moves_of_resp
169+
150170

151171
let rec process await_new_mask_diff mask m_init prev_diff =
152172
await mask (Some m) in

bot/types_bot.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type wcs_config = {
1010
wcs_workspace_turn_id : string;
1111
wcs_workspace_intent_dispatch_id : string;
1212
wcs_workspace_piece_id : string;
13+
wcs_workspace_undo_id : string;
1314
}
1415

1516
type intent_dispatch =

bot/types_bot.rmli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type wcs_config = {
88
wcs_workspace_turn_id : string;
99
wcs_workspace_intent_dispatch_id : string;
1010
wcs_workspace_piece_id : string;
11+
wcs_workspace_undo_id : string;
1112
}
1213

1314
type intent_dispatch =

0 commit comments

Comments
 (0)