Thread Closed

$50 bounty to port this text lunar lander to compile on O2.
#1
$50 bounty to port this text lunar lander to compile on O2.
Hi All,

There don't seem to be many IRIX simple example C++ programs, if you know where they are hiding please share that. Aside from other simple examples, I have this text based lunar lander game that I would like as vanilla IRIX-friendly, C++ that I can compile and experiment with. My machine is an O2 running IRIX 6.5.30 and has the Base Compiler Dev Environment 7.2.1. If you need further info in order to do this for me please ask. 

Please add any IRIX specific comments where necessary, that will help me see the difference. I can PayPal $50, I hope that's fair. Thank you.

KB

// ----------------------------------------------------------------------------
//
// LUNAR LANDER
//
// Based on Lunar lander - Eleven source code by Joe Morrison
// From http://eleven.sourceforge.net/demo/lander.html
//
// See instructions() for details of the game
// Ported to C++ by JL Popyack, January 2012
//
// ----------------------------------------------------------------------------

#include <iostream>
#include <string>
#include <cmath>

// ----------------------------------------------------------------------------
//
// -------------------------------- Prototypes --------------------------------
//
// ----------------------------------------------------------------------------

string lowerCase(string s) ;
bool getYesNoResponse(string question) ;
void instructions(void) ;

void updateStatus(double &velocity, double &burnAmount,
  double &fuelRemaining, double &height) ;
void touchdown(double &velocity, double &burnAmount,
  double &fuelRemaining, double &height,
  double & delta) ;
void finalAnalysis(int elapsedTime, double delta,
  double velocity, double fuelRemaining) ;

// ----------------------------------------------------------------------------
//
// ------------------------------- Main Program -------------------------------
//
// ----------------------------------------------------------------------------

int main(void)
{
// ----------------------------------------------------------------------------
// Initial position and velocity of the lander
// ----------------------------------------------------------------------------
int    elapsedTime  = 0;     
double height        = 1000;  // distance above the lunar surface, in feet
double velocity      = 50;    // speed of descent, in feet/sec
double fuelRemaining = 150;  // each unit of fuel slows descent by 1 ft/sec

double burnAmount  = 0;

cout << "LUNAR LANDER" << endl ;
cout << "By Dave Ahl (translation from BASIC to ELEVEN by Joe Morrison)" << endl ;
cout << "Adapted to C++ by JL Popyack" << endl << endl ;

instructions() ;

cout << endl << "LUNAR LANDER" << endl ;
cout << "Beginning landing procedure.........." << endl ;
cout << "DIGBY wishes you good luck !!!!!!!" << endl << endl ;

// ------------------------------------------------------------------------
// Each second, the user is asked how many units of fuel to burn.
// The fuel is burned, the lander descends, the velocity is adjusted
// and the user is again asked how many units to burn, until landing.
// ------------------------------------------------------------------------
while (height > 0)
{
cout << endl ;
cout << "Status of your APOLLO spacecraft: " << endl ;
cout << "Time  : " << elapsedTime << " seconds" << endl ;
cout << "Height: " << height << " feet" << endl ;
cout << "Speed : " << velocity << " feet/second" << endl ;
cout << "Fuel  : " << fuelRemaining << endl ;

// --------------------------------------------------------------------
// The user can burn up to 30 units of fuel.
// --------------------------------------------------------------------
if (fuelRemaining > 0)
{
cout << "Enter fuel burn amount: " ;
cin >> burnAmount ;

if( burnAmount < 0 )
burnAmount = 0;
if( burnAmount > 30 )
burnAmount = 30;
if( burnAmount > fuelRemaining )
burnAmount = fuelRemaining;
}
else
{
cout << "**** OUT OF FUEL ****" << endl ;
burnAmount = 0;
}

// --------------------------------------------------------------------
// The new position and velocity are determined after burning the fuel.
// --------------------------------------------------------------------
updateStatus(velocity,burnAmount,fuelRemaining,height) ;
elapsedTime++ ;
}

// ------------------------------------------------------------------------
// Touchdown. Calculate landing parameters.
// ------------------------------------------------------------------------
double delta ;
touchdown(velocity,burnAmount,fuelRemaining,height,delta) ;

elapsedTime-- ;

// ------------------------------------------------------------------------
// Print results and analysis.
// ------------------------------------------------------------------------
finalAnalysis(elapsedTime,delta,velocity,fuelRemaining) ;

return 0 ;
}

// ----------------------------------------------------------------------------
//
// -------------------------- Subprogram Definitions --------------------------
//
// ----------------------------------------------------------------------------

string lowerCase(string s)
{
// ------------------------------------------------------------------------
// Returns string with alpha characters in s converted to lower case
// ------------------------------------------------------------------------
for(unsigned int i=0; i<s.size(); i++)
if( s[i]>='A' && s[i]<='Z' )
s[i] += 'a'-'A' ;
return s ;
}

// ----------------------------------------------------------------------------
//
bool getYesNoResponse(string question)
{
// ------------------------------------------------------------------------
// Prompts user with question. 
// Accepts "y" or "yes" or "n" or "no" in upper or lower case or mixed
// and returns true or false as appropriate
// ------------------------------------------------------------------------
bool done ;
string response ;

cout << question << " " ;
do
{
getline(cin,response) ;
response = lowerCase(response) ;
done = response == "y" || response == "yes" ||
  response == "n" || response == "no" ;
if( !done )
cout << "Please answer 'y' or 'n': " ;
} while(!done) ;

return ( response == "y" || response == "yes" ) ;
}

// ----------------------------------------------------------------------------
//
void instructions(void)
{
// ------------------------------------------------------------------------
// Asks if the user wants instructions and prints them if so
// ------------------------------------------------------------------------
bool wantInstructions = getYesNoResponse("Do you want instructions (y/n)? ") ;

if (!wantInstructions)
return ;

cout << endl ;
cout << "LUNAR LANDER INSTRUCTIONS" << endl  << endl;

cout << "You are landing on the moon and have taken over manual" << endl ;
cout << "control 1000 feet above a good landing spot. You have a" << endl ;
cout << "downward velocity of 50 feet/sec. 150 units of fuel remain." << endl ;
cout << endl ;
cout << "Here are the rules that govern your APOLLO space-craft:" << endl ;
cout << "(1) After each second, the height, velocity, and remaining" << endl ;
cout << "    fuel will be reported via DIGBY, your on-board computer." << endl ;
cout << "(2) After each report, enter the number of units of fuel you" << endl ;
cout << "    wish to burn during the next second. Each unit of fuel" << endl ;
cout << "    will slow your descent by 1 foot/sec." << endl ;
cout << "(3) The maximum thrust of your engine is 30 feet/sec/sec or" << endl ;
cout << "    0 units of fuel per second." << endl ;
cout << "(4) When you contact the lunar surface, your descent engine" << endl ;
cout << "    will automatically shut down and you will be given a " << endl ;
cout << "    report of your landing speed and remaining fuel." << endl ;
cout << "(5) If you run out of fuel, you will no longer be prompted" << endl ;
cout << "    to enter the number of units to burn each second. Your" << endl ;
cout << "    second by second reports will continue until you contact" << endl ;
cout << "    the lunar surface." << endl ;
cout << endl ;
}

// ----------------------------------------------------------------------------
//
void updateStatus(double &velocity, double &burnAmount,
  double &fuelRemaining, double &height)
{
// ------------------------------------------------------------------------
// Given current velocity, height and fuel remaining, calculates the
// new values if burnAmount amount of fuel is burned.
// ------------------------------------------------------------------------
double newVelocity = velocity - burnAmount + 5;
fuelRemaining      = fuelRemaining - burnAmount;
height            = height - (velocity + newVelocity) * 0.5;
velocity          = newVelocity;
}

