Python Forum
Building a patterned grid from a dictionary...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Building a patterned grid from a dictionary...
#3
I often use a dictionary for game boards. Tuples are hashable, so they can be used as keys in a dictionary. So you use a tuple of the coordinates of the peg holes as the keys of the dictionary, and the state of each peg hole is the value.

And Larz60+ is right that boolean may not be the best way to store the state. If your peg holes can have more than two states (empty, unusable, peg), than you want something that can handle more than two states. You can use 'X' and 'O', and then it's easy to print the board on the screen. However, it might be that the way you are processing the peg holes would make integer values easier to use in the processing. So you want to think about where in your program you want to interpret the values, and where in your program you want to make use of them as they are.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Building a patterned grid from a dictionary... - by ichabod801 - Oct-01-2016, 01:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Building a dictionary .update entry from variables Curbie 5 1,536 Sep-03-2024, 07:31 PM
Last Post: Curbie
  Converting a patterned string or text into excel table soup1987 1 2,774 Oct-03-2019, 01:37 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020