Traveller Store CotI Features New Posts Mark Forums Read Register


Go Back TravellerRPG.com > Citizens of the Imperium > General Traveller Discussions > Software Solutions

Software Solutions Discussions on Traveller related software.

Reply
 
Thread Tools Display Modes
  #1  
Old June 4th, 2018, 04:08 PM
Leitz's Avatar
Leitz Leitz is offline
Baron
 
Join Date: Mar 2009
Location: Wretched hive of scum and villany
Posts: 2,734
Gallery : 0
Leitz Citizen+Leitz Citizen+Leitz Citizen+
Default Hobbit Style Birthday Present

Hobbits give others presents on their birthday. I'm a bit tall for a hobbit but well rounded enough to do for. Today is my birthday and I wanted to give us both a present.

Star Merchant actually runs! While it has lots of tests it is still fragile, there's very little error checking and user input is only nominally validated. So far. I wanted to prove to myself that I could take a slightly larger than my usual program and make it work.

Here's a sample short run. Those of you doing other C based languages like TCL, Python, Java, etc, should have no problem replicating my Ruby. I'm using JSON and CSV files and straight unit tests.

Code:
Welcome Captain Ian Domici, the Spinward Quest is ready.
We are currently at Haearn.
Port: Haearn, Cash: 215987601, Open Cargo Space: 153
  textiles : 3
  spice : 5
  weapons : 9
  medicinals : 30
  rare metals : 0
(b)uy, (s)ell, (j)ump, or <q>uit?
b
There is 46 of rare metals; buy?
y
Port: Haearn, Cash: 215527601, Open Cargo Space: 107
  textiles : 3
  spice : 5
  weapons : 9
  medicinals : 30
  rare metals : 46
(b)uy, (s)ell, (j)ump, or <q>uit?
j
Here are the possible jump destinations:
Birach: UWP 777888, Location: -1,1, Trade: Ag
Saorsa: UWP 888777, Location: 2,-1, Trade: Ag
Haearn: UWP 999999, Location: 0,0, Trade: Ag
Which one do we chart for?
Birach
Jumping to Birach.
Port: Birach, Cash: 215527601, Open Cargo Space: 107
  textiles : 3
  spice : 5
  weapons : 9
  medicinals : 30
  rare metals : 46
(b)uy, (s)ell, (j)ump, or <q>uit?
s
Here are the offers, one by one:
Cargo: textiles Offer: 13500.0.
Sell? [y/n]
y
Cargo: spice Offer: 22500.0.
Sell? [y/n]
n
Cargo: weapons Offer: 40500.0.
Sell? [y/n]
n
Cargo: medicinals Offer: 135000.0.
Sell? [y/n]
n
Cargo: rare metals Offer: 207000.0.
Sell? [y/n]
n
Port: Birach, Cash: 215530601, Open Cargo Space: 110
  textiles : 0
  spice : 5
  weapons : 9
  medicinals : 30
  rare metals : 46
(b)uy, (s)ell, (j)ump, or <q>uit?
b
There is 70 of spice; buy?
y
Port: Birach, Cash: 215355601, Open Cargo Space: 40
  textiles : 0
  spice : 75
  weapons : 9
  medicinals : 30
  rare metals : 46
(b)uy, (s)ell, (j)ump, or <q>uit?
q
__________________
Chronicler, the Domici War
Reply With Quote
  #2  
Old June 4th, 2018, 10:36 PM
Spinward Scout's Avatar
Spinward Scout Spinward Scout is offline
Citizen: SOC-14
 
Join Date: Jul 2001
Location: On the edge of the Imperium...
Posts: 5,326
Gallery : 5
Visit Spinward Scout's Blog
Spinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout AwesomeSpinward Scout Awesome
Default

Happy Birthday!
__________________
I like my Traveller like the women I unfortunately usually date: Cold, Harsh, and Full of Drama.
In an effort to mitigate injury or death, the Space Patrol and the Interplanetary Safety Council recommend removing your head from Uranus before attempting any activities...
Excessive gravity is the only way to keep a good man down...
Reply With Quote
  #3  
Old June 5th, 2018, 10:13 AM
JimMarn's Avatar
JimMarn JimMarn is offline
Citizen: SOC-14
 
Join Date: Mar 2013
Posts: 1,240
Gallery : 0
JimMarn Citizen+JimMarn Citizen+JimMarn Citizen+
Default

Happy Birthday !

Are you feeding your gray hares some carrots ?
__________________
'through the thorns to the stars...' Ghost in the Shell Anime.
My Traveller site <- 140 planet surveys, 1645 UWPs, and 1645 world maps
my ATU planet survey links <- links to all surveys
Reply With Quote
  #4  
Old June 7th, 2018, 07:18 AM
Leitz's Avatar
Leitz Leitz is offline
Baron
 
Join Date: Mar 2009
Location: Wretched hive of scum and villany
Posts: 2,734
Gallery : 0
Leitz Citizen+Leitz Citizen+Leitz Citizen+
Default

More grey hares than carrots, I'm afraid...

I've started using the "Issue" tracker on GitHub, if anyone is interested in helping out. Some of the issues are marked "Good First Issue" if you want to learn some more Ruby. Anyone skilled with C based languages (C, Java, TCL, Python) shouldn't have difficulty picking up Ruby.

On another note I'm storing data files as CSV and JSON. If you want to steal...err...reuse any of it for coding in a different language, let me know. Trying to keep things portable and documented. For example, here's the cargo.csv file. Note that the prices are bogus, haven't started on that bit yet. Still in early development phase.

Code:
# title: base price: per unit volume in dT: sell mods : buy mods
textiles:1000:1:Ag 7:Hi 2, NA 3
medicinals:5000:1::In 2, Po 2, Ri 2
vehicles:6000:4:In 2:Ni 2, Hi 1
rare metals:10000:1::Ri 2, In 3
spice:2500:1::Hi 2, Ri 3, Po 3
weapons:4500:1:Hi 2: Po 6
__________________
Chronicler, the Domici War
Reply With Quote
  #5  
Old June 7th, 2018, 09:28 AM
ShawnDriscoll's Avatar
ShawnDriscoll ShawnDriscoll is offline
Citizen: SOC-13
 
Join Date: Apr 2017
Posts: 870
Gallery : 0
ShawnDriscoll Citizen+ShawnDriscoll Citizen+
Default

No header for the CSV? Is that a Ruby thing?
Reply With Quote
  #6  
Old June 7th, 2018, 09:37 AM
Leitz's Avatar
Leitz Leitz is offline
Baron
 
Join Date: Mar 2009
Location: Wretched hive of scum and villany
Posts: 2,734
Gallery : 0
Leitz Citizen+Leitz Citizen+Leitz Citizen+
Default

Quote:
Originally Posted by ShawnDriscoll View Post
No header for the CSV? Is that a Ruby thing?
I'm keeping it simple and not actually using the CSV gem for this. Yet, anyway. Any line that starts with a "#" is ignored, input wise. The line "next if name.start_with?" does that.

Code:
  def get_cargo_options(data_dir, file)
    require 'cargo'
    cargo_data = get_data_csv(data_dir, file)
    cargo = Hash.new
    cargo_data.each {|c|
      name        = c[0]
      next if name.start_with?('#')
      base_price  = c[1]
      cargo_hash = {'name' => name, 'base_price' => base_price}
      cargo[name] = Cargo.new(cargo_hash)
    }
    cargo
  end
  module_function :get_cargo_options
__________________
Chronicler, the Domici War
Reply With Quote
  #7  
Old June 7th, 2018, 08:02 PM
coliver988's Avatar
coliver988 coliver988 is offline
Baron
 
Join Date: Dec 2003
Location: Asheville
Posts: 1,457
Gallery : 101
Visit coliver988's Blog
coliver988 Citizen+coliver988 Citizen+coliver988 Citizen+
Default

Quote:
Originally Posted by ShawnDriscoll View Post
No header for the CSV? Is that a Ruby thing?
actually very common and CSV is entirely language agnostic. Most of the time you consume data knowing what you are getting. HL7 files, for instance, have a 3 digit code indicating the type of record, and then it is all | ^ and other interesting field/repetition data. You have to RTFM to know what is where.

Ruby, particularly Rails, as some interesting opinions (Rails will not let you use upper case variables. Really. Drives me nuts as in C# at least, public fields (attributes in Ruby) are caps by convention to indicate that they are public (private usually lower case, often preceded with an underscore. And that throws me off a bit from my C programming days...)
__________________
Mostly lurking about...CT is still my favorite with T5 as a neat tool box to plunder.


Duke of The Solomani RimLANGELOS A4249A6-FLangelos Write Up AlphaTrane / Glisten 2038
Baron, IpkurIpkur C564543-9Ipkur Write Up AlphaRomar / Glisten 2140
Knight of the Third Imperium [x2]Rhylanor A434934-FCyan / Trojan Reach 2102
Knight of the Third ImperiumIkuna E000410-AKryslion / Trojan Reach 2002
MCG For Conspicuous GallantryThe Assault On AlellSelshor / Trojan Reach 1402
Travellers Aid Society 2798Dudid B510526-9Blog - mix of OTU and MTUhttp://traveller-ct.blogspot.com/
Pilots Guide To D'Arlee QuadrantTraveller Github spacehttps://github.com/COliver988/Traveller
Reply With Quote
  #8  
Old June 7th, 2018, 08:12 PM
ShawnDriscoll's Avatar
ShawnDriscoll ShawnDriscoll is offline
Citizen: SOC-13
 
Join Date: Apr 2017
Posts: 870
Gallery : 0
ShawnDriscoll Citizen+ShawnDriscoll Citizen+
Default

Quote:
Originally Posted by coliver988 View Post
actually very common and CSV is entirely language agnostic. Most of the time you consume data knowing what you are getting.
I've been using a header in my CSV files so that Python knows what the variable names to use are when reading the data.
Reply With Quote
  #9  
Old June 7th, 2018, 08:16 PM
Leitz's Avatar
Leitz Leitz is offline
Baron
 
Join Date: Mar 2009
Location: Wretched hive of scum and villany
Posts: 2,734
Gallery : 0
Leitz Citizen+Leitz Citizen+Leitz Citizen+
Default

Quote:
Originally Posted by ShawnDriscoll View Post
I've been using a header in my CSV files so that Python knows what the variable names to use are when reading the data.
I can see the utility in that, you could make the dict key based on the header. Since my code is pretty raw, and others might want to add to and use it without my snake case name scheme, I'll holding off for the nonce. I do like the idea, though...
__________________
Chronicler, the Domici War
Reply With Quote
  #10  
Old July 20th, 2019, 07:26 AM
Leitz's Avatar
Leitz Leitz is offline
Baron
 
Join Date: Mar 2009
Location: Wretched hive of scum and villany
Posts: 2,734
Gallery : 0
Leitz Citizen+Leitz Citizen+Leitz Citizen+
Default

I had hoped to provide the bit of code to the community, as my 2019 birthday present. Sadly, work issues took up a lot of time, and dealing with the potential to start job-hunting again took up even more time.

That said, here's what I'm doing as my 2019 Hobbit Style Birthday present.

Code:
Crew

    Pilot: Lizabeth Colon [ F ] 897758 ( 5 terms) Age: 39    Brawling-1, Carouse-2, Pilot-3
    Navigator: Coralee Maury [ F ] 87B986 ( 3 terms) Age: 31    Brawling-2, Navigation-2
    Engineers:
        Noble Barna [ M ] 8C7649 ( 2 terms) Age: 28    Carouse-1, Engineering-2, Vehicle-1
        Winford Hanssen [ M ] 883632 ( 5 terms) Age: 41    Carouse-1, Engineering-3, Survival-2
    Medic: Kip Rey [ M ] A62774 ( 3 terms) Age: 32    Carouse-1, Medic-2, Survival-1
    Steward: Murray Nilsen [ M ] 388896 ( 5 terms) Age: 39    Brawling-1, Carouse-1, Gamble-1, Steward-3
    Gunners:
        Jimmy Munro [ M ] 985442 ( 4 terms) Age: 35    Brawling-2, Gunner-3, Stealth-1
        Theron Pollard [ M ] 654968 ( 5 terms) Age: 40    Brawling-1, Gamble-1, GunCbt-1, Gunner-3
There are lots of ways to make this better, and the code repo issues page has a list of known improvements.

While the code is always free and open, that's not this year's present. Ruby is an easy language to learn, if you've thought about wanting to program but never picked up on it, or if you did stuff "back in the day" and would like to learn a modern object oriented language, there's no time like the present!

And that is 2019's present. I'm not a Ruby master, my code is very simple. I am an experienced mentor, and would be happy to help one or two people learn to program. If you're willing to do the work to learn, you can be enjoying your first Ruby in a matter of hours. You can probably read the project's code in a matter of days. In a week or two, at most, you can edit it locally to put in the skills and business logic you prefer.

Think about it. I'll be off-line for a week or so, you have time to poke at Ruby and see if it is for you. You can:
__________________
Chronicler, the Domici War
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[TravellerCON/USA] Touting the present, improving the future FreeTrav TAS News Feed 13 August 5th, 2015 07:01 AM
"The Hobbit", Sovietsky Style Blue Ghost Random Static 9 December 9th, 2014 11:12 AM
The Hobbit movie Qstor2 Random Static 59 January 16th, 2013 09:46 PM
The reprints past, present and future Crimson Cat The Lone Star 4 October 30th, 2003 03:03 PM

This website and its contents are copyright ©2010- Far Future Enterprises. All rights reserved. Traveller is a registered trademark of Far Future Enterprises .
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2010-2013, Far Future Enterprises. All Rights Reserved.