Skip to content

Commit

Permalink
Add function binbo:set_game_state/2
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBRO committed Aug 12, 2020
1 parent 55fd0f9 commit 5fd6542
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/binbo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-export([new_server/0, new_server/1]).
-export([get_server_options/1, set_server_options/2]).
-export([new_game/1, new_game/2]).
-export([game_state/1, game_status/1, side_to_move/1]).
-export([game_state/1, set_game_state/2, game_status/1, side_to_move/1]).
-export([move/2, san_move/2, get_fen/1]).
-export([load_pgn/2, load_pgn_file/2]).
-export([game_draw/1, game_draw/2]).
Expand Down Expand Up @@ -138,6 +138,11 @@ load_pgn_file(Pid, Filename) ->
game_state(Pid) ->
binbo_server:game_state(Pid).

%% set_game_state/2
-spec set_game_state(pid(), term()) -> binbo_server:game_status_ret().
set_game_state(Pid, Game) ->
binbo_server:set_game_state(Pid, Game).

%% game_status/1
-spec game_status(pid()) -> binbo_server:game_status_ret().
game_status(Pid) ->
Expand Down
10 changes: 9 additions & 1 deletion src/binbo_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
-export([stop/1]).
-export([new_game/2, game_move/2, game_san_move/2, get_fen/1]).
-export([load_pgn/2, load_pgn_file/2]).
-export([game_state/1, game_status/1, game_draw/2]).
-export([game_state/1, set_game_state/2, game_status/1, game_draw/2]).
-export([all_legal_moves/2, side_to_move/1]).
-export([new_uci_game/2]).
-export([uci_command_call/2, uci_command_cast/2]).
Expand Down Expand Up @@ -213,6 +213,9 @@ do_handle_call({load_pgn, Type, Data}, _From, State) ->
{reply, Reply, NewState};
do_handle_call(game_state, _From, #state{game = Game} = State) ->
{reply, Game, State};
do_handle_call({set_game_state, Game}, _From, State) ->
Reply = binbo_game:status(Game),
{reply, Reply, State#state{game = Game}};
do_handle_call(game_status, _From, #state{game = Game} = State) ->
Reply = binbo_game:status(Game),
{reply, Reply, State};
Expand Down Expand Up @@ -419,6 +422,11 @@ load_pgn_file(Pid, Filename) ->
game_state(Pid) ->
call(Pid, game_state).

%% set_game_state/2
-spec set_game_state(pid(), term()) -> game_status_ret().
set_game_state(Pid, Game) ->
call(Pid, {set_game_state, Game}).

%% game_status/1
-spec game_status(pid()) -> game_status_ret().
game_status(Pid) ->
Expand Down

0 comments on commit 5fd6542

Please sign in to comment.