need help on grid base board game!

Hi guys,
I am trying to create one small board game. Size of the board is 6 rows and 8 columns (think of a chess board ). Its a two player turn based game. The objective of game is simple where player have to fill the board with his coins. Player who is having more coins on board wins the game.

Here comes the rules and this is where i am stuck. :face_with_spiral_eyes:

  1. Player can fill upto 4 blocks in a row or column. (no diagonal selection is allowed)
  2. Selection should be continues. (Player cant choose blocks scattered around the board. So its like vertical or horizontal blocks line)
  3. Player will keep getting points for each block filled.
  4. Player will lose points if he fills the last empty block (this can be anywhere in the row or column) of the row or the column.
  5. Game will continue until all the blocks are filled.

My question is how to approach this game to get started with coding.
Here are the problems i am facing.

  1. I am able to select upto 4 (or whatever is the max limit) but i am not able to disable diagonal selection.
  2. How can i pass information to code that how many empty blocks are still there in rows and columns. So game on that basis i can add or subtract players points


I hope i am clear enough on what i want to know.
Any help or guidance on the same will be very helpful to me.

I am using Unity4 free / with javascript

Thanks in advance

Maybe make your board up where each block, section on the board is a trigger, cube collider. Each collider is assigned a value A1, A2
, B1, B2
 And so on.

When a block is taken, it knows this by the coin triggering it. The block tells the board manager, boardMng, tht it has been taken. The board manager sees column A and row 1 is now taken. Now, it is the responsibility of the manager to check what other blocks are taken. You could do this by knowing ABCD, BCDE, CDEF
 Or if 1,1,1,1, or 2,2,2,2
 And so on. Since there is no diagonal, it should be easy.

That’s a difficult way of doing it. Just use a 2D array, where each cell in the array represents a square in the board.

–Eric

@renman3000 Thanks a lot
 ill give it a shot.

One other thing i was thinking of creating int variables (size of row or column) for each row and column.
When player will fill any of the block it will get subtracted from the variable, with this i can get info on how many empty blocks are there on the board.
I might be wrong or i am thinking very long way


Thanks for the quick replay, help from you guys will always keep me going.

“2D array” wow new thing to learn
 thanks a lot for pointing it out


http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F#2D_Array

–Eric

Thanks a lot for all the kind support. I was just going through all the docs which talk about “2D array”. Just came back here to found this link

Many many thanks


@Eric, just out of curiosity, how would you set the array’s members? Meaning, how would you know when on member is taken?

Multiple ways to do this. Simplest is to have a boolean property which gets set when a square is taken.

Yes, I understand that. My approach would be to have triggers, in place. Is there another way that is better?

Well, using booleans eliminates the need for any type of collision, so I don’t know why you dismissed that as not being better. Or I didn’t understand what you are asking?

Well,
I would think you place a collider, into a section, that would trigger the bool. How else can you place an object I to some position and have some manager realise it is there?

Depends
if the view is top-down, then just use some basic math. If it’s a 3D view, use Plane.Raycast and some basic math.

–Eric

So, would you shoot a ray from each section. Then place a block on section. If block is let go, it is assumed to be dropped into place, turn off ray, register this section taken?

Well, if you have the size of each square on the grid, and you have the postion of the object you can work out which position in the array the piece is moving to using basic math to translate it’s world position into array indices.

I don’t like to use a collision system if I can somehow manage without it. This is how I would do it:

Select an object
Set calculateGridCellIndices to true

     Inside Update
        if calculateGridCellIndices
          colIndex  =  player.position.y / gridSquareSize
          rowIndex = player.position.x / gridSquareSize
     End Update

If object unselected
   truncate last calculated colIndex and rowIndex to closest integer
     check array position colIndex,rowIndex
       if bAlreadyTaken is false
          Set position of object to be here
          bAlreadyTaken is true
   calculateGridCellIndices = false

Hi guys, i am back with some doubts again.

I was practicing to work with “2d array” and now i can play with them a little.
I can feed and read values in it (manual or with for loop ). but i am still not able to find a way to implement this into my game logic.

For e.g : Now i am looking at this array as its filled with bool values (is it empty ?) but how to toggle this values while interacting with game objects? What kind of logic should i apply to solve this? Please help me on this.

Thanks again!

There was a conversation during this thread about different implementations. Have you read through them all?

@Mister-E2 , Yes i have read through all and unfortunately i got stuck at the very beginning of it. I am not a programmer but i am learning how to code.
I have just completed some basic tutorials and i took this as an assignment for myself and i really wanted to finish it.

I know, i cant ask you guys to do spoon feeding but if i get little guidance on it, then i can finish this assignment faster. :slight_smile:

Thanks and regards