Page 1 of 1

Simulate actions

Posted: 28 May 2020, 01:46
by Tisaac
Hi !

I am currently working on Santorini and found myself in a situation where I need to determine if some kind of action is "possible" during the turn (effect that force the player to do that action if possible). In order to do that, I would like to explore the graphs of possibilities (BFS for instance), but since the new actions available after one action are hard to predict, it would be really nice if I can just use all the game states machines and functions to "simulate" the actions.
Is there any easy way to do this ?

Thanks,
Tisaac

Re: Simulate actions

Posted: 28 May 2020, 10:47
by RicardoRix
You can use the chat window to call any php game functions. Chat: Test() to directly call the php Test() function.

Re: Simulate actions

Posted: 28 May 2020, 11:17
by Tisaac
RicardoRix wrote: 28 May 2020, 10:47 You can use the chat window to call any php game functions. Chat: Test() to directly call the php Test() function.
But if I use the php functions, this will change my state, my bdd, ...
I would like to be able to call them in a "sandbox" like environment to compute some stuffs without touching to the state of the game.

Re: Simulate actions

Posted: 28 May 2020, 12:01
by RicardoRix
tbh, I'm not really sure what you're asking.

It will only change the state if inside the php function you change the game state - You have complete control over that.

If in the end you need to change game state and you have a lot of different ones, then it sounds like you'll need to test all these different possibilities anyway. If these abilities come from cards in the players hand say, then you can just rig a card hand with all the different cards at the same time. The chat function call at-least allows you to create a lot of test functions to quickly accomplish things.

Re: Simulate actions

Posted: 28 May 2020, 14:36
by Tisaac
Okay, let me be more precise.
On a turn, the player might perform some actions between the start and the end of the turn, but these actions are not easily predictable (depending on your power, the power of your opponent, ...). This complex logic is handled by the back-end that compute at each state (and depending on already taken actions) the next possible actions.
At the start of the turn, I want to know if there is a succession of actions that might result in a certain type of action available ("move up" in this case). My basic idea would be to simulate player to explore the graph, but by doing this it will change the current game state, notify everyone, change the database content, ...
So I was hoping I could do something easier than doing this and then rollback everything (which would require some heavy code modification), using some kind of sandbox environment.

Re: Simulate actions

Posted: 28 May 2020, 15:19
by vincentt
Hi,

Can't you use checkAction? if it return false, it means that is not authorized?

Vincent

Re: Simulate actions

Posted: 28 May 2020, 15:24
by Tisaac
vincentt wrote: 28 May 2020, 15:19 Hi,

Can't you use checkAction? if it return false, it means that is not authorized?

Vincent
No, because the action I'm looking for (move up) might only be available after another first action is done !
Maybe I can't move up on my first action, but with my power allowing me to move twice, I can move first on same height and then move up (unless another power applies, that's why I need the backend to handle all the powers).

Re: Simulate actions

Posted: 28 May 2020, 18:53
by RicardoRix
have an array of possible 'operations' (using a different word rather than 'actions'). Pass this array data in the setup and via notifications where an update to the array is appropriate.

If that doesn't work, then it sounds like you need a notification for each and every time.

A game like Innovation or Russian Railroads must be a very good example of this kind of complicated flow.

Re: Simulate actions

Posted: 28 May 2020, 19:53
by fafa-fr
Tisaac wrote: 28 May 2020, 01:46 it would be really nice if I can just use all the game states machines and functions to "simulate" the actions.
Is there any easy way to do this ?
I may not be the good person to answer here (maybe the admins or Alena could give a more authoritative answer), but I don't think there's an easy way to do this with BGA framework. You may have to write new code to compute possible actions. Of course you can reuse some of the code of the "real" actions, but without committing changes to DB and without actually changing gamestate.
(You could commit changes to DB if you make a backup copy of your tables at the beginning of possible moves computing, and restore this backup at the end, but I think you cant reuse completely the same code because it would not be a good idea to actually change state during this possible moves computing. Changing gamestate requires notifications to players and a lot of DB requests.)

Re: Simulate actions

Posted: 29 May 2020, 01:02
by Tisaac
fafa-fr wrote: 28 May 2020, 19:53
Tisaac wrote: 28 May 2020, 01:46 it would be really nice if I can just use all the game states machines and functions to "simulate" the actions.
Is there any easy way to do this ?
I may not be the good person to answer here (maybe the admins or Alena could give a more authoritative answer), but I don't think there's an easy way to do this with BGA framework. You may have to write new code to compute possible actions. Of course you can reuse some of the code of the "real" actions, but without committing changes to DB and without actually changing gamestate.
(You could commit changes to DB if you make a backup copy of your tables at the beginning of possible moves computing, and restore this backup at the end, but I think you cant reuse completely the same code because it would not be a good idea to actually change state during this possible moves computing. Changing gamestate requires notifications to players and a lot of DB requests.)
Ok, thanks for the answer, I was expecting that it's not easily doable.
I'll try to think what is the best way to do this without rewriting everything and otherwise I will just let this power un-implemented for the moment.