# How do I match a square board to an array?

Get help using Construct 2

### » Sat Jun 11, 2016 10:47 am

Hello everybody,

Can you help me with the following problem I have please?

I like to make a GO board game for two persons. The computer does not have to play, it only has to check if all moves are legal, the winning conditions and calculate the winner.

I like to play this during the break which is only 30 minutes. A computer board with no fysical objects should spare us time. What we want is just start the game, load an unfinished game or start a new one.

The board is the official 19 x 19 grid.

The board is just a sprite placed on the background (thank you very much Kyatric, you saved my health here with your excellent Small tactics tutorial). So when I now say 'run' I see the square board with those 19x19 cells. But Construct two has no idea about the intersections on the board itself.

So I need an array to translate the moves, the pieces so Construct2 can process the information. I am thinking on using a class for each intersection storing the X/Y coordinates together the field information (occupied or not and by who).

So the class could look like this :

Code: Select all
`clsBoardintColumn_X as IntegerintRow_Y as integerintFieldState as integer`

So I could have a board array like this :
clssBoard(391) as clsBoard

Do not be bothered about the code, I only try to explain what I am willing to do. I have the feeling my expression is flawed.

So it is one long array (391 elements) of which each element in this array contains the column - row - fieldstate information.

The question I have is, how to organise this array so Construct2 can determine which fields are bordering each other and how based on that calculate the moves and if they are legal? In fact, how to translate the board (images) coordinates and states to the array?

Thank you very much for your efforts to help me, which are very much appreciated.

Friendly greetings,

B
22
S
6
Posts: 138
Reputation: 1,844

### » Sat Jun 11, 2016 12:13 pm

Do you need something like that demo?
You might see this behavior. It is one of my board series plugins.
Goodbye
B
114
S
31
G
295
Posts: 4,549
Reputation: 164,608

### » Sat Jun 11, 2016 6:17 pm

Hello Rexrainbow,

Thank you very much for your suggestions. I took a look at the demo and the documentation.

To be honest, I do not know if it will work for me. Despite the fact the GO board consists of cells, the intersections are used, included those on the borders. There my thinking was flawed and incorrect.

In GO the player does not use the cells but the intersections where lines meet each other, including those on the borders.

With the GO game, a player click and intersection and the pawn is placed on the intersection, not inside the square. Once placed, those pawns can no longer move, only be "removed".

Maybe I should make base sprites which contain a drawing of 4-side, 3 side and 2 side intersections. So every intersection is a sprite (in this case I will have 391 different sprites containing the drawing of the intersection they represent). Instead of drawing the cells, I draw the intersections half the width and half the height of each cell.

Or maybe I can translate the screen position of each intersection to a column-row in the array. For example when clicking on the screen with the mouse, the screen mouse position is translated to the nearest intersection.

I will try your plugin from the moment I can translate the board to the array succesfully.

Thank you again very much for your help, which I do appreciate very much.

Friendly greetings,

B
22
S
6
Posts: 138
Reputation: 1,844

### » Sat Jun 11, 2016 10:54 pm

Need 391 instances of the same sprite, if you wanna do it basic.

Drawed his way, @rexrainbow 's board plugins are a big help for you. After all, its just a regular board.
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Sun Jun 12, 2016 2:57 am

Sorry I misunderstand the "Go" game.
You could still use my board plugin, which is a data structure of instance-to-logical position mapping, for putting chess on the board.

Edit:
Have you try official tilemap object?
-- Sample capx, images come from @99Instances2Go 's sample capx.
Goodbye
B
114
S
31
G
295
Posts: 4,549
Reputation: 164,608

### » Sun Jun 12, 2016 7:33 pm

Hello 99Instance2Go and Rexrainbow,

Thank you very much for your interesting replies. I learned a lot of your demos.

I opened the sample capx and looked to the events. It is exactly what I needed. Next weekend I will continue working on this game (I can only do this during the weekend).

I appreciate both of you, your efforts to help me very much.

Wish you all the best!