TicTacToe: Effeciency Tips

Get help using Construct 2

Post » Mon May 30, 2016 6:30 pm

For practice (swallowed pride and started simple...simplest) I made classic TicTacToe. No frills.

I think the events are pretty efficient/minimal but would appreciate any tips on events or variables. I know this is simple but usually efficiency tips are exponentially helpful as things get more complicated.

Capx:
https://www.dropbox.com/s/vv6cdzqg44y41v2/TicTacToePractice.capx?dl=0

Preview:
http://www.loubagel.com/archives/052916/tictactoe/index.html
ImageImageImage
B
43
S
26
G
11
Posts: 517
Reputation: 10,475

Post » Tue May 31, 2016 3:36 pm

https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Wed Jun 01, 2016 4:13 pm



I have actually read those before but that isn't what I was referring to. I wasn't asking for performance tips and increase running speed and such.

I was asking for tips with events and such. Such as "you could have done the same thing with less events" or "instead of using these features you could have used this one feature".

TicTacToe is rather simple but there are still things to keep track of and check for: who's turn; who played where; which spot available to play; and check for all the victory conditions.

Like I said, just did this for practice and I did become more familiar with some aspects of Contruct that I wasn't familiar with before. But maybe there are some aspects I am oblivious to.

There are many ways to solve a problem—maybe it would have been more interesting to ask how others would approach creating TicTacToe.
ImageImageImage
B
43
S
26
G
11
Posts: 517
Reputation: 10,475

Post » Fri Jun 03, 2016 1:24 pm

I guess I misunderstood your question then.

For me, I would use a 3x3 array and assign a 0, 1, or 2 to each slot to represent null, X, and O. Then just loop through it each move and update the board.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Fri Jun 03, 2016 2:22 pm

You can look at my tutorial for another implementation.
https://www.scirra.com/tutorials/320/tic-tac-toe-part-1
ImageImageImage
B
71
S
22
G
248
Posts: 3,758
Reputation: 138,067

Post » Fri Jun 03, 2016 3:09 pm

gumshoe2029 wrote:I guess I misunderstood your question then.

For me, I would use a 3x3 array and assign a 0, 1, or 2 to each slot to represent null, X, and O. Then just loop through it each move and update the board.


Ah yes, an array definitely sounds fitting and was an option I considered even though didn't use. How would you visualize the array to the board the player sees?
ImageImageImage
B
43
S
26
G
11
Posts: 517
Reputation: 10,475

Post » Sat Jun 04, 2016 2:16 am

Well, this was fun.
I made a TicTacToe game in nine events
Here you go, have a look!
Sorry about crappy host, I don't have a dropbox.
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,471

Post » Mon Jun 06, 2016 12:41 pm

badmoodtaylor wrote:
gumshoe2029 wrote:I guess I misunderstood your question then.

For me, I would use a 3x3 array and assign a 0, 1, or 2 to each slot to represent null, X, and O. Then just loop through it each move and update the board.


Ah yes, an array definitely sounds fitting and was an option I considered even though didn't use. How would you visualize the array to the board the player sees?


I would use @rexrainbow 's SquareTx plugin. Or you could just use 9 sprite objects with three frames each, one X, one O, and one blank.

Whiteclaws wrote:Well, this was fun.
I made a TicTacToe game in nine events
Here you go, have a look!
Sorry about crappy host, I don't have a dropbox.


Yea, see he uses the 9 blocks with 3 frames idea too. I really like your use of tokenat. I think I will borrow this idea for later.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Mon Jun 06, 2016 8:37 pm

I tried my hand at making a minimal event ticktacktoe before looking at whiteclaws' example.

I got 6 (or 4 if you don't count variables) events and I think this is near bare minimum*.
https://dl.dropboxusercontent.com/u/542 ... event.capx

You can increase readability by bumping it up to 8 (3 variables and 5 events):
https://dl.dropboxusercontent.com/u/542 ... dable.capx

*A one event ticktacktoe is possible by using the conditional (?:) operator:
https://dl.dropboxusercontent.com/u/542 ... event.capx
Well it's actually one event and two variables.
B
94
S
33
G
114
Posts: 5,357
Reputation: 73,775

Post » Thu Jun 09, 2016 1:35 am

Now this is what I had in mind. Different people solving a simple problem however they choose. Get to see some different techniques implemented in live examples.

@Whiteclaws version uses a lot of tokenat() which I've never used before. Usually I have to try things out myself before understanding but seeing it done several times here I get how it can be useful

@blackhornet & @gumshoe2029 I don't have those plugins installed but I'm sure I'd learn something about those plugins from the capx. I've heard good things about those plugins but not going to install them at this moment.

@R0J0hound I'll have to examine your projects further as it looks like there are several techniques I could pick up. So in any event you can put (parameter)? and its like making a tiny if statement? Or are there only certain situations you can use it?

Sorry it took me so long to respond and thanks to all that shared.
ImageImageImage
B
43
S
26
G
11
Posts: 517
Reputation: 10,475

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests