Front Office Football Central  

Go Back   Front Office Football Central > Main Forums > Dynasty Reports
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 09-13-2016, 02:58 PM   #1
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Yet another person learning Python - 100 m Simulator

So at the risk of the dynasty forum becoming a python forum, here goes another dynasty thread involving someone learning python.

Some background, I am not a programmer, I had to take 2 programming courses 15 years ago as part of my 1st year engineering courses. After my 3rd year I went on internship, for the next 16 months I was supposed to spend about 50% of my time on data entry, manually parsing files of data that had millions of lines of data (i.e. larger than excel could handle). I wound up teaching myself vba and after a month I was able to complete my task for the year. This is when I really learned to appreciate the power of programming.

One of the things I do at work is review the interpretation of instrumentation. This involves looking at lots of data, as well as training people to process and interpret data. This takes a lot of my time. I have written some vba to help with processing data, however, it's not ideal and there is more data than even excel can handle. Ultimately I'd like to create some kind of gui to manage our specialized instrumentation data and create presentations for clients.

I've also been building an arduino weather station for my dad for christmas. I'd like to write some code and prepare some graphs to support this.

Naturally I've decided to learn python by building a track and field simulator. What I'll try and detail are my many failures at trying to become a better coder and to develop a piece of software that will hopefully help me with my other endeavors. I welcome any comments and suggestions you have along the way.

I've settled on python after some other ill fated attempts. I like that it's object oriented (at least I think that's what I like about it) and it's syntax at least reminds me of other languages I "know" (vba, c++). It also seems like it has lots of other modules that can plug into it.


Last edited by nilodor : 09-13-2016 at 06:35 PM.
nilodor is offline   Reply With Quote
Old 09-13-2016, 03:14 PM   #2
Radii
Head Coach
 
Join Date: Jul 2001
Very cool, good luck! I recently wrote a simple bot for twitch.tv streams that was my first experience with python... extremely simple, but enough to have me interested
Radii is offline   Reply With Quote
Old 09-13-2016, 03:26 PM   #3
johnnyshaka
College Benchwarmer
 
Join Date: Oct 2002
Location: Edmonton, AB
Good luck and I'll be following along.

I still need to get back on track with my Python edumacation...I keep finding new excuses to put it off.
johnnyshaka is offline   Reply With Quote
Old 09-13-2016, 05:44 PM   #4
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Thanks! I hope I don't offend too many people who actually know how to program.

To help learn Python I followed through the lessons here:
https://python.swaroopch.com/

I found they helped a lot and explained things pretty well.

I'm also using eclipse to write the actually code. It's nice because it highlights syntax and provides some tool tips for some of the functions. Although it did take me an hour to figure out how to get numpy to work with it.
nilodor is offline   Reply With Quote
Old 09-13-2016, 05:51 PM   #5
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Anyways, the base simulator I'd like to make is for the 100 m and 200 m dash. They are of interest to me because a long time ago I used to compete in them and it's always one of my favourite events to watch.

With an eye towards my other programs, I also see it as a good application to develop the skills I will need to build a weather station and instrumentation applet.

Some things I would like to accomplish from a long term perspective:
Reading in data from text files and parsing the data.
Developing a GUI allowing user input.
Animating and graphing data from the program.

Some things I would like to do from a make game fun perspective:
Have realistic results
Be able to watch the races in real time
Have country and athlete development

I think the last one can be pretty fun. I'm thinking about rating countries for competition of sport and have events change that with time. Trying to get money and grants for your athletes and developing your countries infrastructure. I think that could be a fun mini game.

A question for those who are reading, anyone interested in the math behind the sim engine? How I'm planning on fitting the data, what the data spread looks like etc? Or just kinda keep things programming focused?
nilodor is offline   Reply With Quote
Old 09-14-2016, 11:09 AM   #6
SirBlurton
High School Varsity
 
Join Date: Feb 2007
Awesome, more great content to read!

I would be very interested in the math....
Will be following with interest!
SirBlurton is offline   Reply With Quote
Old 09-14-2016, 02:08 PM   #7
JonInMiddleGA
Hall Of Famer
 
Join Date: Nov 2000
Location: Behind Enemy Lines in Athens, GA
Quote:
Originally Posted by nilodor View Post
A question for those who are reading, anyone interested in the math behind the sim engine? How I'm planning on fitting the data, what the data spread looks like etc? Or just kinda keep things programming focused?

Given the nature of the forum, the behind-the-dice view would likely always be welcome here.
__________________
"I lit another cigarette. Unless I specifically inform you to the contrary, I am always lighting another cigarette." - from a novel by Martin Amis
JonInMiddleGA is online now   Reply With Quote
Old 09-14-2016, 03:37 PM   #8
Radii
Head Coach
 
Join Date: Jul 2001
Quote:
Originally Posted by JonInMiddleGA View Post
Given the nature of the forum, the behind-the-dice view would likely always be welcome here.

+1, I'm interested in both.
Radii is offline   Reply With Quote
Old 09-14-2016, 03:50 PM   #9
CraigSca
Pro Starter
 
Join Date: Jul 2001
Location: Not Delaware - hurray!
Math, plz!
__________________
She loves you, yeah, yeah, yeah, yeah!
She loves you, yeah!
how do you know?
how do you know?

CraigSca is offline   Reply With Quote
Old 09-15-2016, 12:05 PM   #10
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Ok, math it is!

So a long time ago I used to run the 100 m, 200 m and once, the meatgrinder that is the 400 m, which is the worst thing I ever did. I have a reasonable idea of how each race progresses. The 100 m is pretty much a mad dash, generally you can pretty much push flat out for the entire race and not see much reduction in speed. The 200 m requires more discipline and you will be slowing down once you reach your peak speed. The 400 m is just a mess and is outside of what I want to even think about. So we'll stick to the 100 and the 200.

What my vision is, I want to have a visualization of the race, to play out in real time. Preferably with 8 bit sprites because Tecmo Super Bowl is still my favourite game.

To do this I need to:
Figure out where each athlete is at a given time.
Come up with some way to generate ratings or attributes for the athletes.

There's other stuff I need to do but these are the basics.

To accomplish any of these things I either need equations or data so I can generate my own equations. Remember we're gunning for something that is somewhat realistic here.

Amazingly this is actually really difficult. I can find some 20 m split data (which I feel is unacceptable) and very limited 10 m split data. I've also found a few papers on the kinematics of sprinting that come up with some work energy relationships (which as an aside I think are bullshit because plots of the derivatives don't make sense, if I get stuck maybe I'll post about this later).

So next post I'll post some 10 m split data and the simple equations that we can develop to give a our time space relationship.
nilodor is offline   Reply With Quote
Old 09-15-2016, 12:05 PM   #11
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Also does anyone know a good way to post graphs here?
nilodor is offline   Reply With Quote
Old 09-19-2016, 11:51 AM   #12
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
So we need a mule to carry us through our data set analyses and what better mule than old glue factory himself, Usain Bolt.

Here are his splits from the Berlin World Championship

Code:
Distance Time (sec.) Split (sec.) Reaction time 0.146 s 10m 1.85 s 1.704 s 20m 2.89 s 1.04 s 30m 3.78 s 0.89 s 40m 4.64 s 0.86 s 50m 5.49 s 0.85 s 60m 6.31 s 0.82 s 70m 7.11 s 0.80 s 80m 7.92 s 0.81 s 90m 8.74 s 0.82 s 100m 9.58 s 0.84 s

What I'd like to find is a function that fits the data, and also has some physical meaning (i.e. I can turn the constants into ratings).

After a few tries I settled upon using two functions for position as a function of time. A power law A*t^B for the first portion of the race and a good ol linear function for part two of the race. My switch is when the velocities are equal I'll move from the power law to the linear function.

The nice things are, for the linear function the constant is the sprinters maximum velocity. Also, both functions are relatively easy to take derivatives of so I can find the velocity and acceleration at any time.

While linear may not be the best fit ever, I think it's a reasonable compromise for now. I'll look at updating this after I've come up with some equations for the 200 m race.

Next up it's time to look at what range of coefficients I should use.
nilodor is offline   Reply With Quote
Old 09-19-2016, 11:51 AM   #13
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
So we need a mule to carry us through our data set analyses and what better mule than old glue factory himself, Usain Bolt.

Here are his splits from the Berlin World Championship

Code:
Distance Time (sec.) Split (sec.) Reaction time 0.146 s 10m 1.85 s 1.704 s 20m 2.89 s 1.04 s 30m 3.78 s 0.89 s 40m 4.64 s 0.86 s 50m 5.49 s 0.85 s 60m 6.31 s 0.82 s 70m 7.11 s 0.80 s 80m 7.92 s 0.81 s 90m 8.74 s 0.82 s 100m 9.58 s 0.84 s

What I'd like to find is a function that fits the data, and also has some physical meaning (i.e. I can turn the constants into ratings).

After a few tries I settled upon using two functions for position as a function of time. A power law A*t^B for the first portion of the race and a good ol linear function for part two of the race. My switch is when the velocities are equal I'll move from the power law to the linear function.

The nice things are, for the linear function the constant is the sprinters maximum velocity. Also, both functions are relatively easy to take derivatives of so I can find the velocity and acceleration at any time.

While linear may not be the best fit ever, I think it's a reasonable compromise for now. I'll look at updating this after I've come up with some equations for the 200 m race.

Next up it's time to look at what range of coefficients I should use.

Last edited by nilodor : 09-19-2016 at 11:52 AM.
nilodor is offline   Reply With Quote
Old 09-19-2016, 02:55 PM   #14
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
nilodor is offline   Reply With Quote
Old 09-19-2016, 03:09 PM   #15
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
nilodor is offline   Reply With Quote
Old 09-20-2016, 01:35 PM   #16
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
So I think that the initial model is a good one. We have an acceleration portion and constant velocity portion of the race. When I look at the 200 m race we may revisit the second assumption, but for now I think this is easier. Before we can get to programming we need to look at what range of parameters we can allow. The crossover point (where the race becomes constant vel

For reference the main parameters for our mule are:
A: 4.68
B: 1.43
Vmax: 12.15

The constant portion of V*time + C will come from equating the two equations, so it doesn't really matter.

Now we need to come up with variations in A, B and V that will give us realistic results. The main concern will be total time, I don't want to create some bionic humans that can run 8 second 100 m, but I also don't want realistic times, but unrealistic crossover points (i.e. the acceleration phase is like 2 seconds or something).

Until next post, maybe there will even be some programming!

Also for curiosity here is the mule data vs the fits (note reaction time at the start is removed)

Code:
Distance Split Fit 10 m 1.70 1.70 20 m 2.74 2.76 30 m 3.63 3.66 40 m 4.49 4.49 50 m 5.34 5.32 60 m 6.16 6.14 70 m 6.96 6.96 80 m 7.77 7.78 90 m 8.59 8.60 100 m 9.43 9.43

Last edited by nilodor : 09-20-2016 at 01:35 PM.
nilodor is offline   Reply With Quote
Old 08-08-2017, 01:05 PM   #17
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Ok, so it has been a while since I've updated things.

But I've been doing things in the interim.

For one I did this course: The Python Mega Course: Build 10 Real World Applications | Udemy

(ps never pay full price for a course on udemy. I think i got it for $10 or something, there are always sales).

The course was good and taught me a lot of the syntax and ways that python organizes things. There is still plenty I don't know, but I certainly feel like I know my way around a bit.

I've built a placeholder applet to simulate races. Where it is now is:
  • When I click start the progress bars fill in showing the athletes progress down the track.
  • I have to manually enter in the athletes name and country.
  • The flags appear through a reference to a resource file.
  • When the race is complete the time appears on the right side of the screen.



What I would like to work on next is getting the progress bar to fill in, in real time.

My first try at this was something like this:

In my main window app I have a function doRace
Code:
def doRace(self): #Do some stuff, generate athletes and assign countries A = athlete('Apple','ca') self.label.setText(A.Name) self.label_9.setPixmap(QtGui.QPixmap(":/flags/png/" + A.country + ".png")) sleep(0.1) #I had to put this in to get different rng seeds #race loop divy = 1000 for i in range(13000): # This repeats for each athlete self.progressBar.setProperty("value",xpos_100m(A,i/divy)) if xpos_100m(A,i/divy) >=100:self.label_17.setText(str(A.t100()))

What I tried to do was use sleep with a really small number, but that doesn't work right (i.e. an athlete who takes 10 s to complete the race takes 12s in real world time). I think the answer is using the threading module. But I'm not sure how to define a function inside a main window that uses threading.

I've tried to follow this example, but get a not responding when I try and implement it
Code:
import threading def do_every (interval, worker_func, iterations = 0): if iterations != 1: threading.Timer ( interval, do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1] ).start () worker_func () def print_hw (): print "hello world" def print_so (): print "stackoverflow" # call print_so every second, 5 times total do_every (1, print_so, 5) # call print_hw two times per second, forever do_every (0.5, print_hw)

Anyways, as I make progress I'll update it here, maybe

The next, next things on my list are to automatically generate the athlete names and country. Eventually these will be stored in a SQL database, but there will be a step in between.
nilodor is offline   Reply With Quote
Old 08-08-2017, 02:42 PM   #18
Young Drachma
Dark Cloud
 
Join Date: Apr 2001
very cool good luck following!
__________________
Current dynasty: OOTP25 Blitz: RTS meets Moneyball | OOTP Mod: GM Excel Competitive Balance Tax/Revenue Sharing Calc | FBCB Mods on Github
Young Drachma is offline   Reply With Quote
Old 08-08-2017, 03:14 PM   #19
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
One other thing that has become super evident is I need to find a way to do versioning or archiving or something in Eclipse so if I totally mess up my code I can revert back to something that works.
nilodor is offline   Reply With Quote
Old 08-08-2017, 03:30 PM   #20
Radii
Head Coach
 
Join Date: Jul 2001
Quote:
Originally Posted by nilodor View Post
One other thing that has become super evident is I need to find a way to do versioning or archiving or something in Eclipse so if I totally mess up my code I can revert back to something that works.

One option for some very simple local source control is:

Mercurial SCM


I use this for a solution that I wrote for twitch.tv streamers. I created two projects, one is the actual release version that is currently active and being distributed to streamers. The other is a development version. I make changes in the development version, and try to break my changes down into features, or blocks that make sense to me, and commit changes on a regular basis, into the development version. Once I've made enough changes and am happy with where I'm at and am ready to distribute a new update to the people using my software, I move all of those changes to the "production" version all at once, and then leave it alone again. Since I'm committing incremental changes as I finish new fixes or features to my development branch, the opportunity is always there to revert and go back to something else should I need to, or to pull out specific commits if one thing is no longer necessary.

This is all local and directory based and didn't require a ton of learning to get going. You could get away with something simpler than what I'm doing since you don't have any users for now. Just the development branch is needed.


There may be other solutions that would be easier for you, I'm not sure. I'm reasonable comfortable with git/github for work so I'm comfortable with source control concepts. I just wanted to keep this personal project entirely local (other than some FTP backups), so this is what I did.
Radii is offline   Reply With Quote
Old 08-09-2017, 03:15 PM   #21
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Quote:
Originally Posted by Radii View Post
One option for some very simple local source control is:

Mercurial SCM


I use this for a solution that I wrote for twitch.tv streamers. I created two projects, one is the actual release version that is currently active and being distributed to streamers. The other is a development version. I make changes in the development version, and try to break my changes down into features, or blocks that make sense to me, and commit changes on a regular basis, into the development version. Once I've made enough changes and am happy with where I'm at and am ready to distribute a new update to the people using my software, I move all of those changes to the "production" version all at once, and then leave it alone again. Since I'm committing incremental changes as I finish new fixes or features to my development branch, the opportunity is always there to revert and go back to something else should I need to, or to pull out specific commits if one thing is no longer necessary.

This is all local and directory based and didn't require a ton of learning to get going. You could get away with something simpler than what I'm doing since you don't have any users for now. Just the development branch is needed.


There may be other solutions that would be easier for you, I'm not sure. I'm reasonable comfortable with git/github for work so I'm comfortable with source control concepts. I just wanted to keep this personal project entirely local (other than some FTP backups), so this is what I did.

Cool! Thanks for the tip. This whole level of coding is new to me. I'm pretty good at VBA, but that's about it. I've downloaded Mercurial and got it working in Eclipse. Now I just need to understand the whole push/pull/commit thing and I'll be golden.
nilodor is offline   Reply With Quote
Old 08-09-2017, 03:29 PM   #22
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Quick update:

So I screwed around with threads and was able to get something working so now my code is working in two sections:

The actual race bit:

Code:
def doRace(self, i): divy = 1000 self.progressBar.setProperty("value",xpos_100m(self.A,i/divy)) if xpos_100m(self.A,i/divy) >=100:self.label_17.setText(str(self.A.t100())) self.progressBar_2.setProperty("value",xpos_100m(self.B,i/divy)) if xpos_100m(self.B,i/divy) >=100:self.label_18.setText(str(self.B.t100())) self.progressBar_3.setProperty("value",xpos_100m(self.C,i/divy))

And a main thread

Code:
def runRace(self): for i in range (13000): bob = threading.Thread(target=self.doRace, args=(i,), daemon=True) #bob = threading.Timer(interval=0.001,target=self.doRace, args=(i,), daemon=True) bob.start()

Now you can see where I made my first attempt at using a timer. Which crashed my program, probably for good reason. But it's a win! I also think I'm probably violating how threads work.
nilodor is offline   Reply With Quote
Old 08-10-2017, 08:42 PM   #23
Groundhog
Coordinator
 
Join Date: Dec 2003
Location: Sydney, Australia
Ahh threads... I think that's everyone's first major stumbling block when working with GUIs! Are you using Qt for your GUI? If so I highly recommend using the QThreads class instead of the threading module. Lots of Python folks might disagree, but QThreads was a real breeze to work with within Qt.
__________________
Politics, n. Strife of interests masquerading as a contest of principles.
--Ambrose Bierce
Groundhog is offline   Reply With Quote
Old 08-11-2017, 10:26 AM   #24
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Quote:
Originally Posted by Groundhog View Post
Ahh threads... I think that's everyone's first major stumbling block when working with GUIs! Are you using Qt for your GUI? If so I highly recommend using the QThreads class instead of the threading module. Lots of Python folks might disagree, but QThreads was a real breeze to work with within Qt.

Totally am using PyQt5. I will check for QThreads module, I didn't even know it existed! I hope it goes better than when it took me an hour to realize I had to manually convert my resource file into a rcc file to get it to load.
nilodor is offline   Reply With Quote
Old 08-12-2017, 03:05 AM   #25
Groundhog
Coordinator
 
Join Date: Dec 2003
Location: Sydney, Australia
This got me started with QThreads: python - Background thread with QThread in PyQt - Stack Overflow
__________________
Politics, n. Strife of interests masquerading as a contest of principles.
--Ambrose Bierce
Groundhog is offline   Reply With Quote
Old 08-13-2017, 10:26 PM   #26
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Ok, so I've done my best to implement the Qtimer module and I have things working similar to how they were with threads.

I've included an animated gif of the working applet, pardon the colour as I have a program to make things less white to reduce eyestrain
Spoiler


I'm sure there is a different way to do things but here is the code I've used, it took me way too long to figure it out:

Code:
class ExampleApp(QtWidgets.QMainWindow,design.Ui_MainWindow): def __init__(self): super(self.__class__,self).__init__() self.setupUi(self) self.pushButton.clicked.connect(self.runRace) self.genAthletes() self.timer = QTimer() self.timer.timeout.connect(self.runRace) self.counter=0 self.timer.setInterval(5) def runRace(self): if self.counter < 13000: self.doRace(self.counter) self.counter += 5 else: self.timer.stop() self.counter=0

Now it doesn't run in real time. This race was still taking 12 seconds for times just over 10 seconds. I think I need to change to a precise timer, but I'm not quite sure how to do that. I also think that I'm probably pushing it for how tight the timer can be using 5 msec jumps. My issue is that if I go much courser than I'll get some rounding errors in the races (which could lead to the animation showing the wrong person winning).
nilodor is offline   Reply With Quote
Old 08-14-2017, 02:29 PM   #27
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Ok, so I'm going to park the whole real time thing for now. It's pretty close, which counts in hand grenades, atom bombs and virtual track simulators.

I think the next steps are automating generation of the athletes. So this will mean getting a database of names tied to each country. I have some ideas about how to do this. I'm thinking I'll have a database for types of names, English, French, German, Spanish, Portuguese, Russian, Nordic, Arabic, Slavic, African, Asian, Indian and draw from there based on the percentages from the country? Maybe that's a bit crazy? I was kinda hoping to webscrape the database for each country from sports-reference.com/olympics. But I think it violates their terms of use. Maybe I could slow webscrape it? I'm not sure.
nilodor is offline   Reply With Quote
Old 08-15-2017, 05:55 AM   #28
Groundhog
Coordinator
 
Join Date: Dec 2003
Location: Sydney, Australia
I spent a surprisingly high % of my coding time working on exactly this... If you can find a smart webscrapper, Soccer leagues are the best place to find names outside of the US IMO. You will need to filter out non-national players, but most countries have pretty good league pages including player rosters. Naming conventions of some cultures makes it harder than you'd expect too!

Unfortunately the code I put together to scrape all these names was rendered useless when Kimono was bought out... They had some great customizable web scrapers.
__________________
Politics, n. Strife of interests masquerading as a contest of principles.
--Ambrose Bierce
Groundhog is offline   Reply With Quote
Old 08-15-2017, 01:24 PM   #29
SirBlurton
High School Varsity
 
Join Date: Feb 2007
I have a 15 mb SQLite database of names I pulled from a variety of sources, if you want it. I think I still have the excel version too, but I edited some frequency rates (I weighted more common names).

If memory serves, it has 42 demographic groups.
SirBlurton is offline   Reply With Quote
Old 08-15-2017, 02:12 PM   #30
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Quote:
Originally Posted by SirBlurton View Post
I have a 15 mb SQLite database of names I pulled from a variety of sources, if you want it. I think I still have the excel version too, but I edited some frequency rates (I weighted more common names).

If memory serves, it has 42 demographic groups.

I'd certainly be interested in it.

I've found a couple of sources:
data request - Multinational list of popular first names and surnames? - Open Data Stack Exchange

There's a german database with a whole bunch of first names.

And you can also order names from Generate a Random Name - Fake Name Generator that generate first and last names. The nice thing is you can order in bulk.
nilodor is offline   Reply With Quote
Old 08-15-2017, 04:17 PM   #31
SirBlurton
High School Varsity
 
Join Date: Feb 2007
I found some of the those sources too - mainly used the for female names. I've also not done much in the way of adhering to cultural name conventions...it's just first name, last name.

I also recall I had some unicode display issues - but I remember fixing that in one of my projects...will find the line.

If you're a dropbox user, shoot me a PM with your e-mail address and I'll send a link to the database...and as a bonus, a python file that picks a random one. Uses numpy though...I don't know how that impacts licenses if it's something commercial. Wouldn't be hard to do it another way though...

I'm travelling for work this week but if I get access, I could still send before I get home. It'll be karma for all the fun I had with your draft classes! I think those were yours...
SirBlurton is offline   Reply With Quote
Old 08-21-2017, 02:45 PM   #32
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Ok so I did some screwing around and I've decided that the next thing I should work on is getting it so I can generate a roster of athletes for a country. Then put them in a race.

I've just put together a very simple dodad:



What I'm planning on doing is making a database file that will contain all of the country information (flag, text colour, background color, the later ratings and such).

I just used some simple code:

Code:
import sys import CountryHome from PyQt5 import QtWidgets, QtGui class CountryApp(QtWidgets.QMainWindow, CountryHome.Ui_MainWindow): def __init__(self): super(self.__class__,self).__init__() self.setupUi(self) self.updateLabel() def updateLabel(self): self.label_2.setPixmap(QtGui.QPixmap(":/flags/flags/shiny/64/flags/flags/shiny/64/Antarctica.png")) self.label.setText("Antarctica") self.label.setStyleSheet("QLabel { color: rgb(255,255,255);" "background-color: rgb(0,0,0)}") def main(): app = QtWidgets.QApplication(sys.argv) form = CountryApp() form.show() app.exec_() if __name__ == '__main__': main()

What I will have is a list of athletes down at the bottom, from which you can select them to put them in a race.

Later what I'm thinking is this will serve as some sort of home screen, there will be a tab for country stats, athletes roster, training, staff, etc.

The real game portion will be in how you can improve your country. I'm envisioning something where you select a country, say Canada. At the start each country will receive a grade, one in interest level (how popular the sport is), available funding, infrastructure, historic success, and maybe some others.

So for Canada funding might be a B+ (rich country, lots of corporations that could sponsor athletes), interest might be a C (not super popular, would be behind hockey, football, soccer, baseball, basketball, skiing, in popularity), infrastructure might be a B, historic success B+.

All of these things will go into generate the athletes you can receive and how well they can develop. The more interest, the more likely top athletes will choose track, the more investment you can get (national or corporate), the more the athletes will develop, the better they do, the more interest arises, etc.

Some countries would be very easy, like the US, some would be almost impossible, like Palau, while some may be interesting, like India.

Anyways, that's a long way ahead, for right now I'm still thinking about things like how do I open a Qwidget in a QMainWindow, and how can I switch tabs in a window. I think I need to redefine crawl, walk, run to sit, crawl, walk, run, because I'm about as far from running as I can be right now.
nilodor is offline   Reply With Quote
Old 08-22-2017, 04:48 PM   #33
SirBlurton
High School Varsity
 
Join Date: Feb 2007
I really like the direction you're taking with this project...very cool!
I've always struggled with coming up with clear mechanics, so I think the fact you have a sense for how you want the central gameplay to work sets you up for success.

To some extent, I find the coding "just happens", especially the GUI part. There are so many resources out there that you can usually find a way to implement what you need.

I've only played with tabs a little bit...I ended up creating a QStackedWidget as my "central widget", then use the menu system to flip between screens.

I think I probably pack too much game logic into my screens though, I've been working a lot on keeping them separated in my new projects.

Anyway, if it's helpful at all, here's an edited example of how I've set up my multi_screen apps.

Code:
class MyMainWindow(QtGui.QMainWindow,Ui_MainWindow): def __init__(self, parent=None): super(MyMainWindow,self).__init__(parent) self.setupUi(self) self.centralwidget = QtGui.QStackedWidget() self.setWindowState(QtCore.Qt.WindowMaximized) self.setCentralWidget(self.centralwidget) self.actionHiring.triggered.connect(self.showHiring) def showHiring(self): self.centralwidget.addWidget(self.pilot_hiring_screen) self.centralwidget.setCurrentWidget(self.pilot_hiring_screen) self.pilot_hiring_screen.update_pilot_roster()
SirBlurton is offline   Reply With Quote
Old 08-22-2017, 07:34 PM   #34
Groundhog
Coordinator
 
Join Date: Dec 2003
Location: Sydney, Australia
Quote:
Originally Posted by SirBlurton View Post
I've only played with tabs a little bit...I ended up creating a QStackedWidget as my "central widget", then use the menu system to flip between screens.

x2, although I did it a little differently - I didn't use the QStackedWidget as the central widget, I just added a bunch of QStackedWidgets to my standard form (I think just a basic QWidget from memory) - one that covers the entire form so you can switch between title screens/game screens etc, then one for the main in-game form that lets you navigate between different screens while keeping your top menu bar, and then use the .setCurrentIndex() method to switch between the tabs.
__________________
Politics, n. Strife of interests masquerading as a contest of principles.
--Ambrose Bierce
Groundhog is offline   Reply With Quote
Old 08-23-2017, 10:04 AM   #35
nilodor
College Benchwarmer
 
Join Date: Oct 2000
Location: calgary, AB
Cool, I'll have to check it out
nilodor is offline   Reply With Quote
Old 08-23-2017, 12:49 PM   #36
SirBlurton
High School Varsity
 
Join Date: Feb 2007
Quote:
Originally Posted by Groundhog View Post
x2, although I did it a little differently - I didn't use the QStackedWidget as the central widget, I just added a bunch of QStackedWidgets to my standard form (I think just a basic QWidget from memory) - one that covers the entire form so you can switch between title screens/game screens etc, then one for the main in-game form that lets you navigate between different screens while keeping your top menu bar, and then use the .setCurrentIndex() method to switch between the tabs.

That's interesting....would you be able to show an example?
SirBlurton is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 06:48 PM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.