473,811 Members | 3,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need ideas and insights on a project...

true911m
92 New Member
I would like to solicit your thoughts and ideas (code can come later) about how you would approach a project idea I just tossed together. I chose this as a testbed for me to play with objects, specifically multiple instances of a few specific objects, and as I thought about it, it raised a lot of questions about how to manage, contain, signal all of those objects that do almost the same thing at the same time.

I want to build an OO bingo simulator. While it is not necessarily the most efficient approach, let's academically assume it needs to be object-oriented.

We have 75 ball objects, which can be picked randomly by a machine, and which therefore need an awareness of being picked(), since no ball can come up twice in a game.

We have a scorecard grid with 25 square objects on it, and appropriate values for each column of the grid (B: 1-15,i:16-30, etc.), which are chosen randomly on each card. If we work with all 75 possible numbers (maybe not the best approach), each number needs to know if it's on the bingo card for this game, whether it's matched a number that's already been picked(), and whether it's a Freebie (middle square on the card - 'FREE' instead of a number)

Initial questions:

Can like objects be grouped by some mechanism such that changing an external parameter has them respond to that change, or do they each need to be iterated/manipulated each time to become "aware" of global changes? For example, a number is picked() - can the squares "know" if one matches the new number, or do I need to trigger each one to check?

Maybe I'm thinking in more of a parallel-thread mode here, one thread per object, which remains "active" during the game. Is that way out there? It's probably over my head at this point anyway.

Reel me in; tell me what you think.
Dec 16 '06 #1
27 2180
bartonc
6,596 Recognized Expert Expert
We have 75 ball objects, which can be picked randomly by a machine, and which therefore need an awareness of being picked(), since no ball can come up twice in a game.
Actually, I believe that the machine is the object in question and that balls are data that it dispences. The machine (object) has a better chance of encapsulating awareness of which numbers have been dispensed than a ball does.

We have a scorecard grid with 25 square objects on it, and appropriate values for each column of the grid (B: 1-15,i:16-30, etc.), which are chosen randomly on each card. If we work with all 75 possible numbers (maybe not the best approach), each number needs to know if it's on the bingo card for this game, whether it's matched a number that's already been picked(), and whether it's a Freebie (middle square on the card - 'FREE' instead of a number)

Initial questions:

Can like objects be grouped by some mechanism such that changing an external parameter has them respond to that change, or do they each need to be iterated/manipulated each time to become "aware" of global changes? For example, a number is picked() - can the squares "know" if one matches the new number, or do I need to trigger each one to check?
I've got similar thoughts here. Going to look for some examples

Maybe I'm thinking in more of a parallel-thread mode here, one thread per object, which remains "active" during the game. Is that way out there? It's probably over my head at this point anyway.

Reel me in; tell me what you think.
Do you have Robin Dunn's book: wxPython in Action?
Dec 16 '06 #2
true911m
92 New Member
Actually, I believe that the machine is the object in question and that balls are data that it dispences. The machine (object) has a better chance of encapsulating awareness of which numbers have been dispensed than a ball does.



I've got similar thoughts here. Going to look for some examples



Do you have Robin Dunn's book: wxPython in Action?
I haven't read it all, just looked up a few things.

I'm not really interested in the GUI in particular, more the logic. If the GUI objects are easier to build/attach to than abstract code items, that's fine.
Dec 16 '06 #3
true911m
92 New Member
The reason for the balls, instead of the machine, as objects is that I want to exercise multiple identical objects in action. JFYI.
Dec 16 '06 #4
bartonc
6,596 Recognized Expert Expert
The reason for the balls, instead of the machine, as objects is that I want to exercise multiple identical objects in action. JFYI.
Ok, I'll buy that. So if each ball instance needs to know which number was just picked() here's how I'd (almost) lay out the structure:

Expand|Select|Wrap|Line Numbers
  1. # I do this a bit differently, but Mr. Dunn says something like this:
  2.  
  3. class NumberDispenser(object):
  4.     def __init__(self):
  5.         self.clients = []
  6.  
  7.     def RegisterClient(self, client):
  8.         self.clients.append(client)
  9.  
  10.     def UpdateClients(self, data):
  11.         for client in self.clients:
  12.             client.Update(data)     # This part I don't like:
  13.                                     # having to know the name of the client function here
  14.  
  15. class NumberClient(object):
  16.     def __init__(self, server, name):
  17.         self.name = name
  18.         server.RegisterClient(self)
  19.  
  20.     def Update(self, data):
  21.         print self.name, data
  22.  
  23.  
  24. if __name__ == "__main__":
  25.     server = NumberDispenser()
  26.     client1 = NumberClient(server, "client #1")
  27.     client2 = NumberClient(server, "client #2")
  28.  
  29.     # call this in response to some event or whatever
  30.     server.UpdateClients(6545)
Dec 16 '06 #5
bartonc
6,596 Recognized Expert Expert
I haven't read it all, just looked up a few things.

I'm not really interested in the GUI in particular, more the logic. If the GUI objects are easier to build/attach to than abstract code items, that's fine.
Actually, I don't use the GUI stuff from the book. I really like (and use similar design) the Model-View-Controler idea. There is also threading discussion toward the end.
Dec 16 '06 #6
true911m
92 New Member
Actually, I don't use the GUI stuff from the book. I really like (and use similar design) the Model-View-Controler idea. There is also threading discussion toward the end.
OK, that's not ringing any bells. Can you elaborate on this - what, where, refs?
Dec 16 '06 #7
true911m
92 New Member
Ok, I'll buy that. So if each ball instance needs to know which number was just picked() here's how I'd (almost) lay out the structure:

Expand|Select|Wrap|Line Numbers
  1.     def UpdateClients(self, data):
  2.         for client in self.clients:
  3.             client.Update(data)     # This part I don't like:
  4.                                     # having to know the name of the client function here
  5.  
  6. ...
  7. if __name__ == "__main__":
  8.     server = NumberDispenser()
  9.     client1 = NumberClient(server, "client #1")  # <===
  10.     client2 = NumberClient(server, "client #2")  # <===
  11.  



Regarding that, my original thought, which is admittedly BASIC-esque, was to define an array where each element would become an instance. I don't know how to translate that here, but such a construct would alleviate much of the naming overhead. I guess it would also be redundant, since if I did that I wouldn't need the objects at all. :) But like I said, it's an academic exercise...

Can I use some form of eval() to create something like (this is just off the top of my head, trying to get the idea across):
Expand|Select|Wrap|Line Numbers
  1. varhdr = 'client'
  2.  
  3. for i in range(75):
  4.     eval(varhdr+str(i)+' = NumberClient(server, "client #'+str(i)+'")')
  5.  
Don't know if that's close to a proper use of eval; in SB we had a means of constructing dynamic lines of code like that so they could be reused, as in a loop.

This problem is what I was referring to when I mentioned a curiousity about how people would "group"cont rol of these objects.

Actually, the use of a class variable, as discussed in that other thread, may make sense here. Such as, when a number is picked,

Expand|Select|Wrap|Line Numbers
  1. NumberClient.LastPicked=32
  2.  
  3. for square in grid:
  4.     # execute instance.CheckPicked code here
  5.     # each instance of NumberClient class now has 
  6.     # a self.LastPicked value of 32 to process against
  7.  
  8.  
Dec 16 '06 #8
bartonc
6,596 Recognized Expert Expert
Regarding that, my original thought, which is admittedly BASIC-esque, was to define an array where each element would become an instance. I don't know how to translate that here, but such a construct would alleviate much of the naming overhead. I guess it would also be redundant, since if I did that I wouldn't need the objects at all. :) But like I said, it's an academic exercise...

Can I use some form of eval() to create something like (this is just off the top of my head, trying to get the idea across):
Expand|Select|Wrap|Line Numbers
  1. varhdr = 'client'
  2.  
  3. for i in range(75):
  4.     eval(varhdr+str(i)+' = NumberClient(server, "client #'+str(i)+'")')
  5.  
Don't know if that's close to a proper use of eval; in SB we had a means of constructing dynamic lines of code like that so they could be reused, as in a loop.

This problem is what I was referring to when I mentioned a curiousity about how people would "group"cont rol of these objects.

Actually, the use of a class variable, as discussed in that other thread, may make sense here. Such as, when a number is picked,

Expand|Select|Wrap|Line Numbers
  1. NumberClient.LastPicked=32
  2.  
  3. for square in grid:
  4.     # execute instance.CheckPicked code here
  5.     # each instance of NumberClient class now has 
  6.     # a self.LastPicked value of 32 to process against
  7.  
  8.  
A list comprehension is what you are looking for. A comprehension is a very handy tool when you don't need much stuff going on in a loop, but you do need elements appended to a list. This technique creates the list object and fills it in all at once. Notice, also, the C-line string formatting. I use it all the time.


Expand|Select|Wrap|Line Numbers
  1. class NumberDispenser(object):
  2.     def __init__(self):
  3.         self.clients = []
  4.  
  5.     def RegisterClient(self, client):
  6.         self.clients.append(client)
  7.  
  8.     def UpdateClients(self, data):
  9.         for client in self.clients:
  10.             client.Update(data)     # This part I don't like:
  11.                                     # having to know the name of the client function here
  12.  
  13. class NumberClient(object):
  14.     def __init__(self, server, name):
  15.         self.name = name
  16.         server.RegisterClient(self)
  17.  
  18.     def Update(self, data):
  19.         print self.name, data
  20.  
  21.  
  22. if __name__ == "__main__":
  23.     server = NumberDispenser()
  24.     # list comprehension syntax uses [] on around the expession, generators use ()
  25.     instanceList = [NumberClient(server, "client%d" %i) for i in range(5)]
  26.     for inst in instanceList:
  27.         print inst.name
Dec 17 '06 #9
bartonc
6,596 Recognized Expert Expert
The list comprehension here
Expand|Select|Wrap|Line Numbers
  1. instanceList = [NumberClient(server, "client%d" %i) for i in range(5)]
is equivalent to
Expand|Select|Wrap|Line Numbers
  1. instanceList = []
  2. for i in range(5):
  3.     instanceList.append(NumberClient(server, "client%d" %i))
which may be easier to read. I learned comprehensions so long ago that I have forgotten if the benefits actually outweigh the mashed syntax. If I get a break, I'll look it up and get back to you.
Dec 17 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4542
by: Slash | last post by:
Hello everyone I'm looking for seminar topics (and project ideas too) for my final year in Computer Engineering. I'm considering doing something on C++/Linux, considering that I love it so much -- I'm still learning it though. The topic could be anything computer-related at all, anything new and interesting perhaps :) Perhaps a research topic.
10
2893
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work for multiple companies and work for multiple divisions within each company. Within each division he can work in multiple departments and within each department he can work with multiple groups. In each group he works on multiple projects. All the...
2
4072
by: micangello | last post by:
i need ideas on what my final year project can be about i have studied 2 years of pure math (advanced calculus and algebra, topology, statistics..... ) i then switched ot computer science now in in my last year in Computer Science i have taken courses in Numerical analysis Operation Research
3
1773
by: Kinokunya | last post by:
Hi guys, My group and I will be working on our final year project, the scope to do a program/web-based application similar areas of functionalities like the PyLint and PyChecker; a Python syntax checker. We have no Python background, equipped only with some knowledge of Java and Dot net. We did some research on PyLint and found out that there are 2 common modules that PyLint & PyChecker are using, namely logilab-astng and
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.