Shift row or column in a card matrix

Game development with Board Game Arena Studio
Post Reply
User avatar
Morgalad
Posts: 108
Joined: 17 January 2017, 20:46
Contact:

Shift row or column in a card matrix

Post by Morgalad »

Hi all,
I'm struggling with something that might look simple but has been giving me headaches the last 2 days, I was wondering how to do this:

I have a matrix of cards

(x,y)

Cells are labeled like this:

Code: Select all

03 13 23 33
02 12 22 32
01 11 21 31
00 10 20 30
The player can choose any card as Target
and then a second card adjacent to it (not diagonally) as direction to shift that entire row or column.
(this is a circular shift and the card on position 31 for example would enter the row from the other side in position 01)


What you think is the best method to do this?

I-ve been thinking in creating an array with the values from the database with the row or column selected and then use PUSH and POP to rearrange the cards. But I was wondering if there is something more efficient.
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Morgalad
Posts: 108
Joined: 17 January 2017, 20:46
Contact:

Re: Shift row or column in a card matrix

Post by Morgalad »

Ok,

my first try based on the idea:

Code: Select all

$sql = "select card_location_arg from cards where card_id=".$cardtarget;
					$targetpos=self::getUniqueValueFromDB( $sql );
					$sql = "select card_location_arg from cards where card_id=".$card_id;
			        $cardpos=self::getUniqueValueFromDB( $sql );
					
					$delta=$cardpos-$targetpos;
					
					$X= $targetpos % 10 ;
		            $Y=  ($targetpos - $targetpos % 10) / 10; 
					
					$shiftcards= array ();
					
					switch($delta)
					{
						case "1":
						    $shiftcards= array ($Y*10+0,$Y*10+1,$Y*10+2,$Y*10+3  );
							break;
						case "-1":
					        $shiftcards= array ($Y*10+3,$Y*10+2,$Y*10+1,$Y*10+0  );
							break;
						case "10":
					        $shiftcards= array (0+$X,10+$X,20+$X,30+$X  );
							break;
						case "-10":
					        $shiftcards= array (30+$X,20+$X,10+$X,0+$X  );
							break;	
					}
					$shiftcards_ids= array ();
					for ($c=0;$c<=3;$c++)
					{
						$sql = "select card_id from cards where (card_location='field') and (card_location_arg=".$shiftcards[$c].")";
						$shiftcards_ids[$c]=self::getUniqueValueFromDB( $sql );
					}
					
					$moveitems=  array();
					
					for ($c=1;$c<=4;$c++)
					{
						self::DbQuery( "UPDATE cards SET card_location_arg=".$shiftcards[$c%4]." WHERE card_id=".$shiftcards_ids[$c-1] );
						$moveitems[ 'card_'.$shiftcards_ids[$c-1]] = 'field'.$shiftcards[$c%4] ;
					}
					
					
					self::notifyAllPlayers( "moveitems", clienttranslate( '${player_name} shifts a row or column of cards ' ), array(
								'player_id' => $player_id,
								'player_name' => self::getActivePlayerName(),
								'moveitems' => $moveitems
								) );
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Een
Posts: 3854
Joined: 16 June 2010, 19:52

Re: Shift row or column in a card matrix

Post by Een »

Hi Morgalad,

Not sure what would be the best method exactly, but there is already a game published on BGA which does exactly that type of shifting: "Noir: Killer vs Inspector".

In the up to date studio, you can get readonly access to the code from the projects page to take a look at how the developer managed it.

Anyway, with a matrix this size, efficiency and performance should not be a real problem, whatever method you choose to use in the end.
User avatar
Morgalad
Posts: 108
Joined: 17 January 2017, 20:46
Contact:

Re: Shift row or column in a card matrix

Post by Morgalad »

Hi Een,
Thanks for the feedback!

I have now another issue because of using that link to get ReadOnly permissions I now lost access to VeggieGarden and TakaraIsland. (I cant upload files and even trying to change the permissions I removed myself accidentally as admin :oops: )

I think something has meessed my acls.
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: Shift row or column in a card matrix

Post by DrKarotte »

I cannot upload files to any of my project since this morning, without having done something with the new buttons.
User avatar
Een
Posts: 3854
Joined: 16 June 2010, 19:52

Re: Shift row or column in a card matrix

Post by Een »

Indeed, a cron script had messed with the file permissions this morning.
This should be fixed now!
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: Shift row or column in a card matrix

Post by DrKarotte »

I can confirm that :-)
Post Reply

Return to “Developers”