[virtualcommons-svn] SF.net SVN: virtualcommons:[43] vcweb/trunk/virtualcommons/experiment
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2008-08-18 06:43:56
|
Revision: 43 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=43&view=rev Author: seematalele Date: 2008-08-18 06:44:06 +0000 (Mon, 18 Aug 2008) Log Message: ----------- written code for rule 2 and rule 3 but needs to do testing. Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module Modified: vcweb/trunk/virtualcommons/experiment/experiment.inc =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-16 00:02:36 UTC (rev 42) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-18 06:44:06 UTC (rev 43) @@ -319,7 +319,25 @@ $this->assessTurnSequenceFines($group_id); break; case 3: + $students=db_query("select id from vc_student where vc_group_id=%d",$group_id); + while($student_data=db_fetch_object($students)) + { + $result=db_query("Select id,harvest_decision,total_points from vc_forestry_student + where vc_student_id='%s' and round_no=%d ",$student_data->id,$this->getCurrentRoundNo()); + if($data=db_fetch_object($result)) + { + if($data->harvest_decision > 2) + { + $fine = $data->harvest_decision + 3; + $total_points = $data->total_points - $fine; + db_query('UPDATE vc_forestry_student SET fine=%d, total_points=%d + WHERE id=%d', $fine, $total_points, $data->id); + } + } + + } + break; default: form_set_error(t('Current rule number is invalid: ' . $current_rule_number)); @@ -425,11 +443,8 @@ { $this->updateStartFlag(true); } - - - - //update current round_no + //update current round_no $round_no=$round_no+1; $this->current_round_no = $round_no; @@ -578,12 +593,14 @@ // several ways to implement this - // 1. use array_rand to get a set of random keys into the array // 2. use shuffle and then take an array_slice from 0 to $how_many - private function generateTurnSequence($how_many, $no_of_students) { - $students = range(1,$no_of_students); - drupal_set_message("no of students need to be selected for this round are :" . $how_many); - //$keys=array(); - $keys = array_rand( range(1, $no_of_students), $how_many ); - $turn_sequence = array(); + private function generateTurnSequence($how_many, $no_of_students,$rule_no) { + if($rule_no==1) + { + $students = range(1,$no_of_students); + drupal_set_message("no of students need to be selected for this round are :" . $how_many); + //$keys=array(); + $keys = array_rand( range(1, $no_of_students), $how_many ); + $turn_sequence = array(); if(! is_array($keys)) { @@ -594,6 +611,11 @@ // drupal_set_message($keys[$i]); $turn_sequence[] = $students[$keys[$i]]; } + } + else + { + + } return $turn_sequence; @@ -631,7 +653,7 @@ drupal_set_message("For some reason there were $no_of_student students - should never happen!"); break; } - $turn_sequence_array=$this->generateTurnSequence($how_many, $no_of_student); + $turn_sequence_array=$this->generateTurnSequence($how_many, $no_of_student,$rule_no); //if $turn_sequence is an array then only implode with ',' else directly put the value in the database if($how_many <> 1) { @@ -662,14 +684,41 @@ case 4: case 5: $how_many = 2; - - - break; - default: + + if($round_no==1) + { + //For the first round initialise the turn sequence + $turn_sequence="1,2"; + } + else + { + $prev_round_no=$round_no-1; + $turn_seq=array(); + //get the sequnce number for the last round number, determine the sequence + $seq=db_query("Select turn_sequence from vc_forestry_turn_sequence where vc_game_id=%d and vc_group_id=%d and round_no=%d and vc_rules_id=%d",$this->game_id,$group_id,$prev_round_no,$selected_rule_id); + $temp_seq=explode(',',$seq); + $last_element=end($temp_seq); + for($j=0;$j<$how_many;$j++) + { + if($last_element<$no_of_student) + { + $turn_seq[]=$last_element++; + } + else + { + $turn_seq[]=1; + $last_element=1; + } + } + } + $turn_sequence = implode(',',$turn_seq); + break; + + default: drupal_set_message("For some reason there were $no_of_student students - should never happen!"); break; } - $turn_sequence_array=$this->generateTurnSequence($how_many, $no_of_student); + //if $turn_sequence is an array then only implode with ',' else directly put the value in the database db_query("insert into {vc_forestry_turn_sequence}(round_no,turn_sequence,vc_group_id,vc_rules_id,vc_game_id) values (%d,'%s',%d,%d,%d)",$round_no,$turn_sequence,$group_id,$selected_rule_id,$this->game_id); Modified: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-16 00:02:36 UTC (rev 42) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-18 06:44:06 UTC (rev 43) @@ -178,15 +178,18 @@ if($student->getGroup()->getGame()->isVotingEnabled()) { - if($student->isTurn()) - { - $form['turn']=array( - '#type'=>'item', - '#value'=>t('You have been chosen for this round. You can harvest.') + $rule_no=$group->getGame()->getCurrentRuleNumber($group->getId()); + if($rule_no<>3) + { + if($student->isTurn()) + { + $form['turn']=array( + '#type'=>'item', + '#value'=>t('You have been chosen for this round. You can harvest.') - ); - - } + ); + } + } } //store the round no in hidden field $form['round_no']=array( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |