Author Topic: Creating a Simulation Engine  (Read 1965 times)

Offline Devereaux

  • Level 3
  • *
  • Posts: 7
  • Reputation: +0/-0
    • View Profile
Creating a Simulation Engine
« on: July 12, 2013, 10:22:48 PM »
Hey everyone, I'm hard at work developing the core of my game and being someone that has never messed with in depth algorithms for game development I was wonder if I could get some help/tips/pointers on how to approach this aspect in my game. First off let me explain by saying my game is a wrestling simulation similar to THEWRESTLINGGAME. A user will create a wrestler, wrestle matches, train, and equip more advanced moves. Now the meat and potatoes will be the simulation engine which I was to construct to be as fun as possible to read match results.

Now there will be a ton of variables for each character. My first question is should I use all of these variables combined to come up with an overall number to determine skill then calculate it with the strength of the characters moveset (which will also be averaged out?)? Is there a different approach you would take?

Second is providing the text for the match results. I am completely clueless as to how to do this. Should I created a table with a bunch of action texts along with reaction texts and then just randomize them in certain situations or just pull the moves from the table and just within the results page itself create a buttload of if/else with a randomizer? Or if I'm completely off base feel free again to share any ideas.

Lastly, I included an example of simulation engines that are currently working in a few games just for reference on how I should approach the engine itself.

Example:
Code: [Select]
Ring Announcer: "The following contest is scheduled for One Fall!"

Ring Announcer: "Introducing first, Mark Devereaux"!
Mark Devereaux makes his way to the ring

Ring Announcer: "and his opponent, Thantanos"!
Thantanos makes his way to the ring

The two wrestlers stare proudly at each other
and then engage in a exciting test of strength, trying to overcome their opponent
after a few, seemingly endless, seconds and an enormous effort Thantanos prevails
Thantanos points to Mark Devereaux with decision
and hits his face with an light Ear Slap showing no respect
Thantanos prepares to hit the rival
Mark Devereaux moves and dodges a Forearm Smash, taking the initiative back
Mark Devereaux grasps Thantanos
and lifts him up, slamming him down to the mat performing a light Body Slam
Mark Devereaux gets besides the laying opponent
Thantanos blocks the Knee Stomp easely
Thantanos gets close to his grounded opponent
and hits him executing a light Knee Stomp
Thantanos grabs Mark Devereaux's hair
Thantanos grabs one of his opponent's arms and swings him into the ropes
Thantanos takes a run-up on the ropes, runs towards his opponent
stretching his arm hitting his back with a light Clothesline to Back
Thantanos pulls Mark Devereaux still groggy, by his hair
Thantanos puts his opponent on his shoulders
Mark Devereaux climbs down his rival's shoulders dodging the Samoan Drop regaining the initiative
Mark Devereaux grabs Thantanos's hair
lunges himself on the ropes
Mark Devereaux runs toward Thantanos and jumps
Thantanos prevents from being thrown with a Running Arm Drag
Thantanos puts his opponent on his shoulders
and throws himself backward, trampling him with light Samoan Drop
Thantanos grabs Mark Devereaux's hair
Thantanos grabs one Mark Devereaux's arms and spins, swinging him into the ropes, then lunges himself as well
Thantanos hooks Mark Devereaux from behind
Mark Devereaux suddenly dodges the Backslide Pin, and starts to counterattack
Mark Devereaux grabs Thantanos's hair
Mark Devereaux grabs one Thantanos's arms and spins, swinging him into the ropes, then lunges himself as well
Mark Devereaux grabs Thantanos from behind
and attempts a pinfall with a light Backslide Pin
Referee starts counting...
Referee: ....Oneeeeeeeeeeeeeeeee....
Referee: ....Twooooooooooooooooo....
Thantanos gets up and resolutely fights back
Thantanos stares at Mark Devereaux in front of him
and hits his face with an light Ear Slap showing no respect
Thantanos loads his arm chop style and
Mark Devereaux moves and dodges a Forearm Smash, taking the initiative back
Mark Devereaux grasps Thantanos
and slams him down to the mat performing a light Body Slam
Mark Devereaux grabs Thantanos's hair
Mark Devereaux grabs one Thantanos's arms and spins, swinging him into the ropes, then lunges himself as well
Mark Devereaux hooks Thantanos from behind
hooking him by the arms sliding him across his back while falling performing a light Backslide Pin
Referee starts counting...
Referee: ....Oneeeeeeeeeeeeeeeee....
Referee: ....Twooooooooooooooooo....
Thantanos gets up and resolutely fights back
Thantanos stares at Mark Devereaux
Mark Devereaux avoids an Ear Slap and takes the initiative
Mark Devereaux loads an arm towards himself
Thantanos blocks the rival's arm preventing the execution of a Forearm Smash
Thantanos loads his opponent on his shoulders
and throws himself backward, trampling him with violent Samoan Drop
Thantanos gets close to his grounded opponent
and strikes his forehead with a light Knee Stomp
Thantanos approaches his laying opponent
Mark Devereaux avoids the Knee Stomp and counterattacks
Mark Devereaux approaches his laying opponent
Thantanos blocks the Knee Stomp easely
Thantanos gets besides the laying opponent
and strikes his forehead with a strong Knee Stomp
Thantanos grabs Mark Devereaux's hair
Thantanos grabs one Mark Devereaux's arms and spins, swinging him into the ropes, then lunges himself as well
Thantanos runs toward Mark Devereaux
and spins hitting him with a light Rolling Elbow Smash
Thantanos pulls Mark Devereaux still groggy, by his hair
Thantanos lifts his opponent on his shoulders
and throws himself backward, trampling him with violent Samoan Drop
Thantanos grabs Mark Devereaux's hair
Thantanos grabs one of his opponent's arms and swings him into the ropes
Thantanos takes a run-up on the ropes, runs towards his opponent
and he hits his back with his arm taut performing a strong Clothesline to Back
Thantanos grabs Mark Devereaux's hair
Thantanos grabs one of his opponent's arms and swings him into the ropes
Thantanos bounces on the ropes running towards his opponent
Mark Devereaux gets down and avoids the Clothesline to Back. gaining the initiative
Mark Devereaux gets close to his grounded opponent
to hit him with a light Knee Stomp
Mark Devereaux pulls Thantanos still groggy, by his hair
Mark Devereaux loads his opponent on his shoulders
Thantanos firmly blocks the execution of the Samoan Drop
Thantanos grabs his opponent's nape from behind with his right hand
and kneels down, flipping him over his shoulder down to the mat, back first connecting with a light Snapmare
Thantanos grabs Mark Devereaux's hair
Thantanos grabs one Mark Devereaux's arms and spins, swinging him into the ropes, then lunges himself as well
Thantanos grabs Mark Devereaux from behind
hooking him by the arms sliding him across his back while falling performing a light Backslide Pin
Referee starts counting...
Referee: ....Oneeeeeeeeeeeeeeeee....
Referee: ....Twooooooooooooooooo....
Referee: ....Threeeeeeeeeeeeeeee....
THANTANOS WINS THE MATCH AND DEFEATS MARK DEVEREAUX!!!

Any guidance is well appreciated. Thanks guys!
« Last Edit: July 16, 2013, 10:35:39 PM by Devereaux »

Offline Barrikor

  • Level 26
  • **
  • Posts: 371
  • Reputation: +5/-0
    • View Profile
Re: Creating a Simulation Engine
« Reply #1 on: July 13, 2013, 01:30:15 AM »
First off, I think this is probably one of those things that you just have to start half-way before you find the best way to do it and then rewrite it...

I'd start out with drawing up a couple variables and arrays for storing stuff. I'd wait before messing with the database because you'll just be putting everything from the DB into the vars and arrays anyway and needing to redo your database tables whenever you made a major change in your code would weigh you down.


Now there will be a ton of variables for each character. My first question is should I use all of these variables combined to come up with an overall number to determine skill then calculate it with the strength of the characters moveset (which will also be averaged out?)? Is there a different approach you would take?

I think you've just gotta play with it a lot, test the different possibilities, and fine-tune it until it actually seems fun. There's a lot of formulas people come up with, but (IMHO) there's no formula for making players think something it interesting or fun, you've just gotta make little changes until you seems good to you.


Second is providing the text for the match results. I am completely clueless as to how to do this. Should I created a table with a bunch of action texts along with reaction texts and then just randomize them in certain situations or just pull the moves from the table and just within the results page itself create a buttload of if/else with a randomizer? Or if I'm completely off base feel free again to share any ideas.

I'd avoid putting the full text descriptions into the DB, maybe just store a number for each action and reaction, and have an array of action descriptions and an array of reaction descriptions... Or maybe a function that takes the id and the name of both wrestlers as parameters and returns the text as a string.
Projects: Pith Framework (at 0.5), CactusGUI (at 0.3), Grand Canyon Studios 

Offline arai

  • Level 10
  • *
  • Posts: 60
  • Reputation: +2/-0
    • View Profile
Re: Creating a Simulation Engine
« Reply #2 on: July 13, 2013, 03:08:05 AM »
Write it out on paper first.  What are the attributes of each character (skills, abilities, moves, etc) and how do they interact with each other (how do they affect other abilities within the character, and how do they affect other characters).