// ----------------------------------------------------------------------------
//
void touchdown(double &velocity, double &burnAmount,
double &fuelRemaining, double &height,
double & delta)
{
// ------------------------------------------------------------------------
// Touchdown occurs when the height reaches 0.
// Final values are computed.
// ------------------------------------------------------------------------
double newVelocity = velocity;

velocity = velocity - 5 + burnAmount;
height = height + (velocity + newVelocity) * 0.5;

if (burnAmount == 5)
  delta = height/velocity;
else
  delta = ( sqrt(velocity*velocity + height*(10 - burnAmount*2) ) - velocity) / (5 - burnAmount);

newVelocity = velocity + (5 - burnAmount)*delta;
velocity = newVelocity ;
}

// ----------------------------------------------------------------------------
//
void finalAnalysis(int elapsedTime, double delta,
  double velocity, double fuelRemaining)
{
// ------------------------------------------------------------------------
// Prints final statistics and analysis.
// ------------------------------------------------------------------------
cout << endl ;
cout << "***** CONTACT *****" << endl ;
cout << "Touchdown at " << elapsedTime + delta << " seconds." << endl ;
cout << "Landing velocity = " << velocity << " feet/second" << endl ;
cout << fuelRemaining << " units of fuel remaining." << endl << endl ;

if (velocity <= 0)
{
cout << "Congratulations! A perfect landing!!" << endl ;
cout << "Your license will be renewed.............later." << endl ;
}
else if (velocity < 2)
{
cout << "A little bumpy." << endl ;
}
else if (velocity < 5)
{
cout << "You blew it!!!!!!" << endl ;
cout << "Your family will be notified..............by post." << endl ;
}
else if (velocity < 10)
{
cout << "Your ship is a heap of junk !!!!!" << endl ;
cout << "Your family will be notified..............by post." << endl ;
}
else if (velocity < 30)
{
cout << "You blasted a huge crater !!!!!" << endl ;
cout << "Your family will be notified..............by post." << endl ;
}
else if (velocity < 50)
{
cout << "Your ship is a wreck !!!!!" << endl ;
cout << "Your family will be notified..............by post." << endl ;
}
else
{
cout << "You totaled an entire mountain !!!!!" << endl ;
cout << "Your family will be notified..............by post." << endl ;
}
}
KayBee
Octane

Trade Count: (0)
Posts: 132
Threads: 40
Joined: Feb 2020
Find
04-13-2020, 04:09 AM
#2
RE: $50 bounty to port this text lunar lander to compile on O2.
Code:
using namespace std;
Adding that was enough for me to build and run this code with MIPSpro.

EDIT: I really don't expect 50 bucks for that, it took like 20 minutes including hooking up my system and such.

EDIT2: Do you see why that line was required?
(This post was last modified: 04-13-2020, 03:15 PM by nintendoeats.)
nintendoeats
Octane

Trade Count: (0)
Posts: 85
Threads: 8
Joined: Nov 2019
Location: Canada
Find
04-13-2020, 02:34 PM
#3
RE: $50 bounty to port this text lunar lander to compile on O2.
Good Morning NE,

Thank you for doing it. I don't know why that line is required, but also, on my O2 when I try to compile it (with the line added after the includes) with CC -n32 lunar_lander_cpp.cpp
I get: "CC ERROR: cannot exec /usr/lib32/cmplrs/fecc
and there is no "fecc" in that directory.


A bounty is a bounty, I intend to PayPal you, if you can just help me get it compiling on the O2.

Thanks again.

KB
KayBee
Octane

Trade Count: (0)
Posts: 132
Threads: 40
Joined: Feb 2020
Find
04-13-2020, 03:28 PM
#4
RE: $50 bounty to port this text lunar lander to compile on O2.
(04-13-2020, 03:28 PM)KayBee Wrote:  I don't know why that line is required
The code uses a bunch of classes, such as string and cout, from the std (standard) namespace. I guess whatever compiler they were using automatically used std when required.

Quote:when I try to compile it (with the line added after the includes) with CC -n32 lunar_lander_cpp.cpp
I get: "CC ERROR: cannot exec /usr/lib32/cmplrs/fecc
and there is no "fecc" in that directory.
I had this problem not a few days ago and Raion helped me out. You need to install the development foundation and MIPSpro compilers from here: http://usftp.irixnet.org/sgi-irix/development/

Direct from Raion:
Quote:devf_13.tar.gz Development Foundation 1.3 (needed)
mipspro-7.4.3m.tar 7.4.3m update (Not needed)
mipspro744update.tar.gz 7.4.4m update (needed)
mipspro_c.tar.gz 7.4 C Compiler (needed)
mipspro_cee.tar.gz 7.4 EoE for MIPSPro (needed)
mipspro_cpp.tar.gz 7.4 C++ Compiler (needed)
mipsproap.tar.gz Auto-Parallelizing (not needed, but useful) -nintendoeats: Actually, this is just the documentation, so not needed.
prodevworkshop-2.9.2.tar.gz Workshop 2.9.2 (Debugger tools)
prodevworkshop-2.9.5.tar.xz Workshop 2.9.5 (Debugger tools; needed)

I think I will assemble a guide for answering some of the questions that I have had, including this one. I want to start from a clean install, so that will probably be a task next weekend. For some reason, whenever I get into a hobby I start writing guides. I guess that's why I'm a technical writer :p
(This post was last modified: 04-13-2020, 05:22 PM by nintendoeats.)
nintendoeats
Octane

Trade Count: (0)
Posts: 85
Threads: 8
Joined: Nov 2019
Location: Canada
Find
04-13-2020, 03:37 PM
#5
RE: $50 bounty to port this text lunar lander to compile on O2.
Oh man, A guide to setting up a dev environment on these machines would be both helpful and healthy for the long term existence of the community. That is generous of you, and selfishly I really look forward to starting down the IRIX C++ road and get things compiling.

Cheers!

KB
KayBee
Octane

Trade Count: (0)
Posts: 132
Threads: 40
Joined: Feb 2020
Find
04-13-2020, 05:47 PM
#6
RE: $50 bounty to port this text lunar lander to compile on O2.
(04-13-2020, 05:47 PM)KayBee Wrote:  Oh man, A guide to setting up a dev environment on these machines would be both helpful and healthy for the long term existence of the community. That is generous of you, and selfishly I really look forward to starting down the IRIX C++ road and get things compiling.

Cheers!

KB
No problem, it was something I was thinking about doing anyway. I find writing guides useful for helping me to understand what I'm doing better.
nintendoeats
Octane

Trade Count: (0)
Posts: 85
Threads: 8
Joined: Nov 2019
Location: Canada
Find
04-13-2020, 05:50 PM
#7
RE: $50 bounty to port this text lunar lander to compile on O2.
I thought I sent Kevin directions on how to install the compilers? Strange.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find
04-13-2020, 06:01 PM
#8
RE: $50 bounty to port this text lunar lander to compile on O2.
Thank you NE, as you wished I donated the bounty reward to the site.

Cheers,

KB
KayBee
Octane

Trade Count: (0)
Posts: 132
Threads: 40
Joined: Feb 2020
Find
04-13-2020, 07:51 PM
#9
RE: $50 bounty to port this text lunar lander to compile on O2.
Thats kind of you guys

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find
04-13-2020, 07:53 PM
#10
RE: $50 bounty to port this text lunar lander to compile on O2.
Angel
nintendoeats
Octane

Trade Count: (0)
Posts: 85
Threads: 8
Joined: Nov 2019
Location: Canada
Find
04-13-2020, 07:57 PM
Thread Closed


Forum Jump:


Users browsing this thread: 1 Guest(s)