14 May, 2009, David Haley wrote in the 21st comment:
Votes: 0
If somebody did, presumably they'd have said so already. :wink:
I think one reason this is likely to be hard to track down is that it's a pretty hard problem to begin with. The code here is probably going to be relatively simple; the design is the interesting part. You might have better luck looking at economic simulation games, although the ones I know of do not actually have stock markets but instead focus on managing a companies revenue streams.
14 May, 2009, Davion wrote in the 22nd comment:
Votes: 0
It took some digging, but I managed to find it/remember the name :). here's a link right to the economy.c file! The codebase is called Lyonesse
14 May, 2009, David Haley wrote in the 23rd comment:
Votes: 0
Although that appears to be an implementation of a product supply/demand economy, does it implement a stock market at all? :wink:
14 May, 2009, Davion wrote in the 24th comment:
Votes: 0
I could swear it did… but it appears not. Still some cool stuff in there ;).

I shall redeem myself with this :D
14 May, 2009, David Haley wrote in the 25th comment:
Votes: 0
That appears to be an implementation with basically random fluctuations in stock prices, without any tying back to transactions. It looks basically like rolling dice skinned with stock names instead of dice numbers. Code-wise, it could do with some cleaning up, too.
14 May, 2009, Banner wrote in the 26th comment:
Votes: 0
Both links will be useful.. thank ya much Davion, and everyone else's input! :)
15 May, 2009, Banner wrote in the 27th comment:
Votes: 0
I began the implementation and have encountered a problem with loading already. I'm attempting to maintain two lists of shares, the huge list of every share for every corporation, then a list per corporation of the shares for that corporation. I verified that the share is being saved to the corporation, but upon reboot, it doesn't load. Any help is appreciated.

create_share
SHARE_DATA *create_share( CORP_DATA *corp, char * buyer, int amount, int profit )
{
SHARE_DATA *share;

CREATE( share, SHARE_DATA, 1);

share->buyer = STRALLOC(buyer);
share->numowned = amount;

LINK( share, first_share, last_share, next, prev );
LINK( share, corp->first_corp_share, corp->last_corp_share, next, prev );

corp->numshares -= amount;
corp->funds += profit;
return share;
}


save_corp snippet:
fprintf( fp, "NumShares   %d\n", corp->numshares );
fprintf( fp, "SharePrice %d\n", corp->shareprice );
if( corp->first_corp_share )
{
for( share = corp->first_corp_share; share; share = share->next )
{
fprintf( fp, "#SHARE\n" );
fprintf( fp, "Buyer %s~\n", share->buyer );
fprintf( fp, "Numowned %d\n", share->numowned );
fprintf( fp, "End\n\n" );
}
}
if( corp->maincorp )
fprintf( fp, "MainCorp %s~\n", corp->maincorp->name );
fprintf( fp, "End\n\n" );
fprintf( fp, "#END\n" );
}


load_corp_file snippet:
word = fread_word( fp );
if( !str_cmp( word, "CORPORATION" ) )
{
fread_corp( corp, fp );
break;
}
else if( !str_cmp( word, "SHARE" ) )
{
fread_share( corp, fp );
continue;
}
else if( !str_cmp( word, "END" ) )
break;


fread_share:
void fread_share( CORP_DATA * corp, FILE * fp )
{
SHARE_DATA *share;
char buf[MAX_STRING_LENGTH];
char *word;
bool fMatch;
CREATE( share, SHARE_DATA, 1 );
for( ;; )
{
word = feof( fp ) ? "END" : fread_word( fp );
fMatch = FALSE;

switch ( UPPER( word[0] ) )
{
case '*':
fread_to_eol( fp );
fMatch = TRUE;
break;
case 'B':
KEY( "Buyer", share->buyer, fread_string( fp ) );
break;
case 'E':
if( !str_cmp( word, "End" ) )
{
if( !share->buyer )
share->buyer = STRALLOC( "" );

LINK( share, first_share, last_share, next, prev );
LINK( share, corp->first_corp_share, corp->last_corp_share, next, prev );
return;
}
break;
case 'N':
KEY( "Numowned", share->numowned, fread_number( fp ) );
break;
}
if( !fMatch )
{
sprintf( buf, "No Match: fread_share: %s", word );
bug( buf, 0 );
}
}
}
15 May, 2009, Banner wrote in the 28th comment:
Votes: 0
Apparently it has chosen to ignore lines of my code since it clearly says to fread_share if it encounters SHARE. What is missing here?

