TicTacToe: Effeciency Tips

0 favourites
  • 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

  • Did you read?

    https://www.scirra.com/manual/134/performance-tips

    https://www.scirra.com/blog/83/optimisa ... -your-time

    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.

  • 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.

  • You can look at my tutorial for another implementation.

    https://www.scirra.com/tutorials/320/tic-tac-toe-part-1

  • 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?

  • 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.

  • > 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.

    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.

  • 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.

  • 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.

  • The manual explains the conditional operator pretty well here:

    https://www.scirra.com/manual/78/expressions

    But yeah, it's like a simple if then else.

    If X=2

    Then set y to 4

    Else set y to 5

    Can be written instead as

    Set y to X=2?4:5

  • The manual explains the conditional operator pretty well here:

    https://www.scirra.com/manual/78/expressions

    But yeah, it's like a simple if then else.

    If X=2

    Then set y to 4

    Else set y to 5

    Can be written instead as

    Set y to X=2?4:5

    Wow, I've landed on that page so many times when searching for various answers but I have never read the operators section. Assumed I knew plus, minus, greater than, less than etc. We all know what assuming makes.... usually I try to read everything

  • tokenat() is useful if you don't want to create a JSON or manually populate an array, with a text variable, it basically acts like the At command of a one-dimensional array.

    I use it a lot, but I don't know if performance gets affected by it.

  • tokenat() is useful if you don't want to create a JSON or manually populate an array, with a text variable, it basically acts like the At command of a one-dimensional array.

    I use it a lot, but I don't know if performance gets affected by it.

    Yes, what you did with tokenat() reminded me of a simple array. Honestly, at first it seemed to be more complex in writing the syntax than using an array. But that's probably because I haven't seen it or tried it so I won't knock it until I try it. I could see it possibly coming in handy with text choices as well "yes/no/maybe", "save&quit/save&exit/exit".

    Do you usually accompany it with another variable to track the index? If you use it and discard it in the event its unnecessary but it seems like in a lot of cases you would want to save the results somewhere, whether in global or instance variable.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    We use it in our current game to produce our isometric platform:

    https://www.stormforgedproductions.com/ ... 287745.png

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)