Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - George McGinn

Pages: 1 [2] 3 4 ... 14
16
QB64 Discussion / Re: Double Check on order of operations
« on: January 30, 2022, 03:28:25 pm »
@luke

In all of math, Integer Division is not treated any different than division or multiplication.

The same goes for MOD.  (See: https://mathworld.wolfram.com/Division.html

Integer Division returns the Quotient only from a division, where MOD returns only the remainder. All are considered division and is supposed to be performed left to right.

All three (four including MOD) should be treated on the same level. Hence, with a mixture of \ and /, all are computed left to right.

For example:  5 / 10.5 \ 5 * 6

The correct answer is 15, yet QB64 returns 0. 0 is incorrect.

Check the following results from Wolfram Alpha:
https://www.wolframalpha.com/input/?i=5+%2F+Quotient%2810.5%2C+5%29++*+6

What is the reason why Integer Division comes after division and multiplication?

The full list, from highest to lowest precedence, is:
  • Exponentiation (^)
  • Negation (-)
  • Division (/), Multiplication (*)
  • Integer Division (\)
  • MOD
  • Subtraction(-), Addition(+)
  • Equality (=), Ordering (<, <=, >, >=)
  • NOT
  • AND
  • OR
  • XOR
  • EQV
  • IMP
Operators on the same line are evaluated left to right, or inside out in the case of the unary operators NOT and negation. In practice, this means:
  • NOT 2 + 3 is NOT (2 + 3) because + has higher precedence and so is evaluated first
  • - 2 ^ 3 = -(2 ^ 3) because ^ has higher precedence and so is evaluated first

Apparently this full list isn't in the wiki anywhere; it probably should be.

17
QB64 Discussion / Re: Double Check on order of operations
« on: January 22, 2022, 03:02:59 pm »
This is how it is supposed to work:

Quote
The PEMDAS rules that state the order in which the operations in an expression should be solved, are:
1. Parentheses - They take precedence over all other operators. The first step is to solve all the operations within the parentheses. Work out all groupings from inside to out. (Whatever is in parentheses is a grouping)
2. Exponents - Work out all the exponential expressions.
3. Multiplication and Division - Next, moving from left to right, multiply and/or divide whichever comes first.
4. Addition and Subtraction - Lastly, moving from left to right, add and/or subtract whichever comes first.

So in the code provided, * and \ (/) are processed left to right in the order they appear in the calculation (same goes for addition/subtraction).

It seems that QB64 isn't doing that, otherwise the answer should be 186 instead of 421

The code below breaks Cobalt's formula down the way it is supposed to be calculated:

Code: QB64: [Select]
  1. Scale%% = 3
  2. Xloc% = 450 - 16 * 11 \ 2 * Scale%%
  3.  
  4. PRINT Xloc%
  5.  
  6. x = 16 * 11
  7. x = x \ 2
  8. x = x * Scale%%
  9. x = 450 - x

18
QB64 Discussion / Re: Our own version of Linux
« on: December 27, 2021, 06:52:28 pm »
If you are looking to build your own Linux OS, here are some resources you should check out.

A minimal Linux OS usually means no GUI or Windows. Everything is done for the command line of a terminal program. For example, the difference between, say Ubuntu 20.04 and Ubuntu 20.04 Server is that the Server version does not have a GUI desktop and the supporting files for it.

And minimal may also mean that only those files necessary are included. If you need, say Python, you'll have to install it. If you need to print, you'll have to install CUPS, etc.

If you are looking to build a customizable version of Linux, check out:

https://www.maketecheasier.com/6-tools-to-easily-create-your-own-custom-linux-distro/

AND:




19
Programs / Converting MIDI to WAV and MP3 (BASH Script)
« on: December 19, 2021, 07:20:03 pm »
Awhile back I ran into issues where my MIDI file collection needed to be converted into an acceptable file format to be able to play it in QB64, as the only valid files are: WAV, OGG or MP3 file types.

So below is a BASH Shell script that converts a MIDI file into BOTH a .wav and a .mp3 file.

You will need to have installed:

Zenity - Used for the BASH GUI
timidity - To convert MIDI to WAV (Software synthesizer)
ffmpeg -  To convert timidity WAV to MP3 files.

Except for Zenity, timidity and ffmpeg I believe exists on all OS's, Since I only run Linux and macOS, I can't guarantee that this will run on Windows, but the principle behind what the script does should apply. I haven't completely tested it yet on my macOS, but I have installed the three requirements above. If I have any issues with it, I will post an update (not an edit). I know not all features of Zenity work on a macOS system. So I may create a command-line version.

Now I can convert all my Christmas MIDI files into WAV and MP3 files.

Merry Christmas.

Code: Bash: [Select]
  1. #!/bin/bash
  2. #
  3. # MIDI to WAV and MP3 Converter -- Shell Script -- George McGinn 2021
  4. #Version 1.0 -- December 19, 2021
  5. #
  6. # convertMIDI - Script to convert a MIDI file into both a .WAV and .MP3
  7. #               audio formats. Uses Zenity to retrieve the MIDI file,
  8. #               create the output files, show progress, and other messages.
  9. #
  10. # NOTES: This script needs the following installed:
  11. #        Zenity - Script's GUI
  12. #        timidity - Converts the MIDI to a WAV format
  13. #        ffmpeg - Converts a MIDI/WAV to MP3 format
  14. #
  15. # USEAGE:
  16. #   This script can be invoked from a File Manager or from a terminal
  17. #   session. When started, it defaults to your $HOME/Music directory.
  18. #   Select the location of your MIDI file. You will be able to change
  19. #   the directory. Select your MID or MIDI file then click [OK]. Next
  20. #   The output for the WAV and MP3 files will default to your $HOME/Music
  21. #   directory. You can change this location. Enter the file name WITHOUT
  22. #   any extensions. The .wav and .mp3 will be added to the file name
  23. #   you provide. The script will create both files.
  24. #
  25. #   If you select directory(ies) that require ROOT access, the script will
  26. #   ask you for your password and then do the conversions as stated above.
  27. #   There is no need to start this script with sudo.
  28. #
  29.  
  30. # Change directory to Home/Music
  31.  
  32. cd $HOME/Music
  33.  
  34. # Get the MIDI path/file name
  35. mid=$(zenity --file-selection)
  36. if [ $? = 1 ];
  37.         then exit
  38. fi
  39.  
  40.  
  41. # Get save path/file name
  42. wav=$(zenity --file-selection --save --confirm-overwrite)
  43. if [ $? = 1 ];
  44.         then exit
  45. fi
  46.  
  47. # see if current user has write permissions by creating an empty file
  48. > "$wav:".wav
  49. > "$wav".mp3
  50.  
  51. # if so, delete the empty files and do the conversion and show progress bar
  52. if [ $?  -eq 0 ]; then
  53.         rm "$wav:".wav
  54.         rm "$wav".mp3
  55.  
  56.         timidity "$mid" -Ow -o "$wav".wav  | zenity --progress --pulsate --auto-close --text "Converting to WAV..."
  57.         timidity "$mid" -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k "$wav".mp3 | zenity --progress --pulsate --auto-close --text "Converting to MP3..."
  58.  
  59. # Tell us the conversion is done
  60.         zenity --info --text "Conversion complete!"
  61.  
  62. # if not, get root password, run command as root
  63. else
  64. # Get the users password
  65.         passwd=$(zenity --password)
  66.  
  67. # Do the conversion and show a progress bar
  68.         echo $passwd|sudo -S timidity "$mid" -Ow -o "$wav".wav | zenity --progress --pulsate --auto-close --text "Converting to WAV..."
  69.         echo $passwd|sudo -S timidity "$mid" -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k "$wav".mp3 | zenity --progress --pulsate --auto-close --text "Converting to MP3..."
  70.  
  71.         if [ $? = 1 ];
  72.                 then exit
  73.         fi
  74.  
  75. # Tell us the conversion is done
  76.         zenity --info --text "Conversion complete!"
  77. fi
  78.  

20
Programs / Baseball/Softball Statistical Record-keeping System Pre-Release
« on: December 15, 2021, 02:25:29 pm »
I am posting the pre-release of my Baseball/Softball Statistical System for your input on this. I’ve been working on this for more than 4 months, and I need new eyes to spot things I can’t see. I also hope that some of you find it useful. The final release will have more features that can be used for advanced game record-keeping and will include a suite of Sabermetric tools. Any comments from what works, what doesn’t, clarity needed in my HELP and other documentation, and how to make this work with other relational databases like MariaDB and SQLite will be very helpful.

This Linux-only (for now) application records and produces baseball or softball offensive, defensive and pitching statistics and reports for players and for multiple teams. This can be used if you manage/coach one or more youth baseball teams, run a single baseball/softball league, or play a game like Strat-O-Matic Baseball.

This is a pre-release, as I still have some more features to code. But it appears stable enough to unleash on all of you.

Originally I was going to write just a small program for myself, but some others I know wanted to use it as well, and what started off as a tutorial on using MySQL (or just SQL) with QB64 turned into a large application that includes QB64 code, C++ functions, MySQL, HTML, CSS, JavaScript, and Zenity among others.

I have been also working on getting the code in the WIKI (MySQL Client) by Galleon working, but I will be taking that program in another direction, and those who are waiting for that tutorial will have it, probably by the end of January (I hope!).

This is now an example of using various tools in Linux to create a slick-looking application based on QB64. About a month ago, the QB64 code alone topped 7,000 lines of code, with all the code going above 10,000 lines, so this is a substantial application.

The Readme file on my GitHub is quite extensive (and still a work in progress), but there should be enough information there that you can run this application. Also, when you start up this application, on the ABOUT/Splash Screen, there is a link to a menu where you can read all the HELP files for each function/feature to familiarize yourself with the system.

I have tested this on Ubuntu, Linux Mint, and Q4OS (before I added the ability for the application to adapt to Dark/Light/Standard desktop themes), so you may have to tweak the colors of your Dark Theme in the /help/baseballStyle.css file. The rest works automatically.

I know some of you use a different relational DB then MySQL, and I am interested in hearing from you so I can add the ability to use different DB’s transparent to the user.

I have attached the ZIP file with all the source code and files needed to run this application, but I do suggest that you visit my GitHub listed below to read what is documented.

Here is the link to the pre-release: https://github.com/GeorgeMcGinn/baseballStats/releases/tag/v0.27.0

Here is the link to the files on GitHub: https://github.com/GeorgeMcGinn/baseballStats

 

21
QB64 Discussion / Re: DECLARE LIBRARY adding extra slashes to paths
« on: December 15, 2021, 12:29:34 pm »
Couldn't you use a ../ like you can when you have an INCLUDE?

For example:
Code: QB64: [Select]
  1. endPROG:
  2. ' *** CLOSE Log File
  3. '
  4.  
  5. ' *** Remove work files if they exist
  6. '$INCLUDE: '../include/deleteWorkFiles.inc'    
  7.     PRINT #flog%, ">>>>> Executing endPROG"
  8.     PRINT #flog%, ""
  9.     PRINT #flog%, "": PRINT #flog%, "*** " + ProgramName$ + " - Terminated Normally ***"
  10.     CLOSE #flog%
  11.     SYSTEM

The code snippet is part of a SUB located in the /include directory, because it is used in 3 programs. the deleteWorkFiles.inc is used in many of my programs in the project directory.

I've never tried this with DECLARE LIBRARY statements before, but wouldn't it still resolve correctly?

22
QB64 Discussion / Re: IF THEN issue using AND, I think I'm losing my mind!
« on: December 10, 2021, 08:09:50 pm »
This should also work:

Code: QB64: [Select]
  1. IF P.Mouse_over_R AND NOT P.Mouse_over_B THEN

23
I was only joking about you cheating --- I figured you saved more in your stores, because the rats only eat what is stored, and not what comes out of the fields. That's the insects' job! But that you indeed were unlucky that year. I still have fine-tuning to do there. Be aware the original game knocks you down in status at the end if you do not maintain 10 acres per person!

I kind of figured when I added another way to deplete crops/harvests, I added disasters to try and mitigate the extra damages, giving the player twice as many ways to reduce the population, but I always knew that I would have to adjust the starting parameters, as I said or implied in my response to SMcNeill. In my notes on my research of the period, I have the actual population and size of land Hammurabi had at the start of his reign, and may start with that. The final version will have some chances or fate (being at the mercies of their gods!), with ways to help mitigate losses. But that period of time was a very perilous one. So some of that has to play into your future decision-making.

I had planned to, as in one of your posts, break up the population into the actual class-structure that existed back then. The five main classes were: The Ruling Class, Servant Class, Upper Class, Working Class, and Lower Class. Not everyone worked the land. The Servant Class was made up mainly of military members (Generals were in the Ruling Class), master craftsmen and palace/upper class servants, like cooks, etc.) I have three pages of a tree-diagram I created showing the hierarchy within each class. Not all will appear in the game, and I am still trying to figure out the ratio, as historical information about this is pretty vague, but I'll make it so the game is playable.

I do know how many people are needed to work a field, between the overseer to the oxen teams to field hands, it took at least 40 people to work one field (one field = 38.88 ha, or 96 acres, if my math is right that 1 hectare = 2.47 acres).

It will be a strategy game, one based on the real period 1800-1700 BCE, with the real dangers and gains. Besides making it enjoyable to play, I'd like to make it educational as well, so the more you play it, the greater knowledge you will gain from that period of time. A pretty tall order, but I love these kind of coding challenges.

Anything else you can think of, just let me know. I'm always open to suggestions and improvements. I'll probably have a rough program (the skeleton of the game engine) done by end of January next year, with some of these features working. It will use InForm for the GUI, to allow it to run on all platforms.


LOL  , no George I haven't cheated.
I don't like to win easily...

but as you can see from screenshot I have sold 300 acres (I remember at the price of 21 or 23 for acre) and of the starting 2800 bushels I have spent the more to save crops and cruelly the less to save citizens. (population 74 of those  15 migrants and 6 newborns...21 people joining the population in that year that rats take all my bushels!).
....
going out of joke...
as strategy game we start with 2800 bushels  100 citizens that need 20 bushel for each of theme = 2000 bushel for save 100 citizens...you can plant 100 acres using 3 bushel for acre so 300 bushels... so in perspective
100 citizens saved = 2000 bushels
800/3 = 266,666.... acres  that can be planted...--> if fortune kisses you, it is possible that you gain 5 bushel for acre harvesting  1330 bushels... and from here you must take away the food for rats and insects...
at the end you must choose to sacrifice some citizens... also selling at a good price some acres... (I sold at 21 or 23 bushels for acre  just 300 acres) your acres go down quickly and you need almost 700 to let survive 100 citizens (700 x 3 = 2100 bushels).

So at the start point Hammurabi has too many citizens and acres and few bushels.
If rats and insects can get all his bushels... from a strategy game IMHO it becomes a fortune game in with the case /fate draws the main line of the game.

Glad to talk about a strategy game so fine also if in textual state.

24
For my Baseball/Softball Statistics system I'm writing, I have looked at converting some of the reports generated to PDF on Linux, by doing the following after constructing these commands in pipecom:

Quote
enscript -p output.ps input.txt
ps2pdfwr output.ps output.pdf

Both utilities exist on most all Linux distro's.

I wonder if something as simple and similar can be done in a Windows API?

@Mad Axeman I have made code before that would allow you to output to a PDF but you would have to select the "Microsoft Print to PDF" printer with this code. https://www.qb64.org/forum/index.php?topic=4102.msg134503#msg134503

25
Great suggestions. Some I have considered, and will be adding to the game.

Since I want this to keep to the period it is set in, the main crops grown back then were wheat, barley and dates. Barley became a main crop as the soil started to become more saline. But having a variety was necessary for both feeding the population and for trade outside. I also want this game to be a learning experience as well as something fun and hard to play. It has to be educational as well as playable (My next large project after I finish my Baseball/Softball Statistical System, with complete Sabermetrics, and be free and open source to all - and is written in QB64!)

As a teen, I spent my summers (and part of my winters) on a cattle farm in update New York (Liberty, NY in the Catskills), working a heard of about 200+ poll Herefords and a small string of horses (mostly used by us) on about 900 acres. we grew several kinds of grass for hay and 35+ acres of corn for winter feed (made for great pheasant hunting in the fall, as we left most of the stalks up with some corn on them for the deer). Even had chickens.

I remember when crows changed from being a bird we could shoot anytime of the year to having its own hunting season in NY. However, like problem deer, any animal that threatened the well-being of the farm, we were able to shoot year round. Some years we would instead of riding the fence line spend a week or two camping on the ranch on crow duty. My shoulder would be sore by the end of the day just from shooting at them. We even rigged M-80's in tree tops and lit them to scare them away! Those were the days. We never had luck using plastic owls. The crows sit on top of them and crap all over it.

Back to the game, I have done quite extensive research into the time period, so I will be introducing preventive measures for all kinds of pestilences based on how they did it during Hammurabi's time. I will even introduce a simplified version of their actual monetary system, as there has to be a cost of goods as it was back then, including costs of preventive measures. 

I also have to do some work on the issue you bring up about rats. Yes, if the grain is sealed in clay jars, they are more protected from being destroyed, and I will be factoring that in. A good point.

But you know as well as I that introducing other animals to control others have their own problems. Chickens are easy, as if there are too many, they make a fine meal. Not so for cats, as their populations can get out of hand, and then they wind up wiping out all your free-ranging chickens! But such factors can be built into the game. I will have to reread my research on the methods they used to control pestilence as its been a while since I last looked at it.

We had plenty of dogs on the farm. I am partial to Australian Shepherds, and Daphne, my service dog, is an Aussie.

Thanks, great ideas, and I will be considering them.


As a farmer myself, I can give you a few ideas on a few features to add to the game.

1) A variety of crops.  Potatoes, beans, corn, wheat, whatnot.  Each has to have it's own unique seed and plant amount, and each will produce and feed a different number of people, as well as having different lifetime preservation times.  Just because rats got into your cellar and ate your potatoes, that doesn't mean they got into your pottery and ate your dried beans.

2) With a variety of crops comes a variety of predators.  Some of these predators can (and are) naturally edible as well, if you kill them.  Example:  Deer love to eat my corn fields.  I love to eat deer.  The natural cycle of nature makes us both get fatter with a good harvest.   

Other animals are just pest animals.  They honestly have no redeeming qualities to them, rather than to make a farmer's life hell.  Crows, for example, are one of these species.  Honestly, I'd rather have a whole swarm of rats invade my storage, than to have a murder of crows show up around my farm.  Berries and such can, and do, end up stripped completely bare by a single flock of crows -- and often they destroy the harvest in as short of a period of time as overnight.  I've personally seen whole orchards of cheery trees picked clean in just a few hours by a wave of crows that cawed and shit everywhere.

3) Pest prevention.  Many of these pest animals can be controlled by the simple introduction of natural predators.  One of the biggest deterrents to reduce insect damage to your crops is the introduction of free range chickens.  Believe it or not, a chicken eats a ton of insects on a regular basis, and they absolutely love to wander around the loose soil of a garden/field.  You have to keep them away from the crops until they're of suitable size to not damage them, but by the point that the plants have gotten large enough to leaf and bloom to draw insects, it's generally safe to allow chickens to wander amongst the crops.