Fri May 15 04:30:35 2009 :: Loading Corporations
Fri May 15 04:30:35 2009 :: Loading corporations…
Fri May 15 04:30:35 2009 :: banner.corp
Fri May 15 04:30:35 2009 :: banner2.corp
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: #SHARE
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: Buyer
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: Banner~
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: Numowned
Fri May 15 04:30:35 2009 :: [*****] BUG: Fread_corp: no match: 1
Fri May 15 04:30:35 2009 :: $
Fri May 15 04:30:35 2009 :: Done corporations
Sorting Corporations
Fri May 15 04:30:35 2009 :: Done sorting
Fri May 15 04:30:35 2009 :: Reading in Vendors


EDIT: Fixed. End was in the wrong place.
15 May, 2009, David Haley wrote in the 29th comment:
Votes: 0
Quote
I'm attempting to maintain two lists of shares, the huge list of every share for every corporation, then a list per corporation of the shares for that corporation

Doesn't the first list subsume the second one?
15 May, 2009, Banner wrote in the 30th comment:
Votes: 0
Hm. I guess you're right. I sort of figured the way I did it, I'd have to maintain the two lists but that doesn't make much sense really. Thank you for that insight. *shifty eyes*
15 May, 2009, Banner wrote in the 31st comment:
Votes: 0
For some reason, the output from this is always 0.

int x, y;
float percent;
x = share->numowned/corp->numshares;
percent = x*100;
bug( "%s: %s: %d %d", share->buyer, corp->name, share->numowned, corp->numshares );
ch_printf( ch, "&CBuyer&B: &W%-15s &CNumber Bought&B: &Y%-3d &B(&W%.1f% &Cownership&B)\n\r", share->buyer, share->numowned, percent );


SWGI said:
[Health]: 1697/1697 [Move]: 30000/30000 [$$]:[46500000]|>Log: Banner: share tools list
Log: [*****] BUG: Banner: Banner's Tools: 150 1000
Buyer: Banner Number Bought: 150 (0.0% ownership)
15 May, 2009, Stormy wrote in the 32nd comment:
Votes: 0
150 / 1000 = 0.15
x is 0 (because x is an int)
15 May, 2009, Banner wrote in the 33rd comment:
Votes: 0
I also tried it this way with the same affect:

float percent = (share->numowned/corp->numshares)*100;
bug( "%s: %s: %d %d", share->buyer, corp->name, share->numowned, corp->numshares );
ch_printf( ch, "&CBuyer&B: &W%-15s &CNumber Bought&B: &Y%-3d &B(&W%.1f% &Cownership&B)\n\r", share->buyer, share->numowned, percent );
15 May, 2009, David Haley wrote in the 34th comment:
Votes: 0
The return type doesn't matter because at the time of division, both numbers are integers and therefore integer division is performed. You need to convert one to a float before the division.

float percent = (shared->numowned/(float)corp->numshares) * 100;

or if you don't care about the decimal percentage points, the percent variable can be of type int.
15 May, 2009, Stormy wrote in the 35th comment:
Votes: 0
I'm guessing share->numowned and corp->numshares are ints too then, so they're returning 0.

Bah!
15 May, 2009, Banner wrote in the 36th comment:
Votes: 0
David Haley said:
The return type doesn't matter because at the time of division, both numbers are integers and therefore integer division is performed. You need to convert one to a float before the division.

float percent = (shared->numowned/(float)corp->numshares) * 100;

or if you don't care about the decimal percentage points, the percent variable can be of type int.

Hm. I didn't think it mattered as long as it was a float, but it's working correctly now. Thanks.
15 May, 2009, David Haley wrote in the 37th comment:
Votes: 0
The "type" of an operation is determined by the type of the operands; only after the operation is complete (or, the expression is evaluated, if you prefer) is the result assigned to the left-hand side of the assignment, undergoing conversion if necessary (e.g. an int being upgraded to a float, or a float being truncated to an int, etc.)
15 May, 2009, Zenn wrote in the 38th comment:
Votes: 0
You may also wish to include some sort of AI system with this, as will there really be enough players buying/selling enough to change the prices often enough?

Perhaps some random events could happen (rarely?).
16 May, 2009, Banner wrote in the 39th comment:
Votes: 0
Zenn said:
You may also wish to include some sort of AI system with this, as will there really be enough players buying/selling enough to change the prices often enough?

Perhaps some random events could happen (rarely?).

We've already taken this into account, obviously, but thanks for your otherwise needless input.
16 May, 2009, Kline wrote in the 40th comment:
Votes: 0
Banner said:
We've already taken this into account, obviously, but thanks for your otherwise needless input.

Are you typically such an ass to someone just making a suggestion when you previously asked for feedback; or was this a special occasion? Sorry if it may have been brought up elsewhere in this thread, but don't berate people for a small, constructive suggestion on the basis you assume they already knew what you had and hadn't accounted for.
20.0/51