Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thunderbuns · Aug 23, 2018 at 12:52 AM · c#gameplayartificial intelligenceadvicepractices

player rule builder

I am trying to build a game where the users will be given a set of randomly generated rules. For example each player will receive a different starting weapon, a different tool, different clothes and so on. I don't want to hard code all the possible combinations, so I am looking for a better solution. But I have run into a problem. Some of the outputted combinations are conflicting. For example, a player might receive a dagger and a suit of heavy mail, when they would be much better suited to leather armor. I there a way to avoid this problem? A solution that doesn't involve a massive if else tree would be preferable, as that is very hard to scale.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Sep 04, 2018 at 05:52 PM 0
Share

Is this related to Unity, by chance?

avatar image JVene TreyH · Sep 04, 2018 at 05:55 PM 0
Share

I find there's a 'trigger happy' nature of killing questions like this, which are about writing a game but naturally focus on a C# problem in writing the script for it. The fact that Unity presents C# (a dubious choice I$$anonymous$$O) makes C# a Unity subject.


Alas, a number of moderators tend to remove such questions, but really, it makes it difficult for Unity users to get help in C# if these type of questions, writing C# for a Unity game, get removed.


I have as much motivation to strike this particular question because the OP has posted a similar question over a week ago, but hasn't yet recognized that an answer has been given, it just isn't obvious yet - and a breakthrough is im$$anonymous$$ent I think. It is one of those 'things' where the answer is a tad subtle, and the student is not able to recognize the answer for what it is. Sometimes these things need back and forth, and different perspectives - indeed, this version of the question is already moving in the correct direction, the answer is almost fashioned in the question, but again, the OP just hasn't noticed that yet.

avatar image TreyH JVene · Sep 04, 2018 at 06:04 PM 0
Share

thunderbuns is welcome to ask whatever they want on the forum and its members are welcome to respond.

I'm just re$$anonymous$$ding folks to keep it relevant before other moderators see a conversation devolving into SQL, chains, and high-level game design philosophy, then deciding the thread is in violation of:

 Non-Unity question: we want to strictly keep Unity Answers for Unity-related content.


Show more comments
avatar image thunderbuns TreyH · Sep 04, 2018 at 06:04 PM 0
Share

It doesn't have to directly involve gameplay to be related to unity.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JVene · Aug 23, 2018 at 04:43 AM

You have lots of choices. Hard coding is certainly among the least attractive.


As a simple point of logic, generally applicable to your data, is to ask which is smaller, the list of rejections or the list of acceptable matches. I suspect the rejections, or one might call them a list of incompatibilities, is probably smaller. You could proceed on the assumption that things go together just fine unless there's a specific exception that identifies incompatibility. So, you could have a small container (List for example) of identifiers attached to, say, the heavy mail, which indicates an incompatibility with the dagger. The leather armor wouldn't have such an entry in it's list, such that your logic would discover what doesn't work with what, and proceeds to retry for a better match. If, however, you think the list of incompatibilities is actually the larger list, it would be less work to identify likely matches. The point here is you'd choose that which defines less work for yourself.


This incompatibility or compatibility 'rating' could be graduated if you want to indicate preferences. In this way you could allow for situations where some weapons are a best match, good match, poor match or fundamentally rejected, such that if availability of some items is limited the system could help choose an acceptable if not optimal match, and conversely to choose an optimal match among several less optimal alternatives.


You could 'script' the data. The word script is unfortunate, because Unity refers to C# code as scripts, which are really the text files of code in a solution. In this case, however, I use the word script to reference some sort of database, perhaps a JSON or XML file, or it could be a SQL database if you prefer. The point here is that the relationships you must define need not be built in C#. They could be loaded at runtime from a data source, which you could subsequently edit without having to rebuild the application. This ads to the convenience of representing the relationships if you get it right. You could create some UI elements which give this power to in-game editing, or you could create a custom editor for Unity (if these are fairly quick solutions for you), or you could use external tools like spreadsheets or just a text editor.

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thunderbuns · Sep 04, 2018 at 05:15 PM 0
Share

But doing that just draws you into an if else tree.

avatar image JVene thunderbuns · Sep 04, 2018 at 05:42 PM 0
Share

@$$anonymous$$derbuns, Actually, it doesn't if the data is structured correctly. The 'tree' you are imagining is implemented in data, not code. Imagine that I have a list of 100 items to be applied, each of ten different potential 'types'. For each item I have a list of excluded relatives. Where there is no exclusion specified, the items are compatible. Only if I see an entry in the exclusion list is there specified an incompatibility. Ins$$anonymous$$d of a tree, now, I have a list to run through. To check for compatibility, the code considers the recipient. To take your example, the heavy mail suit would include a exclusion entry referencing the dagger. The data, not a tree of if/else statements, indicates the incompatibility. By looping through the heavy mail's exclusion list, I can see what weapons that might be applied are incompatible. This doesn't result in a tree within the code, the tree would result from the data.


This could be implemented from the opposite perspective, though - ins$$anonymous$$d of an incompatibility list, it can be implemented as a match list. In a popular engineering tool, there are nuts, bolts, nails and other fasteners. In this design there are multiple data indicating categories and specific matches. Nails have no match to bolts, so they're rejected. Nuts have to match to nails. Straps have no match to nail, bolts or nuts. These can't be applied to each other. Only nuts match screws (and the reverse). There is no code with 'knowledge' of this - it is done through the descriptive data. The data forms what may be termed a matching algebra (it boils down to boolean, which is why they are a counterpart to if/else logic). From a theoretical perspective, this is no different than creating a compiler which has if/else logical syntax and recognizes how to implement it. The compiler need not know every possible if/else layout that may ever be written, it only requires to understand a few basics which the text can then describe. In your case, however, the text is replaced by the data, but the implementation is nearly identical, fundamentally.


This is what prompted Vadim$$anonymous$$insk to suggest $$anonymous$$arkov chains, though I'm not certain they're perfectly applicable to your requirements, you're implementing rather simple boolean matches, in data. The boolean nature is hinted by the fact you can implement them as if/else tests.

avatar image thunderbuns JVene · Sep 04, 2018 at 05:50 PM 0
Share

Can I see a small code example of this being implemented?

Show more comments
avatar image
0

Answer by VadimMinsk · Aug 23, 2018 at 07:15 AM

Check out Markov chains. With this you can easily control the probability of applying certain rule, based on what other rules were already applied.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

541 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Moving an object which changes direction overtime and instantiates a new clone on the last position it left 1 Answer

Is this making my AI move? 0 Answers

Player spawning systems. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges