[virtualcommons-svn] SF.net SVN: virtualcommons:[46] vcweb/trunk/virtualcommons/experiment
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2008-08-21 16:56:10
|
Revision: 46 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=46&view=rev Author: seematalele Date: 2008-08-21 16:56:18 +0000 (Thu, 21 Aug 2008) Log Message: ----------- -tie is working properly -resource depletion : changed the experiment.inc, forestry_v2 module.tested for 8 students; it is working properly -put some instructions for perticipants in the forestry_v2 module -whole experiment is working properly Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/experiment.install vcweb/trunk/virtualcommons/experiment/experiment.module vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module vcweb/trunk/virtualcommons/experiment/rules/rules.install vcweb/trunk/virtualcommons/experiment/student_login/student_login.module vcweb/trunk/virtualcommons/experiment/survey/survey.module vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module Modified: vcweb/trunk/virtualcommons/experiment/experiment.inc =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-21 16:56:18 UTC (rev 46) @@ -104,7 +104,7 @@ public function save() { //insert into game table - drupal_set_message(t('students:' . $this->no_of_students)); + //drupal_set_message(t('students:' . $this->no_of_students)); if ($this->game_id == -1) { $this->game_id = db_next_id('{vc_game}_id'); db_query("INSERT INTO {vc_game} (id, users_id, vc_experiment_id, no_of_students,vc_stage_id,current_round_no) VALUES (%d,%d,%d,%d,%d,%d)", @@ -141,7 +141,7 @@ { //$turn= (int) $turn[$i]; db_query("Insert into {vc_student} (id,vc_group_id,start_flag,turn_no) values('%s',${group_id},false,%d)",$student_id,$turn[$i]); - drupal_set_message(t('Student ID : %stud Turn is: %key<br>'. gettype($turn[$i]) ,array('%stud'=>$student_id,'%key'=>$turn[$i]))); + //drupal_set_message(t('Student ID : %stud Turn is: %key<br>'. gettype($turn[$i]) ,array('%stud'=>$student_id,'%key'=>$turn[$i]))); $i++; } @@ -171,10 +171,12 @@ $result_group_id=db_query("select id from vc_group where vc_game_id=%d",$this->game_id); while($data=db_fetch_object($result_group_id)) { - $stud_voting_cnt=db_result(db_query("select count(*) from vc_student_voting v where v.vc_student_id in (select id from vc_student where vc_group_id=%d)",$data->id)); + $stud_voting_cnt=db_result(db_query("select count(*) from vc_student_voting v + where v.vc_student_id in (select id from vc_student where vc_group_id=%d) + AND v.consider_flag=false ",$data->id)); $actual_student=db_result(db_query(" select count(*) from vc_student where vc_group_id=%d",$data->id)); // drupal_set_message(t('stud_voting_cnt: '. $stud_voting_cnt)); - //drupal_set_message(t('actual students are: '.$actual_student)); + //drupal_set_message(t('actual students are: '.$data->id)); if($stud_voting_cnt==$actual_student) { $flag=1; @@ -182,11 +184,11 @@ else { $flag=0; - drupal_set_message(t('else Flag is: '.$flag)); + //drupal_set_message(t('else Flag is: '.$flag)); } } - drupal_set_message(t('isvotingDone Flag is: '.$flag)); + //drupal_set_message(t('isvotingDone Flag is: '.$flag)); return $flag; } // FIXME: turn into $forestryGame->init() overloaded method @@ -260,8 +262,31 @@ FROM vc_stage s inner join vc_game g on s.vc_experiment_id=g.vc_experiment_id WHERE g.id=%d', $this->game_id)); return $this->isStageOver() && ($max_stage_number == $this->getCurrentStageNumber()); - } + + private function IsResourceOverForAllGroup() + { + $counter_to_check_group_resources=0; + $no_of_groups=db_result(db_query("select count(*) from vc_group where vc_game_id=%d",$this->game_id)); + + $result_group=db_query("select count(s.vc_group_id) as cnt, s.vc_group_id as group_id from vc_group g, vc_student s + where s.vc_group_id=g.id and g.vc_game_id=%d group by s.vc_group_id",$this->game_id); + + while($data=db_fetch_object($result_group)) + { + $no_of_students=$data->cnt; + $group_id=$data->group_id; + $min_resource=db_result(db_query('select min(max_resource_level) as min_resource from vc_forestry_3player_harvest_table')); + $current_resource=db_result(db_query('select common_resource_pool from vc_forestry_common_resource_pool + where vc_group_id=%d and vc_game_id=%d',$group_id,$this->game_id)); + + if($current_resource <= $min_resource) + $counter_to_check_group_resources++; + + } + return ($counter_to_check_group_resources==$no_of_groups); + + } public function isLastRound() { @@ -270,7 +295,7 @@ public function isStageOver() { - return ($this->getCurrentRoundNo() > $this->getNumberOfRounds()); + return (($this->getCurrentRoundNo() > $this->getNumberOfRounds()) || ($this->IsResourceOverForAllGroup())); } public function getTurnSequence($group_id) { @@ -287,7 +312,7 @@ $valid_ids = array(); while ($data = db_fetch_object($result)) { $valid_ids[] = $data->id; - drupal_set_message(t($data->id. ' , ')); + //drupal_set_message(t($data->id. ' , ')); } return $valid_ids; @@ -345,7 +370,7 @@ private function generate_default_decisions($group_id, $round_no, $stage_id) { $result = db_query('SELECT id FROM vc_student WHERE vc_group_id=%d', $group_id); - drupal_get_messages(); + //drupal_get_messages(); while ($fetch_object = db_fetch_object($result)) { $student_id = $fetch_object->id; $harvest_decision = db_result(db_query("SELECT harvest_decision @@ -353,10 +378,10 @@ WHERE vc_student_id='%s' AND round_no=%d AND vc_stage_id=%d", $student_id, $round_no, $stage_id)); - drupal_set_message("harvest decision is submitted is student :" . $harvest_decision); + // drupal_set_message("harvest decision is submitted is student :" . $harvest_decision); if ($harvest_decision == '') { - drupal_set_message("if harvest decision is submitted is empty :" . $harvest_decision); + //drupal_set_message("if harvest decision is submitted is empty :" . $harvest_decision); $this->insert_default_decision($student_id, $round_no,$stage_id); } } @@ -404,7 +429,7 @@ { // roll the dice $dice = rand(1, 6); - $dice = 6; + // $dice = 6; if ($dice == 6) { // check to see if we need to assess fines @@ -431,8 +456,8 @@ //update start flag if ($this->isLastRound()) { - drupal_get_messages(); - drupal_set_message('Student flag is updated to TRUE'); + //drupal_get_messages(); + //drupal_set_message('Student flag is updated to TRUE'); $this->updateStartFlag(false); } @@ -454,11 +479,11 @@ } - public function setRoundNo($round_no) + public function setRoundNo() { //drupal_set_mesage(t('Round is : ' . $round_no)); - if ($round_no > ($this->getNumberOfRounds())) { + // if ($round_no > ($this->getNumberOfRounds())) { // reset round number to 1 $this->current_round_no = 1; @@ -473,10 +498,10 @@ // experiment is over. figure out how to signal the end of } - } + /* } else { $this->current_round_no = $round_no; - } + }*/ db_query("UPDATE {vc_game} SET current_round_no=%d WHERE id=%d", $this->current_round_no, $this->game_id); @@ -492,17 +517,17 @@ $result_resource=db_query("select max_resources,vc_group_id from vc_forestry_common_resource_pool where vc_game_id=%d",$this->game_id); - if($data=db_fetch_object($result_resource)) + while($data=db_fetch_object($result_resource)) { //$data->max_resources; //db_query("update vc_forestry_common_resource_pool set common_resource_pool=%d where vc_group_id=%d and vc_game_id=%d",$data->max_resources,$data->vc_group_id,$this>game_id); db_query("update {vc_forestry_common_resource_pool} set common_resource_pool=%d where vc_game_id=%d and vc_group_id=%d",$data->max_resources,$this->game_id,$data->vc_group_id); - drupal_set_message("vc_forestry_common_resource_pool si updated for group id, max resources: " . $data->vc_group_id . ', ' . $data->max_resources . ', ' . $this->game_id ); + //drupal_set_message("vc_forestry_common_resource_pool si updated for group id, max resources: " . $data->vc_group_id . ', ' . $data->max_resources . ', ' . $this->game_id ); } - $this->setRoundNo($this->getCurrentRoundNo()); + $this->setRoundNo(); } - public function assign_Rules_To_Groups() + /* public function assign_Rules_To_Groups() { //determine the rule for a group $result_group=db_query("select id from vc_group where vc_game_id=%d",$this->game_id); @@ -576,7 +601,12 @@ $tie=implode(',',$tie_rules); drupal_get_messages(); drupal_set_message(t( 'Tie happened in Group no: ' . $group_id .'.<br> Rules are :' . $tie),'warning'); - db_query("Insert into {vc_tie} (vc_group_id,tie_rules_id) values (%d,'%s')",$group_id,$tie); + + if() + { + saveTie($group_id,$tie); + } + return TRUE; } @@ -592,21 +622,151 @@ }//end of while - }//end of init function + }//end of function*/ + public function assign_Rules_To_Groups() + { + $max_rule_cnt=0;$rule_id=array();$rule_cnt=array();$tie_rules=array();$max_rule_id=0; + //determine the rule for a group + $result_group=db_query("select id from vc_group where vc_game_id=%d",$this->game_id); + while($data=db_fetch_object($result_group)) + { + $group_id=$data->id; + //$result_voting=db_query("select vc_rules_id,count(vc_rules_id) as rule_cnt from vc_student_voting where vc_student_id in (select id from vc_student where vc_group_id=%d) group by vc_rules_id",$group_id); + /*$result_voting=db_query(" select vc_rules_id, count(vc_rules_id) as rule_cnt from vc_student_voting v + where v.time_created >= (select max(time_created) from vc_student_voting vv where v.vc_student_id=vv.vc_student_id) and + v.vc_student_id in (select id from vc_student where vc_group_id=%d) group by vc_rules_id",$group_id);*/ + $result_voting =db_query("select vc_rules_id,count(vc_rules_id) as rule_cnt from vc_student_voting + where vc_student_id in (select id from vc_student where vc_group_id=%d) + and consider_flag=false group by vc_rules_id",$group_id); + //if(db_fetch_object($result_voting)=='') + // { + // drupal_get_messages(); + // drupal_set_message('result is: ' . $result_voting); + /* if(db_fetch_object($result_voting)<> '') + { + + array_push($rule_id,$data->vc_rules_id); + array_push($rule_cnt,$data->rule_cnt);*/ + + + while($data=db_fetch_object($result_voting)) + { + array_push($rule_id,$data->vc_rules_id); + array_push($rule_cnt,$data->rule_cnt); + //$voting[$data->vc_rules_id]=$data->rule_cnt; + + } + + //make consider flag=true for the next round. + db_query("update vc_student_voting set consider_flag=true + where vc_student_id in (select id from vc_student where vc_group_id=%d)",$group_id); + + // drupal_set_message(t('count of an array is :' . count($rule_cnt))); + if(count($rule_cnt)==1) + { + $max_rule_cnt=$rule_cnt[0]; + $max_rule_id=$rule_id[0]; + //drupal_set_message(t( 'NOT Tie' . '$max_rule_id: ' . $max_rule_id)); + db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$max_rule_id,$group_id); + drupal_set_message(t('Group No : '. db_result(db_query("select group_no from vc_group where id=%d",$group_id))),'warning'); + drupal_set_message(t( 'is assigned Rule No: '.db_result(db_query("select rule_no from vc_rules where id=%d",$max_rule_id)) . '<br>'),'warning'); + } + else + { + for($i=0;$i<count($rule_cnt);$i++)//for1 + { + for($j=$i+1;$j<count($rule_cnt);$j++)//for2 + { + //drupal_set_message(t('rule cnt i: '. $rule_cnt[$i] . 'rule cnt j: '.$rule_cnt[$j])); + if($rule_cnt[$i]<$rule_cnt[$j]) + { + if($max_rule_cnt < $rule_cnt[$j]) + { + $max_rule_cnt=$rule_cnt[$j]; + $max_rule_id=$rule_id[$j]; + //drupal_set_message(t( '$max_rule_id is : ' . $rule_id[$j])); + } + } + else + { + + if($rule_cnt[$i]==$rule_cnt[$j]) + { + //echo '<br/>Equal $i ' . $i. ' $j ' .$j; + array_push($tie_rules,$rule_id[$i],$rule_id[$j]); + $tie_rule_cnt=$rule_cnt[$i]; + //drupal_set_message(t('rule cnt i: '. $tie_rules[$i] . 'rule cnt j: '.$tie_rules[$j])); + } + else if($max < $rule_cnt[$i]) + { + $max_rule_cnt=$rule_cnt[$i]; + $max_rule_id=$rule_id[$i]; + // drupal_set_message(t( '$max_rule_id is : ' . $rule_id[$i])); + } + } + + } + + }//end of for1 + + //echo '<br/> Max: '. $max ; + //drupal_set_message(t( '$max_rule_cnt is : ' . $max_rule_cnt)); + + if(($max_rule_cnt==$tie_rule_cnt) || ($max_rule_cnt==0)) + { + + $tie=implode(',',$tie_rules); + //drupal_get_messages(); + // drupal_set_message(t( 'Tie happened in Group no: ' . $group_id .'<br> Rules are :' . $tie),'warning'); + //check if the group id exists in vc_tie.If it exists it means that for $group_id, tie had alredy happened previously. + //So chosse one rule randomly from tie rules + $prev_tie_result=db_result(db_query("select tie_rules_id from vc_tie where vc_group_id=%d",$group_id)); + if($prev_tie_result == '') + $this->saveTie($group_id,$tie); + + else + { + $max_rule_id=array_rand($tie_rules,1); + db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$tie_rules[$max_rule_id],$group_id); + drupal_set_message(t('Group No : '. db_result(db_query("select group_no from vc_group where id=%d",$group_id))),'warning'); + drupal_set_message(t( 'is assigned Rule No: '.db_result(db_query("select rule_no from vc_rules where id=%d",$max_rule_id)) . '<br>'),'warning'); + } + + + return TRUE; + + } + else + { + //drupal_set_message(t( 'NOT Tie' . '$max_rule_id: ' . $max_rule_id)); + db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$max_rule_id,$group_id); + drupal_set_message(t('Group No : '. db_result(db_query("select group_no from vc_group where id=%d",$group_id))),'warning'); + drupal_set_message(t( 'is assigned Rule No: '.db_result(db_query("select rule_no from vc_rules where id=%d",$max_rule_id)) . '<br>'),'warning'); + return FALSE; + } + + // drupal_set_message(t('Rule id : ' . $final_rule_id.'Group id is: ' . $group_id)); + } + //} + }//end of while + + + }//end of init function*/ - public function saveTie() + + private function saveTie($group_id,$tie) { + db_query("Insert into {vc_tie} (vc_group_id,tie_rules_id) values (%d,'%s')",$group_id,$tie); } // 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,$rule_no) { - if($rule_no==1) - { + 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); + // 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(); @@ -620,15 +780,8 @@ // drupal_set_message($keys[$i]); $turn_sequence[] = $students[$keys[$i]]; } - } - else - { - - } - - - return $turn_sequence; - + return $turn_sequence; + } public function initRules() @@ -659,10 +812,10 @@ $how_many = 2; break; default: - drupal_set_message("For some reason there were $no_of_student students - should never happen!"); + drupal_set_message(t("For some reason there were $no_of_student students - should never happen!"),'warning'); break; } - $turn_sequence_array=$this->generateTurnSequence($how_many, $no_of_student,$rule_no); + $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 if($how_many <> 1) { @@ -725,7 +878,7 @@ break; default: - drupal_set_message("For some reason there were $no_of_student students - should never happen!"); + drupal_set_message(t("For some reason there were $no_of_student students - should never happen!"),'warning'); break; } @@ -779,7 +932,7 @@ return $this->game->getGameId(); } else { - drupal_set_message(t('the game is null..')); + //drupal_set_message(t('the game is null..')); return 5; } } @@ -903,14 +1056,17 @@ $rule_id=array(); $final_rule_no=array(); $rule_id=explode(',',$result_voting); - drupal_set_message(t('Tie Rules are : ' . $result_voting)); + //drupal_set_message(t('Tie Rules are : ' . $result_voting)); for($i=0;$i<count($rule_id);$i++) { - array_push($final_rule_no,db_result(db_query("select rule_no from vc_rules where id =%d",$rule_id[$i]))); - drupal_set_message(t('Tie Rules are : ' . $rule_id[$i] )); + $result=db_query("select rule_no,description from vc_rules where id =%d",$rule_id[$i]); + if($data=db_fetch_object($result)) + { + $final_rule_no[$data->rule_no]=$data->description; + } } - //drupal_set_message(t('Rule no : ' . $final_rule_no[0].' ' .$final_rule_no[1]. 'Group id is: ' . $this->group_id)); + return $final_rule_no; } @@ -941,6 +1097,28 @@ db_result(db_query("select description select vc_selected_rules_id from vc_group where id=%d",$this->group_id)); }*/ + public function isStageOver() + { + return (($this->getGame()->getCurrentRoundNo() > $this->getGame()->getNumberOfRounds()) || ($this->IsResourceOver())); + } + public function isResourceOver() + { + $flag=0; + $number_of_players=$this->no_of_students; + $min_resource=db_result(db_query("select min(max_resource_level) from {vc_forestry_${number_of_players}player_harvest_table")); + $current_resource=db_result(db_query('select common_resource_pool from vc_forestry_common_resource_pool + where vc_group_id=%d and vc_game_id=%d',$this->group_id,$this->game_id)); + drupal_set_message(t('min resource level is: '.$min_resource . 'and current resource level is: '.$current_resource)); + if($current_resource <= $min_resource) + $flag=1; + else + $flag=0; + + + drupal_set_message(t('in resource function returning flag is: ' .$flag)); + return $flag; + + } }//end of Group @@ -1083,7 +1261,7 @@ public function save($round_no, $harvest_decision,$stage_id=0) { - drupal_set_message($stage_id); + //drupal_set_message($stage_id); if($stage_id <> 0) { // $stage_id = $this->getGroup()->getGame()->getCurrentStageId(); @@ -1122,7 +1300,7 @@ if(!($this->getGroup()->isGameFinished())) { $valid_id=$this->getGroup()->getGame()->getValidStudentIds($this->getGroup()->getId()); - drupal_set_message(t('Group id is : '. $this->group_id. 'Student Id is : '. $this->stud_id . ' Valid student ids are: ' . $valid_id[0] . ',' . $valid_id[1])); + //drupal_set_message(t('Group id is : '. $this->group_id. 'Student Id is : '. $this->stud_id . ' Valid student ids are: ' . $valid_id[0] . ',' . $valid_id[1])); if(in_array($this->stud_id,$valid_id)) { $flag= TRUE; @@ -1130,7 +1308,7 @@ } else $flag= FALSE; - drupal_set_message(t('flag for student turn : '. $flag)); + // drupal_set_message(t('flag for student turn : '. $flag)); return $flag; } @@ -1150,7 +1328,7 @@ public function getRules($stage_id) { - drupal_set_message(t('current stage is : ' . $stage_id)); + //drupal_set_message(t('current stage is : ' . $stage_id)); $result=db_query("Select rule_no,description from vc_rules where vc_stage_id=%d",$stage_id ); while($data=db_fetch_object($result)) { @@ -1163,7 +1341,7 @@ public function saveStudentVoting($stud_id,$rule_no,$stage_id) { $rule_id=db_result(db_query("select id from vc_rules where vc_stage_id=%d and rule_no=%d",$stage_id,$rule_no)); - db_query("insert into {vc_student_voting} (vc_student_id,vc_rules_id) values('%s',%d)",$stud_id,$rule_id); + db_query("insert into {vc_student_voting} (vc_student_id,vc_rules_id,consider_flag) values('%s',%d,false)",$stud_id,$rule_id); } } Modified: vcweb/trunk/virtualcommons/experiment/experiment.install =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.install 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/experiment.install 2008-08-21 16:56:18 UTC (rev 46) @@ -73,6 +73,7 @@ start_flag BOOL default false, turn_no INT NOT NULL, + played_flag BOOL NOT NULL, PRIMARY KEY(id), FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) Modified: vcweb/trunk/virtualcommons/experiment/experiment.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-21 16:56:18 UTC (rev 46) @@ -177,7 +177,7 @@ $lname=$teacher->getlname();*/ - drupal_set_message(t('Thanks for filling out the form. Your Game will start soon. ')); + drupal_set_message(t('Thanks for filling out the form. Your Game will start soon. '),'warning'); //db_query("Insert into {virtualcommons_conducts} (users_id, virtualcommons_experiments_id ,date, no_of_students ) values(%d,%d,NOW(),%d)",$teacher_id,$result,$no_student); Modified: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-21 16:56:18 UTC (rev 46) @@ -13,16 +13,34 @@ * Implementation of hook_menu(). */ function forestry_v2_menu($may_cache) { - $items = array(); - if ($may_cache) { + //$student = Session::get('student'); + //$stage_no = $student->getGroup()->getGame()->getCurrentStageNumber(); + $items = array(); + if ($may_cache) { + $items[] = array('path' => 'forestry/info', + 'title' => t('Forestry Game Information'), + 'callback' => 'forestry_info', + 'type'=>MENU_CALLBACK, + 'access' => TRUE//user_access('Only Teachers') + ); + + $items[] = array('path' => 'forestry/decision_info', + 'title' => t('Forestry Game Decision Information'), + 'callback' => 'forestry_decision_info', + 'type'=>MENU_CALLBACK, + 'access' => TRUE//user_access('Only Teachers') + ); + + $items[] = array('path' => 'forestry/intro', 'title' => t('Forestry Game'), 'callback' => 'forestry_intro', 'type'=>MENU_CALLBACK, 'access' => TRUE//user_access('Only Teachers') ); + $items[]=array( 'path' => 'forestry/play', - 'title' => t('Forestry Game - Round Active'), + 'title' => t('Forestry Game - Round Active '), 'callback' => 'forestry_play', //'callback arguments'=>array(forestry_game_stage1_multiform), 'type'=>MENU_CALLBACK, @@ -49,6 +67,72 @@ } } + +function forestry_info() +{ + $student = Session::get('student'); + $output = t('<br><h2>Welcome to the Forestry game!</h2>'); + $output.= '<p>In this exercise it is intended to recreate a situation in which a group must make decisions about the use of a forest. + Depending upong the group size, area of forest with initial resource will be determined; which is always set to maximum resource level. + For group of 3 participants, initial resource(maximum resource level) will be 60, + while for group of 4 or 5 participants, initial resource will be 80 or 100 respectively. + You will play several rounds equivalent to, for example, years or seasons. Each round you have to make a decision + about how many resource units you want to harvest. You can harvest a maximum of 5 units and minimum of 0 units of the resource. + {You earn $x for each unit you collect from the harvesting the forest.}. Between the rounds the resource is regrowing. + For each ten units of the existing resource, one new unit is added for the next round. + For example, after everybody make harvest decision in the first round, there are 24 trees available. This leads to a regrowth of 2 new trees, + and thus for the next round 26 trees will be available for harvesting. The forest can not grow to more than maximum resource level.</p>'; + //<p>You participate in a '. $student->getgroup()->getNumberOfStudents().' person group.</p>'; + $output.=drupal_get_form('forestry_info_form'); + return $output; +} +function forestry_info_form() +{ + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next') + ); + + return $form; +} + +function forestry_info_form_submit($form,$form_values) +{ + return 'forestry/intro'; +} + +function forestry_decision_info() +{ + $student = Session::get('student'); + $output = t('<br><h2>Welcome to the Forestry game!</h2>'); + $output.= '<p>In this exercise it is intended to recreate a situation in which a group must make decisions about the use of a forest. The group sizes are 3,4 or 5. + You will play several rounds equivalent to, for example, years or seasons.<br> + Depending upong the group size, area of forest with initial resource will be determined. For group of 3 participants, initial resource will be 60, + while for group of 4 or 5 participants, initial resource will be 80 or 100, respectively. + Each round you have to make a decision about how many resource units you want to harvest. You can harvest a maximum of 5 units and + minimum of 0 units of the resource. {You earn $x for each unit you collect from the harvesting the forest.}. Between the rounds the + resource is regrowing.For each ten units of the existing resource, one new unit is added for the next round. For example, after the harvest + there are 24 trees available. This leads to a regrowth of 2 new trees, and thus for the next round 26 trees will be available. + The forest can not grow to more than 100 units.</p>'; + $output.=drupal_get_form('forestry_info_form'); + return $output; +} +function forestry_decision_info_form() +{ + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next') + ); + + return $form; +} + +function forestry_decision_info_form_submit($form,$form_values) +{ + return 'forestry/play'; +} + + /** * */ @@ -137,6 +221,7 @@ function forestry_play() { // Return the HTML generated from the $form data structure. $student = Session::get('student'); + $start=0; // check if user is properly authenticated if (! $student ) { return drupal_get_form('student_login_nameform'); @@ -154,8 +239,17 @@ { $output .= generate_harvest_table(); $output .= generate_results_table(); - - $output .= ( $student->canStart() ) ? drupal_get_form('forestry_play_multiform') : drupal_get_form('forestry_wait_form'); + drupal_set_message(t('resource over flag is: '. $student->getGroup()->isResourceOver())); + if($student->canStart()) + { + if($student->getGroup()->isResourceOver()) + $start=1; + + } + else + $start=1; + drupal_set_message(t('start flag is: '. $start)); + $output .= (!$start) ? drupal_get_form('forestry_play_multiform') : drupal_get_form('forestry_wait_form'); } return $output; } @@ -174,7 +268,7 @@ $resource_before=0; $round_no = $group->getGame()->getCurrentRoundNo(); -drupal_set_message($round_no); +//drupal_set_message($round_no); if($student->getGroup()->getGame()->isVotingEnabled()) { @@ -183,12 +277,17 @@ { if($student->isTurn()) { - $form['turn']=array( + $msg='You are allowed to harvest in this round.'; + } + else + { + $msg='You can harvest but are not allowed to in this round. If you harvest and you get caught by a monitor (chance one out of six) you have to payback the harvest plus a fine of 3 units'; + } + $form['turn']=array( '#type'=>'item', - '#value'=>t('You have been chosen for this round. You can harvest.') + '#value'=>$msg ); - } } } //store the round no in hidden field @@ -393,13 +492,16 @@ making their decisions and the facilitator instructs you to click on the next button. Clicking on the next button before the facilitator is ready will have no effect.'), - 'warning', FALSE); + 'warning', FALSE); + // drupal_set_message(t('resource over flag:'.$group->isResourceOver())); if ($group->isGameFinished()) { drupal_set_message(t('The game is over. Thanks for participating.'), 'warning', FALSE); } - else if($group->getGame()->isStageOver() || $group->getGame()->isLastRound()) + + else if( $group->getGame()->isLastRound() || $group->isResourceOver() || $group->getGame()->isStageOver() + ) { drupal_set_message(t('This stage is now over. The next stage should begin shortly.'), 'warning', FALSE); $form['submit'] = array( Modified: vcweb/trunk/virtualcommons/experiment/rules/rules.install =================================================================== --- vcweb/trunk/virtualcommons/experiment/rules/rules.install 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/rules/rules.install 2008-08-21 16:56:18 UTC (rev 46) @@ -13,6 +13,7 @@ id INT AUTO_INCREMENT, vc_student_id varchar(14) NOT NULL, vc_rules_id INT NOT NULL, + consider_flag BOOL NOT NULL, time_created TIMESTAMP NOT NULL, PRIMARY KEY(id), @@ -83,6 +84,7 @@ function rules_uninstall() { db_query("DROP TABLE {vc_student_voting}"); + db_query("DROP TABLE {vc_tie}"); drupal_set_message(t('Student Voting table is successfully deleted from the database.')); } Modified: vcweb/trunk/virtualcommons/experiment/student_login/student_login.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/student_login/student_login.module 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/student_login/student_login.module 2008-08-21 16:56:18 UTC (rev 46) @@ -73,5 +73,5 @@ { $_SESSION['student_id']=$form_values['id']; - return 'forestry/intro'; + return 'forestry/info'; } Modified: vcweb/trunk/virtualcommons/experiment/survey/survey.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/survey/survey.module 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/survey/survey.module 2008-08-21 16:56:18 UTC (rev 46) @@ -118,11 +118,19 @@ // Otherwise a bug occurs if the student finishes voting and the survey before // the teacher has processed votes // if ($group->all_students_voted()) { - return 'rule_decision'; + + // return 'rule_decision'; // } // else { // return 'voting/wait'; //} + if($group->getGame()->isRuleSelected() || $group->isTieHappened()) + { + return 'rule_decision'; + } + else + return 'voting/wait'; + } @@ -145,24 +153,26 @@ //t('There is a tie between votings. You need to vote again for the following rules') if($tie_flag) { - $rule_no=$group->getRuleNo(); + $rule=$group->getRuleNo(); $form['rule']=array( - '#title'=>t('There is a tie between following rules. Please vote again. If tie happens one more time after this voting, final rule will be randomly chosen from the following rules.'), - '#type'=>'item', + '#title'=>t('There is a tie between following rules after voting. You can vote again for these rules. If this results again in tie, we draw randomely a winner.'), + '#type'=>'item' ); - $form['rule1']=array( + foreach($rule as $key=>$value) + { + //drupal_set_message(t('Rule no : ' . $key.' ' .$value)); + + $form['rule'.$key]=array( + '#prefix'=>'<div class="indicator">', '#title'=>t('Rule No. '), '#type'=>'item', - '#value'=>$rule_no[0] + '#value'=>t($key . '<p>' . $value . '</p>' ), + '#suffix'=>'</div>' ); - $form['rule2']=array( - '#title'=>t('Rule No. '), - '#type'=>'item', - '#value'=>$rule_no[1] - ); + } $form['vote']=array( - '#prefix'=>'<div class="indicator">', + '#prefix'=>'<div class="indicator">', '#type'=>'textfield', '#title'=>t('Your Vote'), '#default_value'=>'0', @@ -175,6 +185,7 @@ '#value' => t('Vote'), '#suffix'=>'</div>' ); + } else @@ -186,7 +197,7 @@ //drupal_set_message(t('Selected rule no is: '. $key . 'Description is : ' . $value)); $form['rule']=array( - '#title'=>t('Please be patience until others voting decision has made. Teacher will tell you when to click the next button. '), + '#title'=>t('The following rule is chosen for your group. Since other groups have not finished their voting procedure, please have some patience before we go to next round. '), '#type'=>'item', ); @@ -229,8 +240,8 @@ { if($form_values['submit']=="Next") { + return 'forestry/intro'; - } else if($form_values['submit']=="Vote") { @@ -239,7 +250,45 @@ $rule_no=(int) $form_values['vote']; $rules=new Rules(); $rules->saveStudentVoting($student->getId(),$rule_no,$group->getCurrentStageId()); + return 'voting/wait'; } // FIXME: return to the appropriate experiment - return 'forestry/intro'; + } + +function voting_wait() +{ + $output='<b>Please be patience until others voting decision has made. Teacher will tell you when to click the next button.</b>'; + $output .= drupal_get_form('voting_wait_form'); + return $output; +} + + +function voting_wait_form() +{ + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next') + ); + return $form; + +} + +function voting_wait_form_submit($form,$form_values) +{ + $student=Session::get('student'); + //check whether teacher processed the votings + if( $student->getGroup()->getGame()->isRuleSelected()) + { + return 'rule_decision'; + } + else + return 'voting/wait'; + + +} + + + + Modified: vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-21 00:47:39 UTC (rev 45) +++ vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-21 16:56:18 UTC (rev 46) @@ -93,6 +93,7 @@ if ($game->isFinished()) { // $output = t('The game is over.'); + drupal_get_messages(); drupal_set_message(t('<h2 align="center" style="color:#990000">The game is over. Thanks for participating!</h2>')); /* $form['final_msg']=array( @@ -126,7 +127,7 @@ if($start_flag) { //drupal_get_messages(); - drupal_set_message(t('This stage needs voting. Please tell students to vote.'),'warning',FALSE); + // drupal_set_message(t('This stage needs voting. Please tell students to vote.'),'warning',FALSE); $form['submit'] = array( '#type' => 'submit', '#value' => t('Start Stage') @@ -205,18 +206,13 @@ { if(! $game->isRuleSelected()) { - if($game->assign_Rules_To_Groups()) - { - $game->saveTie(); - } - else - { - $rule_no=$game->initRules(); - } + $game->assign_Rules_To_Groups(); + $rule_no=$game->initRules(); + } } else - form_set_error('submit',t('Please tell students to vote. Without voting you can not proceed to Stage 2')); + form_set_error('submit',t('This stage needs voting. Please tell students to vote.')); } //$game->is_Rule_Selected_For_All_Groups(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |