[virtualcommons-svn] SF.net SVN: virtualcommons:[364] mentalmodels/trunk/src/main/java/edu/asu/ com
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-11-16 20:39:40
|
Revision: 364 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=364&view=rev Author: seematalele Date: 2009-11-16 20:39:30 +0000 (Mon, 16 Nov 2009) Log Message: ----------- Changed the code to send game which is a new state of the game rather than block, so that it will be easy for client to extract current block and current round. Modified Paths: -------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-11-13 21:02:56 UTC (rev 363) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-11-16 20:39:30 UTC (rev 364) @@ -16,6 +16,7 @@ import edu.asu.commons.mme.dao.HibernateGroupLocationDao; import edu.asu.commons.mme.dao.HibernateLocationDao; import edu.asu.commons.mme.dao.HibernateStudentDao; +import edu.asu.commons.mme.dao.HibernateStudentStrategyDao; import edu.asu.commons.mme.entity.DayByDayDecisions; import edu.asu.commons.mme.entity.DayByDayOtherStudentDecisions; import edu.asu.commons.mme.entity.Game; @@ -23,6 +24,7 @@ import edu.asu.commons.mme.entity.GroupLocation; import edu.asu.commons.mme.entity.Location; import edu.asu.commons.mme.entity.Student; +import edu.asu.commons.mme.entity.StudentStrategy; /*** 1) Harvesting - Find out the amount of fish per agent and calculate the current population after harvesting @@ -82,13 +84,14 @@ private HibernateGroupLocationDao groupLocationDao; private HibernateGroupDao groupDao; private HibernateDayByDayOtherStudentDecisionsDao dayByDayOtherStudentDecisionsDao; - + private HibernateStudentStrategyDao studentStrategyDao; private double totalFishLeaving; static final String groupsWithinGame = "select distinct student.group from Student student where student.game =:current_game_id "; static final String studentDecisionsForGame = "SELECT d FROM DayByDayDecisions d, Student s where s.game =:game and s=d.student"; static final String getgroupLocation = "SELECT g FROM GroupLocation g where g.group =:group and g.location =:location"; + static final String getStudentStrategy = "SELECT ss FROM StudentStrategy ss,Student s where s.game =: game and s=d.student"; public void setGameDao(HibernateGameDao gameDao) { this.gameDao = gameDao; @@ -320,7 +323,7 @@ //set money student.setMoney(game.getMoney() * amountPerAgent); studentDao.save(student); - + //set other students //List<Student> otherStudents = new ArrayList<Student>(); @@ -441,4 +444,87 @@ } + /*public void executeStrategy(Game game) + { + //get student Strategies + List<StudentStrategy> studentStrategies = new ArrayList<StudentStrategy>(); + + Query studentStrategiesQuery = studentStrategyDao.getCurrentSession().createQuery(getStudentStrategy); + + studentStrategiesQuery.setEntity("game", game); + + Iterator studentStrategyIterator = studentStrategiesQuery.list().iterator(); + try + { + while(studentStrategyIterator.hasNext()) + { + StudentStrategy strategy = (StudentStrategy)studentStrategyIterator.next(); + for(int i = 0; i < strategy.getDays();i++) + studentStrategies.add(strategy); + } + Query queryforGroups = studentDao.getCurrentSession().createQuery(groupsWithinGame); + + queryforGroups.setLong("current_game_id", game.getId()); + Iterator groups = queryforGroups.list().iterator(); + List<GroupLocation> groupLocations = new ArrayList<GroupLocation>(); + List<DayByDayDecisions> bay1Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> bay2Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> bay3Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> harborStudents = new ArrayList<DayByDayDecisions>(); + /** For every group find out the groupLocations objects. + * find out the student decisions for current group. + * Separate the students for each bay + * find out the population for every bay + */ + + /* getLogger().debug("number of groups in the game are: " + queryforGroups.list().size()); + while(groups.hasNext()) + { + Group currentGroup = (Group) groups.next(); + getLogger().debug("group id in executeStrategy is: " + currentGroup.getId()); + + groupLocations = groupLocationDao.findAllByProperty("group",currentGroup); + + //List<StudentDayByDayDecisions> studentDecisionForCurrentGroup = new ArrayList<DayByDayDecisions>(); + for(DayByDayDecisions tempStudentDecision:studentDecisions) + { + + if(tempStudentDecision.getStudent().getGroup().getId() == currentGroup.getId()) + { + //studentDecisionForCurrentGroup.add(tempStudentDecision); + if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay1")) + { + bay1Students.add(tempStudentDecision); + } + else if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay2")) + { + bay2Students.add(tempStudentDecision); + } + else if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay3")) + { + bay3Students.add(tempStudentDecision); + } + else if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Harbor")) + { + harborStudents.add(tempStudentDecision); + } + + } + + } + calculateHarvest(bay1Students,"Bay1",currentGroup,game); + calculateHarvest(bay2Students,"Bay2",currentGroup,game); + calculateHarvest(bay3Students,"Bay3",currentGroup,game); + calculateNewPopulation(currentGroup); + } + }catch(Exception e) + { + e.printStackTrace(); + } + + }*/ + + public void setStudentStrategyDao(HibernateStudentStrategyDao studentStrategyDao) { + this.studentStrategyDao = studentStrategyDao; + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-11-13 21:02:56 UTC (rev 363) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-11-16 20:39:30 UTC (rev 364) @@ -150,7 +150,7 @@ { assignGroups(game); getLogger().debug("system has assigned groups. "); - //pushBlock(game); + pushBlock(game); flag = true; } else @@ -191,14 +191,14 @@ if(newGameState == null) { getLogger().debug("game state is null..."); - msgHandler.sendBlock(null, null); + msgHandler.sendBlock(null); } else { getLogger().debug("game state is NOT null..."); block = newGameState.getCurrentBlock(); - initializeCurrentBlock(block); - msgHandler.sendBlock(block,newGameState); + initializeGame(newGameState); + msgHandler.sendBlock(newGameState); } }catch (Exception e) { @@ -1076,16 +1076,20 @@ }*/ - /*public Round getCurrentRound() { + public Round getCurrentRound(Game currentGame) { getLogger().debug("in get current round funciton"); Round round = currentGame.getCurrentRound(); //Round round = getDao().find(getCurrentRound().getId()); - initializeRound(round); - getLogger().debug("round no is " + currentRound.getRoundNo() + " " + currentRound.getId()); - return currentRound; - }*/ + return round; + } + private void initializeRound(Round round) { + // TODO Auto-generated method stub + Hibernate.initialize(round); + + } + public void setBlockSeqNo(int blockSeqNo) { this.blockSeqNo = blockSeqNo; } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java 2009-11-13 21:02:56 UTC (rev 363) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java 2009-11-16 20:39:30 UTC (rev 364) @@ -62,7 +62,7 @@ /*logger.info("Ack received from client for message " + msg + "is : " + ack);*/ } - public void sendBlock(Block block, Game game) + public void sendBlock(Game game) { MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); @@ -73,11 +73,12 @@ msg.setClientId(clientID); msg.setMessageId(UUIDUtils.createUUID()); msg.setTimestamp(System.currentTimeMillis()); - msg.setBody(block); + + msg.setBody(game); AcknowledgeMessage ack = msgBroker.routeMessageToService(msg, null); - if(block!=null) + if(game!=null) { - //int duration = block.getDuration(); + //int duration = game.getBlock().getDuration(); int duration = 20; Timer timer = new Timer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |