Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 etnom22000 · Dec 06, 2020 at 07:54 AM · scripting problemscripting beginnerpuzzleadvice

Advice on making a Sudoku like win condition for a game

Hello everyone.

I was wondering the best way to set up a UI trigger to enable if, say, all 9 numbers exist on a 3x3 grid in any given order, but no number repeats itself(like one 3x3 in sudoku) The puzzle part I can take care of, its the idea of how to trigger a condition if 1-9 sows up in any given order on a 3x3 space/grid/3x3 objects, etc.

Any advice, links or tutorials would help me greatly and be appreciated.

Comment
Add comment
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

2 Replies

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

Answer by Llama_w_2Ls · Dec 06, 2020 at 03:10 PM

You can have an object-like class that handles the win checking per square. It may have 9 slots (3x3 square) and can have a value from 1-9, or null if not filled yet. Every move, you might check the array of slots and check if it isn't missing any number from 1-9. If it is, then it is either not filled yet, or multiple entries of the same number have been entered. I don't want to write code for this, but I can help you if you need it. Just some advice from me. @etnom22000

Comment
Add comment · Show 3 · 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 sacredgeometry · Dec 06, 2020 at 03:55 PM 0
Share

Unfortunately thats not how sudoku works. You also have vertical and horizontal line checks its not just that you need to check if a square has distinct values.

avatar image etnom22000 · Dec 06, 2020 at 06:28 PM -1
Share

Thanks so much for the info! You made this pretty clear. I'm not an expert on arrays so looking into this will help me get better at it!. Thanks so much!

avatar image sacredgeometry etnom22000 · Dec 06, 2020 at 06:49 PM 0
Share

This answer wont work btw.

avatar image
0

Answer by sacredgeometry · Dec 06, 2020 at 04:05 PM

Personally I would think of your data-structure as something separate from your ui. The optimal way of storing and working on your data is rarely 100% synonymous with the interface you expose to the user.

Maybe using something like a multi dimensional array for the entire grid and then just bounding the search within a certain range of those arrays.

For example (and excuse the contrived example):


int[,] board = new int[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

Would allow you to index a value in the array like board[0, 0]


What this means is that you can iterate over the rows or columns one at a time by incrementing either the "x" or "y" indexes checking that each of the values are distinct and that you have all of them.


That will give you the win condition regardless of the third condition i.e. that each square will have unique values which is an implied emergent property of the other.

Comment
Add comment · Show 2 · 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 etnom22000 · Dec 06, 2020 at 06:30 PM 0
Share

This is great! I will research more about this to use it. This version that uses the rule "Only 1-9 and the box cannot contain doubles" is to simplify the puzle. The game I'm working on focuses on the button presses to change multiple tiles at once in sequence. So when presses, it counts from 1-9 and also does the neighboring squares/numbers as well. so corner will change 3 object in sequence middle does top, bottom, left and right and so on. The sudoku part is just the containing of the numbers 1-9, in any order.

avatar image sacredgeometry etnom22000 · Dec 06, 2020 at 06:50 PM 0
Share

If you are making a sudoku board (i.e a 3x3 grid of 3x3 sections) then the answer you accepted wont work. Because you have to do cross section checking. You cant just check if a section has distinct values because each row and column also needs to have distinct values.

Edit: "The sudoku part is just the containing of the numbers 1-9, in any order."

Ok well as long as you are not needing to do sudoku checking it should be fine.

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

260 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

Related Questions

Jumping makes the player jump 2 times, 2 Answers

How to adjust camera position/rotation when player looks up or down? (Third Person Camera) 1 Answer

Point Counter Works Only Once! 1 Answer

(C#) SetActive isn't working on my UI 2 Answers

Random switch enum with a delay 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