How to implement automatic moves for player?

Game development with Board Game Arena Studio
Post Reply
User avatar
Alex_tgiu
Posts: 59
Joined: 28 December 2020, 22:11

How to implement automatic moves for player?

Post by Alex_tgiu »

In my game, a player's turn consists of several moves, triggered by clicking a game element.
But often, the player has only one option, so I thought about letting the player decide via a user preference, if he wants those moves done automatically.
How do I automatically trigger the action which would normally be triggered by the click handler, so that the user sees the action and move is logged and performed just like manually?
User avatar
tchobello
Posts: 694
Joined: 18 March 2012, 13:19

Re: How to implement automatic moves for player?

Post by tchobello »

hello,

how do you know how many options the player have ?
What do you do then in order for the player to know which moves are possible ?

If you search possible options in PHP and then notify what game elements are clickable...
when you click on a game element, you go back to PHP to trigger the moves to this game element, I suppose.

If there is only one option (checkable), you don't need to go to Javascript and can jump instead directly to the function triggering the moves.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: How to implement automatic moves for player?

Post by Tisaac »

Alex_tgiu wrote: 19 August 2021, 06:13 In my game, a player's turn consists of several moves, triggered by clicking a game element.
But often, the player has only one option, so I thought about letting the player decide via a user preference, if he wants those moves done automatically.
How do I automatically trigger the action which would normally be triggered by the click handler, so that the user sees the action and move is logged and performed just like manually?
Two steps : store the preference in backend, add an st function to your state that will automatically do the action if only one choice and user pref is on.
User avatar
Alex_tgiu
Posts: 59
Joined: 28 December 2020, 22:11

Re: How to implement automatic moves for player?

Post by Alex_tgiu »

tchobello wrote: 19 August 2021, 07:30 how do you know how many options the player have ?
What do you do then in order for the player to know which moves are possible ?
I calculate on server side the possible actions in order to display them on the client. There I can see, when only one action is possible.
Tisaac wrote: 19 August 2021, 08:06 Two steps : store the preference in backend, add an st function to your state that will automatically do the action if only one choice and user pref is on.
I could just continue on server and do the automatic move.
But since it is a player action wich gets automatically executed, I'd like the player to see the action, just as if he had clicked it by himself. (And additionally have it in game log as a move.)
User avatar
robinzig
Posts: 461
Joined: 11 February 2021, 18:23

Re: How to implement automatic moves for player?

Post by robinzig »

Alex_tgiu wrote: 19 August 2021, 18:06
tchobello wrote: 19 August 2021, 07:30 how do you know how many options the player have ?
What do you do then in order for the player to know which moves are possible ?
I calculate on server side the possible actions in order to display them on the client. There I can see, when only one action is possible.
Tisaac wrote: 19 August 2021, 08:06 Two steps : store the preference in backend, add an st function to your state that will automatically do the action if only one choice and user pref is on.
I could just continue on server and do the automatic move.
But since it is a player action wich gets automatically executed, I'd like the player to see the action, just as if he had clicked it by himself. (And additionally have it in game log as a move.)
I am doing something similar in Deus (which is not quite ready for Alpha release yet, but hopefully very soon). You handle it in the same way as a player move - transitioning to the appropriate gamestate and sending the notification, which the client-side receives in order to both update the log and display the action to all players.

In essence, the state handler calculates the number of possible moves. If there are more than one, it transitions to an "activeplayer" type state so the player can choose - doing so triggers an action handler in your .game.php function. If there is only one, you can work out what the "automatic action" would be and call that same function yourself, so there is no difference between the two cases, other than one is triggered by a player action and the other automatically by the game.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: How to implement automatic moves for player?

Post by Tisaac »

robinzig wrote: 19 August 2021, 20:07
Alex_tgiu wrote: 19 August 2021, 18:06
tchobello wrote: 19 August 2021, 07:30 how do you know how many options the player have ?
What do you do then in order for the player to know which moves are possible ?
I calculate on server side the possible actions in order to display them on the client. There I can see, when only one action is possible.
Tisaac wrote: 19 August 2021, 08:06 Two steps : store the preference in backend, add an st function to your state that will automatically do the action if only one choice and user pref is on.
I could just continue on server and do the automatic move.
But since it is a player action wich gets automatically executed, I'd like the player to see the action, just as if he had clicked it by himself. (And additionally have it in game log as a move.)
I am doing something similar in Deus (which is not quite ready for Alpha release yet, but hopefully very soon). You handle it in the same way as a player move - transitioning to the appropriate gamestate and sending the notification, which the client-side receives in order to both update the log and display the action to all players.

In essence, the state handler calculates the number of possible moves. If there are more than one, it transitions to an "activeplayer" type state so the player can choose - doing so triggers an action handler in your .game.php function. If there is only one, you can work out what the "automatic action" would be and call that same function yourself, so there is no difference between the two cases, other than one is triggered by a player action and the other automatically by the game.
Exactly this.
User avatar
Alex_tgiu
Posts: 59
Joined: 28 December 2020, 22:11

Re: How to implement automatic moves for player?

Post by Alex_tgiu »

robinzig wrote: 19 August 2021, 20:07 I am doing something similar in Deus (which is not quite ready for Alpha release yet, but hopefully very soon). You handle it in the same way as a player move - transitioning to the appropriate gamestate and sending the notification, which the client-side receives in order to both update the log and display the action to all players.

In essence, the state handler calculates the number of possible moves. If there are more than one, it transitions to an "activeplayer" type state so the player can choose - doing so triggers an action handler in your .game.php function. If there is only one, you can work out what the "automatic action" would be and call that same function yourself, so there is no difference between the two cases, other than one is triggered by a player action and the other automatically by the game.
Ok, thanks, I'll try that.

But one more question: In the WIKI documentation I only see how to access the preference in JS - I'd need it in PHP, but how?
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: How to implement automatic moves for player?

Post by Tisaac »

Alex_tgiu wrote: 19 August 2021, 21:39
robinzig wrote: 19 August 2021, 20:07 I am doing something similar in Deus (which is not quite ready for Alpha release yet, but hopefully very soon). You handle it in the same way as a player move - transitioning to the appropriate gamestate and sending the notification, which the client-side receives in order to both update the log and display the action to all players.

In essence, the state handler calculates the number of possible moves. If there are more than one, it transitions to an "activeplayer" type state so the player can choose - doing so triggers an action handler in your .game.php function. If there is only one, you can work out what the "automatic action" would be and call that same function yourself, so there is no difference between the two cases, other than one is triggered by a player action and the other automatically by the game.
Ok, thanks, I'll try that.

But one more question: In the WIKI documentation I only see how to access the preference in JS - I'd need it in PHP, but how?
You can't. That's a well-known "missing" feature. You will need to store it yourself.
I've posted some tutorial for that on the dev discord a while back, haven't took the time to add it to the wiki yet.
Post Reply

Return to “Developers”