Establish your gameplay and mechanics before you even consider the implementation.

Offline Devereaux

  • Level 3
  • *
  • Posts: 7
  • Reputation: +0/-0
    • View Profile
Re: Creating a Simulation Engine
« Reply #3 on: July 13, 2013, 03:14:49 AM »
Write it out on paper first.  What are the attributes of each character (skills, abilities, moves, etc) and how do they interact with each other (how do they affect other abilities within the character, and how do they affect other characters).

Establish your gameplay and mechanics before you even consider the implementation.

I understand that but I am trying to understand what goes in to a proper large algorithm and how it would normally be approached. Again, I'm no math major or I'm sure I'd breeze through this.

Offline arai

  • Level 10
  • *
  • Posts: 60
  • Reputation: +2/-0
    • View Profile
Re: Creating a Simulation Engine
« Reply #4 on: July 13, 2013, 04:37:42 AM »
Your example is of a finite state engine.

You have one referee, two wrestlers, three judges, and n rounds to perform m actions.

You initialize the engine with the beginning of the match.

You run a while loop that iterates each round.

You run a while loop that iterates each action performed by the wrestlers.

The actions a wrestler can perform are dependant upon that wrestlers state, in addition to whatever else you decide to add.

The match ends when a wrestler reaches a disqualification state (usually unconscious, or bleeding profusely, oh and lets not forget dead), or the time runs out.

The winner is decided by who is not in the disqualification state, or by the judges if both participants are potentially valid winners.

There are MANY unanswered questions from this point on.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,444
  • Reputation: +29/-1
    • View Profile
Re: Creating a Simulation Engine
« Reply #5 on: July 13, 2013, 05:02:07 AM »
I would do it other way round. First write down an example match outcome and then invent algorithm/attributes that can produce such outcome.

Offline saljutin

  • Level 22
  • *
  • Posts: 272
  • Reputation: +6/-0
    • View Profile
Re: Creating a Simulation Engine
« Reply #6 on: July 13, 2013, 12:13:06 PM »
I will keep that simple...so its up to you and your imagination to expand it
lets say W1 and W2 are wrestlers, they can punch from L(eft) or R(ight), and they can block from BL(eft), BR(ight), their HP is 10, and each sucessful hit is -1HP
lets say user chooses % for PL/PR ratio, and BL/BR ratio ... so 40/60 Punch will mean that 40% of punches will land on left, 60% on right; same with blocks

they fight till someone is on the floor, so rounds is 1-N
while (W1HP>0 AND W2HP>0) -> your function of fighting is here
you do some random -> who will punch in this round (maybe use quickness skill which chooses who will punch=
W1 will punch-> he has 30/70 ratio so you throw "dice" and it chooses punch L
W2 bill block he has 50/50 -> throw dice and choose block R
W1 hits W2, and does some injury
you write that down in some array/text/sql
you can has some randomness here:
R1: W1 hits W2 like a bulldozer.
R2: W1 smashes W2 head from left
R3: W1 hits W2 so hard that his tooth goes flying to the audience...and yes someone SURE got that souvenir!

so basically you action is
1 - who punches
2 - punch from L,R
3 - block - yes/no
4 - random number for text (lets say mt_rand(1,3) which chooses that R1,R2 or R2 text)
so you can write that to some document/database

and when you show your players text from that fight you go and parse that text and translate it to code :)

Offline Devereaux

  • Level 3
  • *
  • Posts: 7
  • Reputation: +0/-0
    • View Profile
Re: Creating a Simulation Engine
« Reply #7 on: July 16, 2013, 10:38:19 PM »
Thanks everyone for the suggestions thus far. More were guided towards the MMA aspect of my example. What about the wrestling one where moves will be being pulled from a database with specific damage attributes and such?

How could I incorporate not only a decent algorithm to determine match winners but also a way to display a play-by-play text involving predetermined text and moves from a moves database?

Thanks again!

Offline Devereaux

  • Level 3
  • *
  • Posts: 7
  • Reputation: +0/-0
    • View Profile
Re: Creating a Simulation Engine
« Reply #8 on: July 18, 2013, 06:28:02 PM »
I would do it other way round. First write down an example match outcome and then invent algorithm/attributes that can produce such outcome.

I think this will be the best bet. I'll come up with something I think would be somewhat entertaining to read and then give a post here again to try and figure out how to implement it.

I got the attributes for each wrestler done and the algorithms to match for level, overall, and the such. Just have to work on the basics for the match simulation. Again, thanks for all the suggestions guys.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal