How do I simulate teams having played a match?

0 favourites
  • 9 posts
From the Asset Store
Match 3 Game Gem Pixel Art work for any kind of Match Games.
  • I have searched the forum and tried a few things, but I am looking for help in what kind of direction I need to go.

    (My knowledge of arrays: basic. I have read the manual and tried experiments with most of the functionality.)

    Wish: there are 4 sport teams. Every time I click a button, they have played a game and I can see the scores and result.

    I think I need an array for this.

    Pressing the button and filling the array with goals scored per team is the basic level I could achieve.

    What I think is also necessary is: how do I let C2 know that when I play team A versus team B, that only team C and team D are left to play a match. (for example team C versus team B is not possible, because team A is playing team B)

    If I am not clear enough, let me know.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • First you need to clearly define what you are trying to simulate. So when you click the button...

    Who plays? Pick a random team. Then do they play another random team? And then the two remaining teams play each other?

    What to record? Score and win count? Is score chosen randomly as well? Otherwise what are the constraints or logic for scoring? Win can be based on score. Do you want to keep track of ties?

  • Who plays? Pick a random team. Then do they play another random team? And then the two remaining teams play each other?

    This is the part I would like to receive tips for techniques.

    Answer to your questions:

    Who plays? (The Player selects a team) Pick a random team.

    Then do they play another random team? (yes)

    And then the two remaining teams play each other? (yes)

  • First off I want to say don't be intimidated by arrays - they are in essence spreadsheets where you can store and manipulate data. One important feature is that they can grow and shrink as you need them, unlike variables, of which you have a fixed amount defined ahead of time. Very useful.

    Basically, your goal is to get teams randomly from a list without repeating. I would use two arrays - the first array contains all your teams and data, the second array starts off empty but when we need to we can move the teams in the desired order to the second array (so that the first two slots play each other, next two, ect.). After the data is processed, they can be moved back to the original array in the correct order as well.

    Here is the commented example - https://www.dropbox.com/s/uu31uxt73zkfx ... .capx?dl=0

    I made heavy use of loopindex, let me know if you have any questions.

    This technique is very similar to shuffling a deck of cards. Imagine you have a "deck" of 52 teams (or 4 in your case), and after you shuffle you draw the top two teams, play them against each other, and then keep repeating until you run out of cards. Sorting them back into the original order is optional.

    If you don't mind using plugins, here is a plugin that might be useful - plugin-smart-random_t163624

  • Wow great. As soon as I get near a computer today or tomorrow, I will study your capx and get back to you. Thanks!

  • oosyrag

    What does this do? (and why "width-1"?)

    -> Shuffler: Set value at (Shuffler.?Width-?1, 1) to Array.?At(?CurrentPick,?1?)

  • So an array width 4

    x indexes are

    0 | 1 | 2 | 3

    array.width-1 = 3, which would be the last column. Since I pushed to the back of the array.

    If you push to the front of the array, you would simply use 0. I don't remember if I had a particular reason to push to the back...

    As for what it does - After pushing current pick to the back, it only sets the first row value (y0). So I need to move the other values in the other two rows (y1 and y2) as well..

  • oosyrag

    Thanks! I’ve studied it and understand it now.

    The technique to go through pairs ((loopindex*2) and 2nd event: (loopindex*2+1)) is something I never would have come up with.

    How did you got to use it? Did it come from a match background or is it a programming technique?

  • All programming techniques come from math. Math lets you take numbers and transform them into whatever form you need, following rules that a computer can understand.

    But generally speaking, experience and practice will let you recognize what you can do in any given situation.

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