Rats can be contained by adding cats.  Crows can be contained by judicious use of a shotgun.  (Just don't tell PETA or Uncle Sam.  In North America, American crows are protected by the Migratory Bird Treaty Act.   /CRY!!)  Dogs do a good job of keeping many varmints away.  (Which is why we domesticated dogs and cats to be our companions in the first place.)

Pesticides, fertilizers, lime and acidity are all things which you could add to a "can you feed your populace" simulation.  Invasive species and species incompatibility should be keep in mind as well.  For example, a walnut tree comes immediately to my mind, as my land is infested is thousands of the things.  There's a lot of acidity in raw, unhulled walnuts, and when they fall from the tree, they turn the soil around it acidic.  Any type of plant/grass that needs an alkaline base to grow good isn't going to grow near walnuts -- not without a lot of soil maintenance with adding lime to replenish the balance.

26
@TempodiBasic,

The code below shows how each (rats & insects) damage your stores and harvest.

The way it works is that there is a 50-50 chance that you'll encounter damage. If so, then it calculates a random percentage from 10 to 100 percent damage for each.

I would agree that rats should not eat more than say 20 percent, but insects, especially if they are a plague, can destroy an entire harvest.

It will be something I look at when I improve the game some more (I plan to add a revolt factor next, along with adding more initial land, etc. to compensate for the increased damages that can occur). That will have to be balanced, maybe I can add a difficulty indicator. You can choose between an easy game or a difficult/near impossible game.

Code: QB64: [Select]
  1. HarvestCrops:
  2. ' *** A BOUNTIFUL HARVEST!
  3.     GOSUB Randomizer
  4.     PRICE = C
  5.     HARVESTED = ACRES_PLANTED * PRICE
  6.  
  7. ' *** Provides a 50-50 chance of no damage due to Rats and Insects
  8.     GOSUB Randomizer
  9.     IF C MOD 2 = 0 THEN
  10.         BUSHELS = BUSHELS + HARVESTED
  11.         GOTO PopulationControl
  12.     END IF
  13.  
  14. ' *** Rats eat the existing store of Bushels, before the harvest is added
  15.     RATS_ATE = 0
  16.     RATS_ATE = INT(BUSHELS / C)
  17.  
  18. ' *** Insects eat at the crops in the field, and reduce the harvest, and
  19. ' *** can sometimes wipe out an entire year's harvest!
  20.     GOSUB Randomizer
  21.     PESTILENCE = 0
  22.     INSECTS_PCT = (10 * RND(1))
  23.     IF INSECTS_PCT >= 6 THEN PESTILENCE = INT(HARVESTED / C)
  24.  
  25.     BUSHELS = BUSHELS + HARVESTED - (RATS_ATE + PESTILENCE)
  26.     IF BUSHELS < 0 THEN BUSHELS = 0

27
EDIT: You had almost 5,000 bushels in storage ??? (who's cheating?)

I ran a game where the insects destroyed my entire harvest for the year!

I never said it would be easy - what fun would that be??? You can change or limit the damage done by modifying the code that determines how much of a percentage each destroys.

I've never seen rats eat that much, but I did change it to eat only what is in storage, rather than the entire stockpile (storage + harvest), as I added insects to destroy the harvest!

I'm looking at what would happen if the initial population and larger amount of land owned would do to the challenge. If you can plant and harvest more at the start, you might last longer than 4 years!

Better luck in your next re-incarnation!

@George McGinn
hey but Hammurabi cheats!
see here how this casual step over destroyed my project of long life!
 
Hammurabi cheats.PNG


28
I've been writing it up for the past two weeks.

However, the program I wanted to write to illustrate it wound up being 5 programs, 2 C++ libraries, almost 1,000 SQL statements, HTML/CSS. It's approaching 10,000 total lines of code.

After I told a friend in a baseball game about it, he wanted to use it, and then it snowballed into features that were needed.

It's on the way. I plan to break one of the programs out and rework it for the tutorial. But I want to put the entire system here first, then the tutorial will follow.

Also, I went and recently revisited Galleon's code in the Wiki on it, and found it doesn't quite work due to massive memory issues with _MEMGET and other memory statements. Row sizes not right, skipping values, adding values to rows and columns that they don't belong to. It is a mess.



Weren't you going to do a tutorial?

29
How about RAM drives?

And I remember when you needed to mortgage your house just to buy an EPROM programmer, if you knew what one was and did!

Wow this guy was 7 around the time I switched from GW to QB and got into data basing. Did not understand the project he was working on, sort of sounded like what I was doing with QB and Batch files with DOS but not sure.

Be nice to really meet Scott with a little sample of code from him, hint, hint...

@TempodiBasic do the words ROM drive also ring a nostalgia bell?

30
Small projects???

I started one, and 4 months later I have a multi-language, 10,000+ lines of code system, and it is still not ready for release (maybe beginning of next week).

Good luck, as my experience is small projects tend to take on a life of their own, once others find out about them!



Like the title says, needing some ideas for a small project. Something to do with API (Windows) would be the most preferable. I've been bored out of my mind recently and have been impatiently awaiting my new PC to get back from the shop. Hit me with some good ideas so I can at least keep my mind sharp.

Pages: 1 [2] 3 4 ... 14