How do I create a 4 in a row game

Get help using Construct 2

Post » Fri May 19, 2017 3:30 pm

Hi guys,

Looking to create a game like this http://www.agame.com/game/4-in-a-row

Have anyone ever created something like this?

Thanks,
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Fri May 19, 2017 7:09 pm

Found this to be an interesting challenge.

It's just a basic version and it might contain bugs, but it mostly works as intended.
The actual challenge was the win-detection algorithm.

Here is the download to the .capx.

It is by no means perfect, there are many ways to make the win-detection algorithms faster and more effective.
Two things that I thought of:
  1. The Array search area can be reduced to a 5x5 square with the last inserted coin as the center.
    There is no possible case where you insert a coin and win with a combination that is outside this area.
  2. The check for vertical combinations should not check above the last placed coin since you can't place new coins under already placed ones.
These features are easily implementable, but I didn't have the time to put them in.

Hope this helps.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun May 21, 2017 3:56 pm

Hi @randomly,

It looks pretty good but there is a major issue. You will win if there is 4 in a row but there is a gap between them.
Image

@R0J0hound would you be able to help?

Thanks,
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Mon May 22, 2017 3:02 am

I have an example for detecting match (3 or 4) >> here-how-i-detect-match_t150699

Works for horizontal & vertical match not diagonal but somehow you can just modify it to your needs.
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226

Post » Mon May 22, 2017 3:34 am

@alextro,

Your example is good but I am not sure how I can implement on the capx randomly provided. can you please give us some clarification?

Thanks,
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Mon May 22, 2017 7:19 am

Perhaps I will start making this kind of tic-tac-toe game after the jam ended.
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226

Post » Mon May 22, 2017 3:30 pm

Fixed the horizontal check and improved vertical check.
I was just thinking too complicated, trying to make smart loops, but could have instead just used brute-force conditions.
Which I did now, inspired by @alextro .

Same link, different file: Download here

One last thing that I need to figure out is, why the dictionary with the supposed check results always contains only one key when moving to the "win" layout.
But that's not important.
Important is that the main engine runs now.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon May 22, 2017 6:01 pm

Good but not perfect yet. I am still getting false wins

Image
B
117
S
49
G
24
Posts: 401
Reputation: 22,282

Post » Tue May 23, 2017 12:06 am

I'm not gonna dig any further into this, this is your project after all, not mine. ;)
Last edited by randomly on Tue May 23, 2017 5:04 pm, edited 1 time in total.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue May 23, 2017 9:48 am

Yes @randomly has provided decent sample for everyone who want to learn the logic. It can be perfected by himself or other user by the time. At least he shown a good sample as starting point.
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000, evillair, mongoose665 and 65 guests