Virtual Government

Status
Not open for further replies.

PHPisl33t

Solid State Member
Messages
9
Hey,
I'm kind of stuck here, my boss asked me to make a Virtual Goverment "game" or should I say "nightmare" in PHP. Okay so there is a virtual congress and a president and vice president, I get how to take votes etc... but what messes me up is trying to figure out how to equationate/program elections and the randomness in government... anyway, yeah. I'm getting paid a pretty good amount of money for this and I'm getting a dedicated server paid for for free. So if someone is willing to help me out, I can give them a share of the server or possibly some money?

~Tyler
 
I don't have anything helpful to offer, but I gotta say that is really cool! Where do you work where you get those type of work orders?!
 
Whats a specific problem your having?

If you need to simulate each person voting, then maybe loop through each person and do a random sort of thing. I took the time to create a presidential election simulator. The votes are in a way random but it is also built to take into account small things such as: Older people are 5% more likely to vote for McCain etc etc.

Btw, im in Australia so the fact that i know anything about your elections is amazing.

The below will take how ever many people you want, and echo exactly who they voted for, person by person.
PHP:
<?php

// Assume its a two party system, with one party being 0, the other
// being 1.

// Lets assume that 20% of the population (mass) is ethnic, and studies 
// show this makes them 10% more likely to vote for Obama.

// Lets assume that 30% of the population (mass) is above 60, and studies 
// show this makes them 5% more likely to vote for McCain.

// Lets assume there are 10000 people in the USA, there are actually <br />
// 300,000,000 but i didnt want to destroy any servers.

// Lets assume 80% of people vote.

// Mass = Voting Population.

$countrypop = 10000;
$votingpop = $countrypop*0.80;

$mass = $votingpop;
$ethnic = $mass*0.20;
$old = $mass*0.30;
$remaining = $mass - ($ethnic+$old);
$count = 0;
$count1 = 0;
$count2 = 0;
$largecount = 0;
$person = 0;
$VotesA = 0;
$VotesB = 0;
$Person1 = "Obama";
$Person2 = "McCain";

echo("Person 1 is: ".$Person1."<br>Person 2 is: ".$Person2."<br><br>");
 ///
 
 while($count<$remaining)
 {
	$person = rand(0,1);
	$count+=1;
	if ($person == 0)
	{echo($count.". Voted for Obama <br>"); 
	$VotesA+=1; }
	if ($person == 1)
	{echo($count.". Voted for McCain <br>"); 
	$VotesB+=1; }
 }
 
 
  while($count1<$ethnic)
 {
	$person = rand(0,100); 
	$count1+=1;
	if ( $person >59 )
	{echo($count+$count1+$count2.". Voted for Obama <br>"); 
	$VotesA+=1; }
	if ( $person <61 )
	{echo($count+$count1+$count2.". Voted for McCain <br>"); 
	$VotesB+=1; }
 }
 

 
   while($count2<$old)
 {
	$person = rand(0,100); 
	$count2+=1;
	if ( $person <56 )
	{echo($count+$count1+$count2.". Voted for Obama <br>"); 
	$VotesA+=1; }
	if ( $person >54 )
	{echo($count+$count1+$count2.". Voted for McCain <br>"); 
	$VotesB+=1; }
 }
 
 ///
 
echo("<br>"."Votes for ".$Person1.": ".$VotesA."<br>");
echo("<br>"."Votes for ".$Person2.": ".$VotesB."<br>");

?>

Its far from perfect and there's a bug or two, but in general, it works.
 
Status
Not open for further replies.
Back
Top Bottom