Page 1 of 1

Pie Rule

Posted: 22 October 2015, 19:46
by ZPolansky
Hello!

I am currently working on a game with BGAstudio, and I am almost done, but I have one rule left to implement.
It's the "Pie rule", where the player to go second may choose, after the first move only, to go first and take the opponent's move as their own.
This is seen in games like Hex and Kalah already on here.

Currently, I have made the appropriate game states and buttons and have those working, I just need to switch the players when necessary.
I have:

Code: Select all

$sql = "UPDATE player SET player_color = '000000' WHERE player_color = 'AAAAAA'"; //000000 is a tempcolor, to switch AAAAAA and 555555
self::DbQuery( $sql );
$sql = "UPDATE player SET player_color = 'AAAAAA' WHERE player_color = '555555'";
self::DbQuery( $sql );
$sql = "UPDATE player SET player_color = '555555' WHERE player_color = '000000'";
self::DbQuery( $sql );
but that seems to only switch the players' scores, and not the colors for the player panels. I don't really know how to mess around with the player panels, or anything like that. Anyone know what I should be doing?

Re: Pie Rule

Posted: 24 October 2015, 09:39
by Rudolf
Hello,
bravo for your work...
first an advice:
maybe you could use WHEN and THEN in your mysql request to make only one call to db
set color = WHEN ..... THEN .... WHEN ... THEN

with that, no need of tempcolor...

second don't you forget to notify change and manage the change in javascript file ?

Re: Pie Rule

Posted: 24 October 2015, 12:47
by Rudolf

Code: Select all

$sql = "UPDATE player SET player_color = CASE  player_color  WHEN 'AAAAAA' THEN '555555'  WHEN '555555' THEN 'AAAAAA' END WHERE player_color in( '555555','AAAAAA') ";


WHERE is there to optimize search speed but not essential...

Re: Pie Rule

Posted: 24 October 2015, 17:36
by ZPolansky
Thank you for the advice. However, my main problem is how to swap the players (e.g. the colors of the names on the player panels).

Re: Pie Rule

Posted: 24 October 2015, 23:38
by Rudolf
As I said, you have to play with javascript code (not only php) ;):
launch a notify from php (for example notifyallplayers ('changecolors',....
and manage notify_changecolors in your javascript file to change
after setup, php is not synchronized with javascript until next refresh /F5...
you can also force a F5...another trick.

Re: Pie Rule

Posted: 25 October 2015, 00:45
by ZPolansky
Yes I understand that, but I don't know how to make the player panels change color. I can't find what makes them the colors they are.

Even with the database player_color swapped, even if the js goes through a refresh, the player panels remain the same.

Re: Pie Rule

Posted: 25 October 2015, 16:12
by Een
Hello JackLance,

This works well in Hex, so I gave your read access to Hex in the studio so that you can look how it was done (I think it will be quicker if you take a look directly at an example ;) )

Cheers,
Een

Re: Pie Rule

Posted: 26 October 2015, 00:33
by ZPolansky
Thanks, that was very helpful! :)